mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 17:01:51 +00:00
MD2. BMW.
git-svn-id: https://svn.eduke32.com/eduke32@294 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
d961d235a5
commit
fe40a9ce85
3 changed files with 62 additions and 31 deletions
|
@ -3,6 +3,12 @@
|
|||
#ifndef _polymer_h_
|
||||
# define _polymer_h_
|
||||
|
||||
# ifdef _WIN32
|
||||
# define PR_CALLBACK __stdcall
|
||||
# else
|
||||
# defube PR_CALLBACK
|
||||
# endif
|
||||
|
||||
# include "compat.h"
|
||||
# include "build.h"
|
||||
# include "glbuild.h"
|
||||
|
|
|
@ -145,6 +145,7 @@ typedef struct
|
|||
|
||||
//MD3 specific
|
||||
md3head_t head;
|
||||
point3d *muladdframes;
|
||||
} md3model;
|
||||
|
||||
#define VOXBORDWIDTH 1 //use 0 to save memory, but has texture artifacts; 1 looks better...
|
||||
|
@ -990,6 +991,7 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris
|
|||
m3->numframes = m3->head.numframes;
|
||||
|
||||
m3->head.frames = (md3frame_t *)calloc(m3->head.numframes, sizeof(md3frame_t)); if (!m3->head.frames) { free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); }
|
||||
m3->muladdframes = (point3d *)calloc(m->numframes * 2, sizeof(point3d));
|
||||
|
||||
f = (md2frame_t *)(m->frames);
|
||||
|
||||
|
@ -1000,6 +1002,8 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris
|
|||
f = (md2frame_t *)&m->frames[i*m->framebytes];
|
||||
strcpy(m3->head.frames[i].nam, f->name);
|
||||
//OSD_Printf("Copied frame %s.\n", m3->head.frames[i].nam);
|
||||
m3->muladdframes[i*2] = f->mul;
|
||||
m3->muladdframes[i*2+1] = f->add;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -1025,6 +1029,7 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris
|
|||
s->tris = (md3tri_t *)calloc(head.numtris, sizeof(md3tri_t)); if (!s->tris) { free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); }
|
||||
s->uv = (md3uv_t *)calloc(s->numverts, sizeof(md3uv_t)); if (!s->uv) { free(s->tris); free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); }
|
||||
s->xyzn = (md3xyzn_t *)calloc(s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { free(s->uv); free(s->tris); free(s); free(m3->head.frames); free(m3); free(m->skinfn); free(m->basepath); free(m->uv); free(m->tris); free(m->glcmds); free(m->frames); free(m); return(0); }
|
||||
|
||||
//memoryusage += (s->numverts * m->numframes * sizeof(md3xyzn_t));
|
||||
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
|
||||
|
||||
|
@ -1052,9 +1057,12 @@ m->basepath = (char *)malloc(i+1); if (!m->basepath) { free(m->uv); free(m->tris
|
|||
while (k < m->numframes)
|
||||
{
|
||||
f = (md2frame_t *)&m->frames[k*m->framebytes];
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].x = ((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x);
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].y = ((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y);
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].z = ((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z);
|
||||
//s->xyzn[(k*s->numverts) + (i*3) + j].x = ((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x);
|
||||
//s->xyzn[(k*s->numverts) + (i*3) + j].y = ((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y);
|
||||
//s->xyzn[(k*s->numverts) + (i*3) + j].z = ((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z);
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].x = f->verts[m->tris[i].v[j]].v[0];
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].y = f->verts[m->tris[i].v[j]].v[1];
|
||||
s->xyzn[(k*s->numverts) + (i*3) + j].z = f->verts[m->tris[i].v[j]].v[2];
|
||||
k++;
|
||||
}
|
||||
j++;
|
||||
|
@ -1349,6 +1357,8 @@ static md3model *md3load (int fil)
|
|||
m = (md3model *)calloc(1,sizeof(md3model)); if (!m) return(0);
|
||||
m->mdnum = 3; m->texid = 0; m->scale = .01;
|
||||
|
||||
m->muladdframes = NULL;
|
||||
|
||||
kread(fil,&m->head,sizeof(md3head_t));
|
||||
m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers);
|
||||
m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes);
|
||||
|
@ -1500,15 +1510,25 @@ static int md3draw (md3model *m, spritetype *tspr)
|
|||
|
||||
//create current&next frame's vertex list from whole list
|
||||
|
||||
if (m->head.flags == 1337)
|
||||
mult = 1 * m->scale; // md2
|
||||
else
|
||||
mult = (1.0/64.0) * m->scale;
|
||||
f = m->interpol; g = 1-f;
|
||||
m0.x = mult*g; m1.x = mult*f;
|
||||
m0.y = mult*g; m1.y = mult*f;
|
||||
m0.z = mult*g; m1.z = mult*f;
|
||||
a0.x = a0.y = 0; a0.z = m->zadd*m->scale;
|
||||
|
||||
if (m->head.flags == 1337)
|
||||
{ // md2
|
||||
m0.x = m->scale * g * m->muladdframes[m->cframe*2].x; m1.x = m->scale * f * m->muladdframes[m->nframe*2].x;
|
||||
m0.y = m->scale * g * m->muladdframes[m->cframe*2].y; m1.y = m->scale * f * m->muladdframes[m->nframe*2].y;
|
||||
m0.z = m->scale * g * m->muladdframes[m->cframe*2].z; m1.z = m->scale * f * m->muladdframes[m->nframe*2].z;
|
||||
a0.x = m->muladdframes[m->cframe*2+1].x * m->scale; a0.x = (m->muladdframes[m->nframe*2+1].x * m->scale - a0.x)*f+a0.x;
|
||||
a0.y = m->muladdframes[m->cframe*2+1].y * m->scale; a0.y = (m->muladdframes[m->nframe*2+1].y * m->scale - a0.y)*f+a0.y;
|
||||
a0.z = m->muladdframes[m->cframe*2+1].z * m->scale; a0.z = (m->muladdframes[m->nframe*2+1].z * m->scale - a0.z)*f+a0.z + m->zadd*m->scale;
|
||||
}
|
||||
else
|
||||
{
|
||||
m0.x = (1.0/64.0) * m->scale * g; m1.x = (1.0/64.0) * m->scale *f;
|
||||
m0.y = (1.0/64.0) * m->scale * g; m1.y = (1.0/64.0) * m->scale *f;
|
||||
m0.z = (1.0/64.0) * m->scale * g; m1.z = (1.0/64.0) * m->scale *f;
|
||||
a0.x = a0.y = 0; a0.z = m->zadd*m->scale;
|
||||
}
|
||||
|
||||
|
||||
// Parkar: Moved up to be able to use k0 for the y-flipping code
|
||||
k0 = tspr->z;
|
||||
|
@ -1612,8 +1632,8 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; }
|
|||
if (tspr->cstat&2) bglEnable(GL_BLEND); else bglDisable(GL_BLEND);
|
||||
}
|
||||
bglColor4f(pc[0],pc[1],pc[2],pc[3]);
|
||||
if (m->head.flags == 1337)
|
||||
bglColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
//if (m->head.flags == 1337)
|
||||
// bglColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
//------------
|
||||
|
||||
// PLAG: Cleaner model rotation code
|
||||
|
@ -1857,6 +1877,8 @@ static void md3free (md3model *m)
|
|||
|
||||
if (m->texid) free(m->texid);
|
||||
|
||||
if (m->muladdframes) free(m->muladdframes);
|
||||
|
||||
free(m);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ float polymostmodelmatrix[16];
|
|||
// tesselation variables
|
||||
GLUtesselator* prtess;
|
||||
int tempverticescount;
|
||||
GLdouble* tempvertices;
|
||||
GLdouble tempvertice[3];
|
||||
|
||||
// Polymer cvars
|
||||
char pr_verbosity = 1; // 0: silent, 1: errors and one-times, 2: multiple-times, 3: flood
|
||||
|
@ -51,7 +51,7 @@ void polymer_glinit(void)
|
|||
bglViewport(0, 0, 1024, 768);
|
||||
|
||||
// texturing
|
||||
bglEnable(GL_TEXTURE_2D);
|
||||
bglDisable(GL_TEXTURE_2D);
|
||||
//bglEnable(GL_TEXTURE_GEN_S);
|
||||
//bglEnable(GL_TEXTURE_GEN_T);
|
||||
params[0] = GL_OBJECT_LINEAR;
|
||||
|
@ -84,6 +84,7 @@ int polymer_updategeometry(short sectnum)
|
|||
sectortype *sec;
|
||||
walltype *wal;
|
||||
int i, ret;
|
||||
long ceilz, florz;
|
||||
|
||||
s = prsectors[sectnum];
|
||||
sec = §or[sectnum];
|
||||
|
@ -105,13 +106,16 @@ int polymer_updategeometry(short sectnum)
|
|||
else
|
||||
ret = 0;
|
||||
|
||||
|
||||
|
||||
i = 0;
|
||||
while (i < s->wallcount)
|
||||
{
|
||||
s->verts[i].wallnum = sec->wallptr + i;
|
||||
s->verts[i].v[2] = -wal->x;
|
||||
s->verts[i].v[0] = wal->y;
|
||||
s->verts[i].v[1] = -sec->floorz;
|
||||
getzsofslope(sectnum, wal->x, wal->y, &ceilz, &florz);
|
||||
s->verts[i].v[1] = -florz;
|
||||
|
||||
i++;
|
||||
wal = &wall[sec->wallptr + i];
|
||||
|
@ -123,25 +127,24 @@ int polymer_updategeometry(short sectnum)
|
|||
}
|
||||
|
||||
// This callback is called by the tesselator when it detects an intersection between contours (HELLO ROTATING SPOTLIGHT IN E1L1).
|
||||
// In this case, we create a new temporary vertex at the intersection point which will be freed after the polygon is drawn.
|
||||
void polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out)
|
||||
void PR_CALLBACK polymer_tesscombine(GLdouble v[3], GLdouble *data[4], GLfloat weight[4], GLdouble **out)
|
||||
{
|
||||
GLdouble *ptr;
|
||||
GLdouble* ptr;
|
||||
|
||||
tempverticescount++;
|
||||
tempvertices = realloc(tempvertices, tempverticescount * sizeof(GLdouble) * 3);
|
||||
tempvertices[(tempverticescount * 3) - 3] = v[0];
|
||||
tempvertices[(tempverticescount * 3) - 2] = v[1];
|
||||
tempvertices[(tempverticescount * 3) - 1] = v[2];
|
||||
//tempverticescount++;
|
||||
//tempvertices = realloc(tempvertices, tempverticescount * sizeof(GLdouble) * 3);
|
||||
tempvertice[0] = v[0];
|
||||
tempvertice[1] = v[1];
|
||||
tempvertice[2] = v[2];
|
||||
|
||||
ptr = &tempvertices[(tempverticescount - 1) * 3];
|
||||
ptr = tempvertice;
|
||||
*out = ptr;
|
||||
|
||||
if (pr_verbosity >= 2) OSD_Printf("PR : Created additional geometry for sector tesselation.\n");
|
||||
}
|
||||
|
||||
// This callback is called by the tesselator whenever it raises an error.
|
||||
void polymer_tesserror(GLenum error)
|
||||
void PR_CALLBACK polymer_tesserror(GLenum error)
|
||||
{
|
||||
if (pr_verbosity >= 1) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, gluErrorString(errno));
|
||||
}
|
||||
|
@ -171,8 +174,8 @@ int polymer_buildfloor(short sectnum)
|
|||
|
||||
gluTessProperty(prtess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE);
|
||||
|
||||
tempverticescount = 0;
|
||||
tempvertices = NULL;
|
||||
//tempverticescount = 0;
|
||||
//tempvertice = NULL;
|
||||
|
||||
gluTessBeginPolygon(prtess, NULL);
|
||||
gluTessBeginContour(prtess);
|
||||
|
@ -193,12 +196,12 @@ int polymer_buildfloor(short sectnum)
|
|||
|
||||
bglEndList();
|
||||
|
||||
if (tempverticescount)
|
||||
/*if (tempverticescount)
|
||||
{
|
||||
free(tempvertices);
|
||||
tempvertices = NULL;
|
||||
tempverticescount = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (pr_verbosity >= 2) OSD_Printf("PR : Tesselated floor of sector %i.\n", sectnum);
|
||||
|
||||
|
@ -255,7 +258,7 @@ void polymer_drawsector(long daposx, long daposy, long daposz, short
|
|||
polymer_updategeometry(sectnum);
|
||||
polymer_buildfloor(sectnum);
|
||||
}
|
||||
else if (prsectors[sectnum]->invalidate)
|
||||
else if ((prsectors[sectnum]->invalidate) || 1)
|
||||
{
|
||||
if (pr_verbosity >= 2) OSD_Printf("PR : Sector %i invalidated. Tesselating...\n", sectnum);
|
||||
polymer_updategeometry(sectnum);
|
||||
|
|
Loading…
Reference in a new issue