mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-26 03:30:46 +00:00
Model bounding box and sphere computation.
git-svn-id: https://svn.eduke32.com/eduke32@1237 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
4daa93c453
commit
dec9c2cbac
2 changed files with 126 additions and 3 deletions
|
@ -1534,6 +1534,98 @@ static md3model_t *md3load(int32_t fil)
|
||||||
return(m);
|
return(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void md3postload(md3model_t* m)
|
||||||
|
{
|
||||||
|
int framei, surfi, verti;
|
||||||
|
md3xyzn_t *frameverts;
|
||||||
|
float dist;
|
||||||
|
|
||||||
|
// apparently we can't trust loaded models bounding box/sphere information,
|
||||||
|
// so let's compute it ourselves
|
||||||
|
|
||||||
|
framei = 0;
|
||||||
|
|
||||||
|
while (framei < m->head.numframes)
|
||||||
|
{
|
||||||
|
m->head.frames[framei].min.x = 0.0f;
|
||||||
|
m->head.frames[framei].min.y = 0.0f;
|
||||||
|
m->head.frames[framei].min.z = 0.0f;
|
||||||
|
|
||||||
|
m->head.frames[framei].max.x = 0.0f;
|
||||||
|
m->head.frames[framei].max.y = 0.0f;
|
||||||
|
m->head.frames[framei].max.z = 0.0f;
|
||||||
|
|
||||||
|
m->head.frames[framei].r = 0.0f;
|
||||||
|
|
||||||
|
surfi = 0;
|
||||||
|
while (surfi < m->head.numsurfs)
|
||||||
|
{
|
||||||
|
frameverts = &m->head.surfs[surfi].xyzn[framei * m->head.surfs[surfi].numverts];
|
||||||
|
|
||||||
|
verti = 0;
|
||||||
|
while (verti < m->head.surfs[surfi].numverts)
|
||||||
|
{
|
||||||
|
if (!verti && !surfi)
|
||||||
|
{
|
||||||
|
m->head.frames[framei].min.x = frameverts[verti].x;
|
||||||
|
m->head.frames[framei].min.y = frameverts[verti].y;
|
||||||
|
m->head.frames[framei].min.z = frameverts[verti].z;
|
||||||
|
|
||||||
|
m->head.frames[framei].max.x = frameverts[verti].x;
|
||||||
|
m->head.frames[framei].max.y = frameverts[verti].y;
|
||||||
|
m->head.frames[framei].max.z = frameverts[verti].z;
|
||||||
|
} else {
|
||||||
|
if (m->head.frames[framei].min.x > frameverts[verti].x)
|
||||||
|
m->head.frames[framei].min.x = frameverts[verti].x;
|
||||||
|
if (m->head.frames[framei].max.x < frameverts[verti].x)
|
||||||
|
m->head.frames[framei].max.x = frameverts[verti].x;
|
||||||
|
|
||||||
|
if (m->head.frames[framei].min.y > frameverts[verti].y)
|
||||||
|
m->head.frames[framei].min.y = frameverts[verti].y;
|
||||||
|
if (m->head.frames[framei].max.y < frameverts[verti].y)
|
||||||
|
m->head.frames[framei].max.y = frameverts[verti].y;
|
||||||
|
|
||||||
|
if (m->head.frames[framei].min.z > frameverts[verti].z)
|
||||||
|
m->head.frames[framei].min.z = frameverts[verti].z;
|
||||||
|
if (m->head.frames[framei].max.z < frameverts[verti].z)
|
||||||
|
m->head.frames[framei].max.z = frameverts[verti].z;
|
||||||
|
}
|
||||||
|
|
||||||
|
verti++;
|
||||||
|
}
|
||||||
|
surfi++;
|
||||||
|
}
|
||||||
|
|
||||||
|
m->head.frames[framei].cen.x = (m->head.frames[framei].min.x + m->head.frames[framei].max.x) / 2.0f;
|
||||||
|
m->head.frames[framei].cen.y = (m->head.frames[framei].min.y + m->head.frames[framei].max.y) / 2.0f;
|
||||||
|
m->head.frames[framei].cen.z = (m->head.frames[framei].min.z + m->head.frames[framei].max.z) / 2.0f;
|
||||||
|
|
||||||
|
surfi = 0;
|
||||||
|
while (surfi < m->head.numsurfs)
|
||||||
|
{
|
||||||
|
frameverts = &m->head.surfs[surfi].xyzn[framei * m->head.surfs[surfi].numverts];
|
||||||
|
|
||||||
|
verti = 0;
|
||||||
|
while (verti < m->head.surfs[surfi].numverts)
|
||||||
|
{
|
||||||
|
dist = m->head.frames[framei].cen.x * frameverts[verti].x +
|
||||||
|
m->head.frames[framei].cen.y * frameverts[verti].y +
|
||||||
|
m->head.frames[framei].cen.z * frameverts[verti].z;
|
||||||
|
|
||||||
|
if (dist > m->head.frames[framei].r)
|
||||||
|
m->head.frames[framei].r = dist;
|
||||||
|
|
||||||
|
verti++;
|
||||||
|
}
|
||||||
|
surfi++;
|
||||||
|
}
|
||||||
|
|
||||||
|
m->head.frames[framei].r = sqrt(m->head.frames[framei].r);
|
||||||
|
|
||||||
|
framei++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t md3draw(md3model_t *m, spritetype *tspr)
|
static int32_t md3draw(md3model_t *m, spritetype *tspr)
|
||||||
{
|
{
|
||||||
point3d fp, fp1, fp2, m0, m1, a0;
|
point3d fp, fp1, fp2, m0, m1, a0;
|
||||||
|
@ -2950,9 +3042,13 @@ mdmodel_t *mdload(const char *filnam)
|
||||||
{
|
{
|
||||||
case 0x32504449:
|
case 0x32504449:
|
||||||
// initprintf("Warning: model '%s' is version IDP2; wanted version IDP3\n",filnam);
|
// initprintf("Warning: model '%s' is version IDP2; wanted version IDP3\n",filnam);
|
||||||
vm = (mdmodel_t*)md2load(fil,filnam); break; //IDP2
|
vm = (mdmodel_t*)md2load(fil,filnam);
|
||||||
|
md3postload((md3model_t*)vm);
|
||||||
|
break; //IDP2
|
||||||
case 0x33504449:
|
case 0x33504449:
|
||||||
vm = (mdmodel_t*)md3load(fil); break; //IDP3
|
vm = (mdmodel_t*)md3load(fil);
|
||||||
|
md3postload((md3model_t*)vm);
|
||||||
|
break; //IDP3
|
||||||
default:
|
default:
|
||||||
vm = (mdmodel_t*)0; break;
|
vm = (mdmodel_t*)0; break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
||||||
" }\n"
|
" }\n"
|
||||||
" result += diffuseTexel * vec4(lightAttenuation * dotNormalLightDir * lightDiffuse, 0.0);\n"
|
" result += diffuseTexel * vec4(lightAttenuation * dotNormalLightDir * lightDiffuse, 0.0);\n"
|
||||||
" float specular = pow( max(dot(reflect(-normalize(lightVector), fragmentNormal), normalize(-vertexPos)), 0.0), 60.0);\n"
|
" float specular = pow( max(dot(reflect(-normalize(lightVector), fragmentNormal), normalize(-vertexPos)), 0.0), 60.0);\n"
|
||||||
" result += vec4(lightAttenuation * specular * vec3(1.0, 1.0, 1.0), 0.0);\n"
|
" result += diffuseTexel * vec4(lightAttenuation * specular * lightDiffuse * 10, 0.0);\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"\n"
|
"\n"
|
||||||
" l++;\n"
|
" l++;\n"
|
||||||
|
@ -2484,6 +2484,33 @@ static void polymer_drawmdsprite(spritetype *tspr)
|
||||||
bglScalef(scale * tspr->xrepeat, scale * tspr->xrepeat, scale * tspr->yrepeat);
|
bglScalef(scale * tspr->xrepeat, scale * tspr->xrepeat, scale * tspr->yrepeat);
|
||||||
bglTranslatef(0.0f, 0.0, m->zadd * 64);
|
bglTranslatef(0.0f, 0.0, m->zadd * 64);
|
||||||
|
|
||||||
|
// debug code for drawing the model bounding sphere
|
||||||
|
// bglDisable(GL_TEXTURE_2D);
|
||||||
|
// bglBegin(GL_LINES);
|
||||||
|
// bglColor4f(1.0, 0.0, 0.0, 1.0);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
||||||
|
// m->head.frames[m->cframe].cen.y,
|
||||||
|
// m->head.frames[m->cframe].cen.z);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x + m->head.frames[m->cframe].r,
|
||||||
|
// m->head.frames[m->cframe].cen.y,
|
||||||
|
// m->head.frames[m->cframe].cen.z);
|
||||||
|
// bglColor4f(0.0, 1.0, 0.0, 1.0);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
||||||
|
// m->head.frames[m->cframe].cen.y,
|
||||||
|
// m->head.frames[m->cframe].cen.z);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
||||||
|
// m->head.frames[m->cframe].cen.y + m->head.frames[m->cframe].r,
|
||||||
|
// m->head.frames[m->cframe].cen.z);
|
||||||
|
// bglColor4f(0.0, 0.0, 1.0, 1.0);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
||||||
|
// m->head.frames[m->cframe].cen.y,
|
||||||
|
// m->head.frames[m->cframe].cen.z);
|
||||||
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
||||||
|
// m->head.frames[m->cframe].cen.y,
|
||||||
|
// m->head.frames[m->cframe].cen.z + m->head.frames[m->cframe].r);
|
||||||
|
// bglEnd();
|
||||||
|
// bglEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
polymer_getscratchmaterial(&mdspritematerial);
|
polymer_getscratchmaterial(&mdspritematerial);
|
||||||
|
|
||||||
color = mdspritematerial.diffusemodulation;
|
color = mdspritematerial.diffusemodulation;
|
||||||
|
|
Loading…
Reference in a new issue