- replaced vec3f_t with FVector3.

This commit is contained in:
Christoph Oelckers 2021-12-14 09:58:01 +01:00
parent 6e43f1a15a
commit 7546cf3a4b
9 changed files with 172 additions and 182 deletions

View file

@ -623,7 +623,7 @@ EXTERN FixedBitArray<MAXVOXELS>voxreserve;
#ifdef USE_OPENGL
// TODO: dynamically allocate this
typedef struct { vec3f_t add; int16_t angadd, flags, fov; } hudtyp;
typedef struct { FVector3 add; int16_t angadd, flags, fov; } hudtyp;
typedef struct
{
@ -656,7 +656,7 @@ int32_t md_defineanimation(int32_t modelid, const char *framestart, const char *
int32_t fps, int32_t flags);
int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32_t skinnum,
int32_t surfnum, float param, float specpower, float specfactor, int32_t flags);
int32_t md_definehud (int32_t modelid, int32_t tilex, vec3f_t add,
int32_t md_definehud (int32_t modelid, int32_t tilex, FVector3 add,
int32_t angadd, int32_t flags, int32_t fov);
int32_t md_undefinetile(int32_t tile);
int32_t md_undefinemodel(int32_t modelid);

View file

@ -11,6 +11,7 @@
#include "m_alloc.h"
#include "intvec.h"
#include "m_swap.h"
#include "vectors.h"
////////// Language and compiler feature polyfills //////////
@ -62,22 +63,11 @@ typedef intptr_t bssize_t;
using native_t = intptr_t;
typedef struct {
struct vec2f_t {
float x, y;
} vec2f_t;
};
typedef struct {
union {
struct {
union { float x, d; };
union { float y, u; };
union { float z, v; };
};
vec2f_t vec2;
};
} vec3f_t;
static_assert(sizeof(vec3f_t) == sizeof(float) * 3);
static_assert(sizeof(FVector3) == sizeof(float) * 3);
#include "basics.h"

View file

@ -73,7 +73,7 @@ typedef struct
typedef struct { uint8_t v[3], ni; } md2vert_t; //compressed vertex coords (x,y,z)
typedef struct
{
vec3f_t mul, add; //scale&translation vector
FVector3 mul, add; //scale&translation vector
char name[16]; //frame name
md2vert_t verts[1]; //first vertex of this frame
} md2frame_t;
@ -104,7 +104,7 @@ typedef struct { int16_t x, y, z; uint8_t nlat, nlng; } md3xyzn_t; //xyz are [10
typedef struct
{
vec3f_t min, max, cen; //bounding box&origin
FVector3 min, max, cen; //bounding box&origin
float r; //radius of bounding sphere
char nam[16]; //ascz frame name
} md3frame_t;
@ -112,7 +112,7 @@ typedef struct
typedef struct
{
char nam[64]; //ascz tag name
vec3f_t p, x, y, z; //tag object pos&orient
FVector3 p, x, y, z; //tag object pos&orient
} md3tag_t;
typedef struct
@ -163,7 +163,7 @@ struct md3model_t : public idmodel_t
//MD3 specific
md3head_t head;
vec3f_t *muladdframes;
FVector3 *muladdframes;
uint16_t *indexes;
uint16_t *vindexes;
@ -183,7 +183,7 @@ FGameTexture* mdloadskin(idmodel_t* m, int32_t number, int32_t pal, int32_t surf
void mdinit(void);
void freeallmodels(void);
int32_t polymost_mddraw(tspriteptr_t tspr);
EXTERN void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float mat[16]);
EXTERN void md3_vox_calcmat_common(tspriteptr_t tspr, const FVector3 *a0, float f, float mat[16]);
EXTERN int32_t mdpause;
EXTERN int32_t nextmodelid;

View file

@ -81,7 +81,7 @@ static int32_t nummodelsalloced = 0;
static int32_t maxmodelverts = 0, allocmodelverts = 0;
static int32_t maxmodeltris = 0, allocmodeltris = 0;
static vec3f_t *vertlist = NULL; //temp array to store interpolated vertices for drawing
static FVector3 *vertlist = NULL; //temp array to store interpolated vertices for drawing
#ifdef USE_GLEXT
static int32_t allocvbos = 0, curvbo = 0;
@ -303,7 +303,7 @@ int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32
return 0;
}
int32_t md_definehud(int32_t modelid, int32_t tilex, vec3f_t add, int32_t angadd, int32_t flags, int32_t fov)
int32_t md_definehud(int32_t modelid, int32_t tilex, FVector3 add, int32_t angadd, int32_t flags, int32_t fov)
{
if (!mdinited) mdinit();
@ -685,7 +685,7 @@ static md2model_t *md2load(FileReader & fil, const char *filnam)
m3->numframes = m3->head.numframes;
m3->head.frames = (md3frame_t *)M_Calloc(m3->head.numframes, sizeof(md3frame_t));
m3->muladdframes = (vec3f_t *)M_Calloc(m->numframes * 2, sizeof(vec3f_t));
m3->muladdframes = (FVector3 *)M_Calloc(m->numframes * 2, sizeof(FVector3));
f = (md2frame_t *)(m->frames);
@ -751,9 +751,9 @@ static md2model_t *md2load(FileReader & fil, const char *filnam)
while (k < m->numframes)
{
f = (md2frame_t *)&m->frames[k*m->framebytes];
s->xyzn[(k*s->numverts) + (i*3) + j].x = (int16_t) (((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x) * 64.f);
s->xyzn[(k*s->numverts) + (i*3) + j].y = (int16_t) (((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y) * 64.f);
s->xyzn[(k*s->numverts) + (i*3) + j].z = (int16_t) (((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z) * 64.f);
s->xyzn[(k*s->numverts) + (i*3) + j].x = (int16_t) (((f->verts[m->tris[i].v[j]].v[0] * f->mul.X) + f->add.X) * 64.f);
s->xyzn[(k*s->numverts) + (i*3) + j].y = (int16_t) (((f->verts[m->tris[i].v[j]].v[1] * f->mul.Y) + f->add.Y) * 64.f);
s->xyzn[(k*s->numverts) + (i*3) + j].z = (int16_t) (((f->verts[m->tris[i].v[j]].v[2] * f->mul.Z) + f->add.Z) * 64.f);
k++;
}
@ -996,8 +996,8 @@ static void md3postload_common(md3model_t *m)
{
frame = &m->head.frames[framei];
memset(&frame->min, 0, sizeof(vec3f_t));
memset(&frame->max, 0, sizeof(vec3f_t));
memset(&frame->min, 0, sizeof(FVector3));
memset(&frame->max, 0, sizeof(FVector3));
frame->r = 0.0f;
@ -1013,9 +1013,9 @@ static void md3postload_common(md3model_t *m)
{
md3xyzn_t const & framevert = frameverts[0];
frame->min.x = framevert.x;
frame->min.y = framevert.y;
frame->min.z = framevert.z;
frame->min.X = framevert.x;
frame->min.Y = framevert.y;
frame->min.Z = framevert.z;
frame->max = frame->min;
}
@ -1023,20 +1023,20 @@ static void md3postload_common(md3model_t *m)
{
md3xyzn_t const & framevert = frameverts[verti];
if (frame->min.x > framevert.x)
frame->min.x = framevert.x;
if (frame->max.x < framevert.x)
frame->max.x = framevert.x;
if (frame->min.X > framevert.x)
frame->min.X = framevert.x;
if (frame->max.X < framevert.x)
frame->max.X = framevert.x;
if (frame->min.y > framevert.y)
frame->min.y = framevert.y;
if (frame->max.y < framevert.y)
frame->max.y = framevert.y;
if (frame->min.Y > framevert.y)
frame->min.Y = framevert.y;
if (frame->max.Y < framevert.y)
frame->max.Y = framevert.y;
if (frame->min.z > framevert.z)
frame->min.z = framevert.z;
if (frame->max.z < framevert.z)
frame->max.z = framevert.z;
if (frame->min.Z > framevert.z)
frame->min.Z = framevert.z;
if (frame->max.Z < framevert.z)
frame->max.Z = framevert.z;
}
++verti;
@ -1045,9 +1045,9 @@ static void md3postload_common(md3model_t *m)
++surfi;
}
frame->cen.x = (frame->min.x + frame->max.x) * .5f;
frame->cen.y = (frame->min.y + frame->max.y) * .5f;
frame->cen.z = (frame->min.z + frame->max.z) * .5f;
frame->cen.X = (frame->min.X + frame->max.X) * .5f;
frame->cen.Y = (frame->min.Y + frame->max.Y) * .5f;
frame->cen.Z = (frame->min.Z + frame->max.Z) * .5f;
surfi = 0;
while (surfi < m->head.numsurfs)
@ -1061,9 +1061,9 @@ static void md3postload_common(md3model_t *m)
{
md3xyzn_t const & framevert = frameverts[verti];
vec1[0] = framevert.x - frame->cen.x;
vec1[1] = framevert.y - frame->cen.y;
vec1[2] = framevert.z - frame->cen.z;
vec1[0] = framevert.x - frame->cen.X;
vec1[1] = framevert.y - frame->cen.Y;
vec1[2] = framevert.z - frame->cen.Z;
dist = vec1[0] * vec1[0] + vec1[1] * vec1[1] + vec1[2] * vec1[2];
@ -1083,7 +1083,7 @@ static void md3postload_common(md3model_t *m)
}
void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float mat[16])
void md3_vox_calcmat_common(tspriteptr_t tspr, const FVector3 *a0, float f, float mat[16])
{
float k0, k1, k2, k3, k4, k5, k6, k7;
@ -1106,9 +1106,9 @@ void md3_vox_calcmat_common(tspriteptr_t tspr, const vec3f_t *a0, float f, float
mat[10] = k4*k7 - k5*k6;
mat[14] = k2*k6 + k3*k7;
mat[12] = (mat[12] + a0->y*mat[0]) + (a0->z*mat[4] + a0->x*mat[ 8]);
mat[13] = (mat[13] + a0->y*mat[1]) + (a0->z*mat[5] + a0->x*mat[ 9]);
mat[14] = (mat[14] + a0->y*mat[2]) + (a0->z*mat[6] + a0->x*mat[10]);
mat[12] = (mat[12] + a0->Y*mat[0]) + (a0->Z*mat[4] + a0->X*mat[ 8]);
mat[13] = (mat[13] + a0->Y*mat[1]) + (a0->Z*mat[5] + a0->X*mat[ 9]);
mat[14] = (mat[14] + a0->Y*mat[2]) + (a0->Z*mat[6] + a0->X*mat[10]);
}
static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle,
@ -1130,7 +1130,7 @@ static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle,
vt->SetTexCoord(s->uv[k].u, s->uv[k].v);
vt->SetVertex(vertlist[k].x, vertlist[k].y, vertlist[k].z);
vt->SetVertex(vertlist[k].X, vertlist[k].Y, vertlist[k].Z);
}
}
GLInterface.Draw(DT_Triangles, data.second, s->numtris *3);
@ -1138,7 +1138,7 @@ static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle,
static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
{
vec3f_t m0, m1, a0;
FVector3 m0, m1, a0;
md3xyzn_t *v0, *v1;
int32_t i, surfi;
float f, g, k0, k1, k2=0, k3=0, mat[16]; // inits: compiler-happy
@ -1170,11 +1170,11 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
m->nframe = clamp(m->nframe, 0, m->numframes-1);
}
m0.z = m0.y = m0.x = g *= m->scale * (1.f/64.f);
m1.z = m1.y = m1.x = f *= m->scale * (1.f/64.f);
m0.Z = m0.Y = m0.X = g *= m->scale * (1.f/64.f);
m1.Z = m1.Y = m1.X = f *= m->scale * (1.f/64.f);
a0.x = a0.y = 0;
a0.z = m->zadd * m->scale;
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 = (float)tspr->z+spriteext[tspr->owner].position_offset.z;
@ -1186,28 +1186,28 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
// Parkar: Changed to use the same method as centeroriented sprites
if (globalorientation&8) //y-flipping
{
m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z;
m0.Z = -m0.Z; m1.Z = -m1.Z; a0.Z = -a0.Z;
k0 -= (float)(sizyrep<<2);
}
if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping
if (globalorientation&4) { m0.Y = -m0.Y; m1.Y = -m1.Y; a0.Y = -a0.Y; } //x-flipping
// yoffset differs from zadd in that it does not follow cstat&8 y-flipping
a0.z += m->yoffset*m->scale;
a0.Z += m->yoffset*m->scale;
f = ((float)tspr->xrepeat) * (1.f/64.f) * m->bscale;
m0.x *= f; m0.y *= -f;
m1.x *= f; m1.y *= -f;
a0.x *= f; a0.y *= -f;
m0.X *= f; m0.Y *= -f;
m1.X *= f; m1.Y *= -f;
a0.X *= f; a0.Y *= -f;
f = ((float)tspr->yrepeat) * (1.f/64.f) * m->bscale;
m0.z *= f; m1.z *= f; a0.z *= f;
m0.Z *= f; m1.Z *= f; a0.Z *= f;
// floor aligned
k1 = (float)tspr->y+spriteext[tspr->owner].position_offset.y;
if ((globalorientation&48)==32)
{
m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z;
m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y;
f = a0.x; a0.x = a0.z; a0.z = f;
m0.Z = -m0.Z; m1.Z = -m1.Z; a0.Z = -a0.Z;
m0.Y = -m0.Y; m1.Y = -m1.Y; a0.Y = -a0.Y;
f = a0.X; a0.X = a0.Z; a0.Z = f;
k1 += (float)(sizyrep>>3);
}
@ -1215,9 +1215,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
// calculations below again, but are needed for the base offsets.
f = (65536.f*512.f)/(fxdimen*fviewingrange);
g = 32.f/(fxdimen*gxyaspect);
m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x+spriteext[tspr->owner].position_offset.x-globalposx))* (1.f/1024.f) + a0.y)*f;
m0.x *=-f; m1.x *=-f; a0.x = ((k1 -fglobalposy) * -(1.f/1024.f) + a0.x)*-f;
m0.z *= g; m1.z *= g; a0.z = ((k0 -fglobalposz) * -(1.f/16384.f) + a0.z)*g;
m0.Y *= f; m1.Y *= f; a0.Y = (((float)(tspr->x+spriteext[tspr->owner].position_offset.x-globalposx))* (1.f/1024.f) + a0.Y)*f;
m0.X *=-f; m1.X *=-f; a0.X = ((k1 -fglobalposy) * -(1.f/1024.f) + a0.X)*-f;
m0.Z *= g; m1.Z *= g; a0.Z = ((k0 -fglobalposz) * -(1.f/16384.f) + a0.Z)*g;
md3_vox_calcmat_common(tspr, &a0, f, mat);
@ -1276,17 +1276,17 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
// PLAG: Cleaner model rotation code
if (sext->pitch || sext->roll)
{
float f = 1.f/((fxdimen * fviewingrange) * (256.f/(65536.f*128.f)) * (m0.x+m1.x));
float f = 1.f/((fxdimen * fviewingrange) * (256.f/(65536.f*128.f)) * (m0.X+m1.X));
memset(&a0, 0, sizeof(a0));
if (sext->pivot_offset.x)
a0.x = (float) sext->pivot_offset.x * f;
a0.X = (float) sext->pivot_offset.x * f;
if (sext->pivot_offset.y) // Compare with SCREEN_FACTORS above
a0.y = (float) sext->pivot_offset.y * f;
a0.Y = (float) sext->pivot_offset.y * f;
if ((sext->pivot_offset.z) && !(tspr->clipdist & TSPR_FLAGS_MDHACK)) // Compare with SCREEN_FACTORS above
a0.z = (float)sext->pivot_offset.z / (gxyaspect * fxdimen * (65536.f/128.f) * (m0.z+m1.z));
a0.Z = (float)sext->pivot_offset.z / (gxyaspect * fxdimen * (65536.f/128.f) * (m0.Z+m1.Z));
k0 = bcosf(sext->pitch, -14);
k1 = bsinf(sext->pitch, -14);
@ -1302,7 +1302,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
{
//PLAG : sorting stuff
uint16_t *indexhandle;
vec3f_t fp;
FVector3 fp;
const md3surf_t *const s = &m->head.surfs[surfi];
@ -1311,28 +1311,28 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
if (sext->pitch || sext->roll)
{
vec3f_t fp1, fp2;
FVector3 fp1, fp2;
for (i=s->numverts-1; i>=0; i--)
{
fp.z = v0[i].x + a0.x;
fp.x = v0[i].y + a0.y;
fp.y = v0[i].z + a0.z;
fp.Z = v0[i].x + a0.X;
fp.X = v0[i].y + a0.Y;
fp.Y = v0[i].z + a0.Z;
fp1.x = fp.x*k2 + fp.y*k3;
fp1.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1);
fp1.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0;
fp1.X = fp.X*k2 + fp.Y*k3;
fp1.Y = fp.X*k0*(-k3) + fp.Y*k0*k2 + fp.Z*(-k1);
fp1.Z = fp.X*k1*(-k3) + fp.Y*k1*k2 + fp.Z*k0;
fp.z = v1[i].x + a0.x;
fp.x = v1[i].y + a0.y;
fp.y = v1[i].z + a0.z;
fp.Z = v1[i].x + a0.X;
fp.X = v1[i].y + a0.Y;
fp.Y = v1[i].z + a0.Z;
fp2.x = fp.x*k2 + fp.y*k3;
fp2.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1);
fp2.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0;
fp.z = (fp1.z - a0.x)*m0.x + (fp2.z - a0.x)*m1.x;
fp.x = (fp1.x - a0.y)*m0.y + (fp2.x - a0.y)*m1.y;
fp.y = (fp1.y - a0.z)*m0.z + (fp2.y - a0.z)*m1.z;
fp2.X = fp.X*k2 + fp.Y*k3;
fp2.Y = fp.X*k0*(-k3) + fp.Y*k0*k2 + fp.Z*(-k1);
fp2.Z = fp.X*k1*(-k3) + fp.Y*k1*k2 + fp.Z*k0;
fp.Z = (fp1.Z - a0.X)*m0.X + (fp2.Z - a0.X)*m1.X;
fp.X = (fp1.X - a0.Y)*m0.Y + (fp2.X - a0.Y)*m1.Y;
fp.Y = (fp1.Y - a0.Z)*m0.Z + (fp2.Y - a0.Z)*m1.Z;
vertlist[i] = fp;
}
@ -1341,9 +1341,9 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
{
for (i=s->numverts-1; i>=0; i--)
{
fp.z = v0[i].x*m0.x + v1[i].x*m1.x;
fp.y = v0[i].z*m0.z + v1[i].z*m1.z;
fp.x = v0[i].y*m0.y + v1[i].y*m1.y;
fp.Z = v0[i].x*m0.X + v1[i].x*m1.X;
fp.Y = v0[i].z*m0.Z + v1[i].z*m1.Z;
fp.X = v0[i].y*m0.Y + v1[i].y*m1.Y;
vertlist[i] = fp;
}
@ -1376,28 +1376,28 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr)
{
for (i=0; i<=s->numtris-1; ++i)
{
vec3f_t const vlt[3] = { vertlist[s->tris[i].i[0]], vertlist[s->tris[i].i[1]], vertlist[s->tris[i].i[2]] };
FVector3 const vlt[3] = { vertlist[s->tris[i].i[0]], vertlist[s->tris[i].i[1]], vertlist[s->tris[i].i[2]] };
// Matrix multiplication - ugly but clear
vec3f_t const fp[3] = { { (vlt[0].x * mat[0]) + (vlt[0].y * mat[4]) + (vlt[0].z * mat[8]) + mat[12],
(vlt[0].x * mat[1]) + (vlt[0].y * mat[5]) + (vlt[0].z * mat[9]) + mat[13],
(vlt[0].x * mat[2]) + (vlt[0].y * mat[6]) + (vlt[0].z * mat[10]) + mat[14] },
FVector3 const fp[3] = { { (vlt[0].X * mat[0]) + (vlt[0].Y * mat[4]) + (vlt[0].Z * mat[8]) + mat[12],
(vlt[0].X * mat[1]) + (vlt[0].Y * mat[5]) + (vlt[0].Z * mat[9]) + mat[13],
(vlt[0].X * mat[2]) + (vlt[0].Y * mat[6]) + (vlt[0].Z * mat[10]) + mat[14] },
{ (vlt[1].x * mat[0]) + (vlt[1].y * mat[4]) + (vlt[1].z * mat[8]) + mat[12],
(vlt[1].x * mat[1]) + (vlt[1].y * mat[5]) + (vlt[1].z * mat[9]) + mat[13],
(vlt[1].x * mat[2]) + (vlt[1].y * mat[6]) + (vlt[1].z * mat[10]) + mat[14] },
{ (vlt[1].X * mat[0]) + (vlt[1].Y * mat[4]) + (vlt[1].Z * mat[8]) + mat[12],
(vlt[1].X * mat[1]) + (vlt[1].Y * mat[5]) + (vlt[1].Z * mat[9]) + mat[13],
(vlt[1].X * mat[2]) + (vlt[1].Y * mat[6]) + (vlt[1].Z * mat[10]) + mat[14] },
{ (vlt[2].x * mat[0]) + (vlt[2].y * mat[4]) + (vlt[2].z * mat[8]) + mat[12],
(vlt[2].x * mat[1]) + (vlt[2].y * mat[5]) + (vlt[2].z * mat[9]) + mat[13],
(vlt[2].x * mat[2]) + (vlt[2].y * mat[6]) + (vlt[2].z * mat[10]) + mat[14] } };
{ (vlt[2].X * mat[0]) + (vlt[2].Y * mat[4]) + (vlt[2].Z * mat[8]) + mat[12],
(vlt[2].X * mat[1]) + (vlt[2].Y * mat[5]) + (vlt[2].Z * mat[9]) + mat[13],
(vlt[2].X * mat[2]) + (vlt[2].Y * mat[6]) + (vlt[2].Z * mat[10]) + mat[14] } };
f = (fp[0].x * fp[0].x) + (fp[0].y * fp[0].y) + (fp[0].z * fp[0].z);
g = (fp[1].x * fp[1].x) + (fp[1].y * fp[1].y) + (fp[1].z * fp[1].z);
f = (fp[0].X * fp[0].X) + (fp[0].Y * fp[0].Y) + (fp[0].Z * fp[0].Z);
g = (fp[1].X * fp[1].X) + (fp[1].Y * fp[1].Y) + (fp[1].Z * fp[1].Z);
if (f > g)
f = g;
g = (fp[2].x * fp[2].x) + (fp[2].y * fp[2].y) + (fp[2].z * fp[2].z);
g = (fp[2].X * fp[2].X) + (fp[2].Y * fp[2].Y) + (fp[2].Z * fp[2].Z);
if (f > g)
f = g;
@ -1524,7 +1524,7 @@ int32_t polymost_mddraw(tspriteptr_t tspr)
{
if (maxmodelverts > allocmodelverts)
{
vertlist = (vec3f_t *) M_Realloc(vertlist, sizeof(vec3f_t)*maxmodelverts);
vertlist = (FVector3 *) M_Realloc(vertlist, sizeof(FVector3)*maxmodelverts);
allocmodelverts = maxmodelverts;
}

View file

@ -1123,18 +1123,18 @@ static void polymost_internal_nonparallaxed(vec2f_t n0, vec2f_t n1, float ryp0,
py[1] = y1;
py[2] = double(global_getzofslope_func((usectorptr_t)&sector[sectnum], oxy.x, oxy.y) - globalposz) * oy2 + ghoriz;
vec3f_t oxyz[2] = { { (float)(py[1] - py[2]), (float)(py[2] - py[0]), (float)(py[0] - py[1]) },
FVector3 oxyz[2] = { { (float)(py[1] - py[2]), (float)(py[2] - py[0]), (float)(py[0] - py[1]) },
{ (float)(px[2] - px[1]), (float)(px[0] - px[2]), (float)(px[1] - px[0]) } };
float const r = 1.f / (oxyz[0].x * px[0] + oxyz[0].y * px[1] + oxyz[0].z * px[2]);
float const r = 1.f / (oxyz[0].X * px[0] + oxyz[0].Y * px[1] + oxyz[0].Z * px[2]);
xtex.d = (oxyz[0].x * duv[0].d + oxyz[0].y * duv[1].d + oxyz[0].z * duv[2].d) * r;
xtex.u = (oxyz[0].x * duv[0].u + oxyz[0].y * duv[1].u + oxyz[0].z * duv[2].u) * r;
xtex.v = (oxyz[0].x * duv[0].v + oxyz[0].y * duv[1].v + oxyz[0].z * duv[2].v) * r;
xtex.d = (oxyz[0].X * duv[0].d + oxyz[0].Y * duv[1].d + oxyz[0].Z * duv[2].d) * r;
xtex.u = (oxyz[0].X * duv[0].u + oxyz[0].Y * duv[1].u + oxyz[0].Z * duv[2].u) * r;
xtex.v = (oxyz[0].X * duv[0].v + oxyz[0].Y * duv[1].v + oxyz[0].Z * duv[2].v) * r;
ytex.d = (oxyz[1].x * duv[0].d + oxyz[1].y * duv[1].d + oxyz[1].z * duv[2].d) * r;
ytex.u = (oxyz[1].x * duv[0].u + oxyz[1].y * duv[1].u + oxyz[1].z * duv[2].u) * r;
ytex.v = (oxyz[1].x * duv[0].v + oxyz[1].y * duv[1].v + oxyz[1].z * duv[2].v) * r;
ytex.d = (oxyz[1].X * duv[0].d + oxyz[1].Y * duv[1].d + oxyz[1].Z * duv[2].d) * r;
ytex.u = (oxyz[1].X * duv[0].u + oxyz[1].Y * duv[1].u + oxyz[1].Z * duv[2].u) * r;
ytex.v = (oxyz[1].X * duv[0].v + oxyz[1].Y * duv[1].v + oxyz[1].Z * duv[2].v) * r;
otex.d = duv[0].d - px[0] * xtex.d - py[0] * ytex.d;
otex.u = duv[0].u - px[0] * xtex.u - py[0] * ytex.u;
@ -1309,10 +1309,10 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
// Transform polygon to sky coordinates
for (int i = 0; i < n; i++)
{
vec3f_t const o = { dpxy[i].x-ghalfx, dpxy[i].y-ghalfy, ghalfx / gvrcorrection };
FVector3 const o = { dpxy[i].x-ghalfx, dpxy[i].y-ghalfy, ghalfx / gvrcorrection };
//Up/down rotation
vec3d_t v = { o.x, o.y * gchang - o.z * gshang, o.z * gchang + o.y * gshang };
vec3d_t v = { o.X, o.Y * gchang - o.Z * gshang, o.Z * gchang + o.Y * gshang };
float const r = (ghalfx / gvrcorrection) / v.z;
xys[i].x = v.x * r + ghalfx;
xys[i].y = v.y * r + ghalfy;
@ -1337,7 +1337,7 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
vv[1] = dd*((float)xdimscale*fviewingrange) * (1.f/(daptileyscale*65536.f));
vv[0] = dd*((float)((tilesize.y>>1)+dapyoffs)) - vv[1]*ghoriz;
int ti = (1<<(heightBits(globalpicnum))); if (ti != tilesize.y) ti += ti;
vec3f_t o;
FVector3 o;
xtex.d = xtex.v = 0;
ytex.d = ytex.u = 0;
@ -1360,9 +1360,9 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
int picnumbak = globalpicnum;
ti = globalpicnum;
o.y = fviewingrange/(ghalfx*256.f); o.z = 1.f/o.y;
o.Y = fviewingrange/(ghalfx*256.f); o.Z = 1.f/o.Y;
int y = ((int32_t)(((x0-ghalfx)*o.y)+fglobalang)>>(11-dapskybits));
int y = ((int32_t)(((x0-ghalfx)*o.Y)+fglobalang)>>(11-dapskybits));
float fx = x0;
do
@ -1372,14 +1372,14 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
globalpicnum = skytile;
if (npot)
{
fx = ((float)((y<<(11-dapskybits))-fglobalang))*o.z+ghalfx;
fx = ((float)((y<<(11-dapskybits))-fglobalang))*o.Z+ghalfx;
int tang = (y<<(11-dapskybits))&2047;
otex.u = otex.d*(t*((float)(tang)) * (1.f/2048.f) + xPanning) - xtex.u*fx;
}
else
otex.u = otex.d*(t*((float)(fglobalang-(y<<(11-dapskybits)))) * (1.f/2048.f) + xPanning) - xtex.u*ghalfx;
y++;
o.x = fx; fx = ((float)((y<<(11-dapskybits))-fglobalang))*o.z+ghalfx;
o.X = fx; fx = ((float)((y<<(11-dapskybits))-fglobalang))*o.Z+ghalfx;
if (fx > x1) { fx = x1; ti = -1; }
@ -1410,10 +1410,10 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
for (int i = 0; i < 3; i++)
{
vec2f_t const o = { fxy[i].x-ghalfx, fxy[i].y-ghalfy };
vec3f_t const o2 = { o.x, o.y, ghalfx / gvrcorrection };
FVector3 const o2 = { o.x, o.y, ghalfx / gvrcorrection };
//Up/down rotation (backwards)
vec3d_t v = { o2.x, o2.y * gchang + o2.z * gshang, o2.z * gchang - o2.y * gshang };
vec3d_t v = { o2.X, o2.Y * gchang + o2.Z * gshang, o2.Z * gchang - o2.Y * gshang };
float const r = (ghalfx / gvrcorrection) / v.z;
fxyt[i].x = v.x * r + ghalfx;
fxyt[i].y = v.y * r + ghalfy;
@ -1422,18 +1422,18 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
duvt[i].v = duv[i].v*r;
}
vec3f_t oxyz[2] = { { (float)(fxyt[1].y - fxyt[2].y), (float)(fxyt[2].y - fxyt[0].y), (float)(fxyt[0].y - fxyt[1].y) },
FVector3 oxyz[2] = { { (float)(fxyt[1].y - fxyt[2].y), (float)(fxyt[2].y - fxyt[0].y), (float)(fxyt[0].y - fxyt[1].y) },
{ (float)(fxyt[2].x - fxyt[1].x), (float)(fxyt[0].x - fxyt[2].x), (float)(fxyt[1].x - fxyt[0].x) } };
float const rr = 1.f / (oxyz[0].x * fxyt[0].x + oxyz[0].y * fxyt[1].x + oxyz[0].z * fxyt[2].x);
float const rr = 1.f / (oxyz[0].X * fxyt[0].x + oxyz[0].Y * fxyt[1].x + oxyz[0].Z * fxyt[2].x);
xtex.d = (oxyz[0].x * duvt[0].d + oxyz[0].y * duvt[1].d + oxyz[0].z * duvt[2].d) * rr;
xtex.u = (oxyz[0].x * duvt[0].u + oxyz[0].y * duvt[1].u + oxyz[0].z * duvt[2].u) * rr;
xtex.v = (oxyz[0].x * duvt[0].v + oxyz[0].y * duvt[1].v + oxyz[0].z * duvt[2].v) * rr;
xtex.d = (oxyz[0].X * duvt[0].d + oxyz[0].Y * duvt[1].d + oxyz[0].Z * duvt[2].d) * rr;
xtex.u = (oxyz[0].X * duvt[0].u + oxyz[0].Y * duvt[1].u + oxyz[0].Z * duvt[2].u) * rr;
xtex.v = (oxyz[0].X * duvt[0].v + oxyz[0].Y * duvt[1].v + oxyz[0].Z * duvt[2].v) * rr;
ytex.d = (oxyz[1].x * duvt[0].d + oxyz[1].y * duvt[1].d + oxyz[1].z * duvt[2].d) * rr;
ytex.u = (oxyz[1].x * duvt[0].u + oxyz[1].y * duvt[1].u + oxyz[1].z * duvt[2].u) * rr;
ytex.v = (oxyz[1].x * duvt[0].v + oxyz[1].y * duvt[1].v + oxyz[1].z * duvt[2].v) * rr;
ytex.d = (oxyz[1].X * duvt[0].d + oxyz[1].Y * duvt[1].d + oxyz[1].Z * duvt[2].d) * rr;
ytex.u = (oxyz[1].X * duvt[0].u + oxyz[1].Y * duvt[1].u + oxyz[1].Z * duvt[2].u) * rr;
ytex.v = (oxyz[1].X * duvt[0].v + oxyz[1].Y * duvt[1].v + oxyz[1].Z * duvt[2].v) * rr;
otex.d = duvt[0].d - fxyt[0].x * xtex.d - fxyt[0].y * ytex.d;
otex.u = duvt[0].u - fxyt[0].x * xtex.u - fxyt[0].y * ytex.u;
@ -1448,13 +1448,13 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
{
int const j = i < n-1 ? i + 1 : 0;
if (xys[i].x >= o.x)
if (xys[i].x >= o.X)
cxy[n2++] = xys[i];
if ((xys[i].x >= o.x) != (xys[j].x >= o.x))
if ((xys[i].x >= o.X) != (xys[j].x >= o.X))
{
float const r = (o.x - xys[i].x) / (xys[j].x - xys[i].x);
cxy[n2++] = { o.x, (xys[j].y - xys[i].y) * r + xys[i].y };
float const r = (o.X - xys[i].x) / (xys[j].x - xys[i].x);
cxy[n2++] = { o.X, (xys[j].y - xys[i].y) * r + xys[i].y };
}
}
@ -1476,10 +1476,10 @@ static void polymost_flatskyrender(vec2f_t const* const dpxy, int32_t const n, i
// Transform back to polymost coordinates
for (int i = 0; i < n3; i++)
{
vec3f_t const o = { cxy2[i].x-ghalfx, cxy2[i].y-ghalfy, ghalfx / gvrcorrection };
FVector3 const o = { cxy2[i].x-ghalfx, cxy2[i].y-ghalfy, ghalfx / gvrcorrection };
//Up/down rotation
vec3d_t v = { o.x, o.y * gchang + o.z * gshang, o.z * gchang - o.y * gshang };
vec3d_t v = { o.X, o.Y * gchang + o.Z * gshang, o.Z * gchang - o.Y * gshang };
float const r = (ghalfx / gvrcorrection) / v.z;
cxy[i].x = v.x * r + ghalfx;
cxy[i].y = v.y * r + ghalfy;
@ -2205,7 +2205,7 @@ void polymost_drawrooms()
gstang = -gstang;
//Generate viewport trapezoid (for handling screen up/down)
vec3f_t p[4] = { { 0-1, 0-1+ghorizcorrect, 0 },
FVector3 p[4] = { { 0-1, 0-1+ghorizcorrect, 0 },
{ (float)(windowxy2.x + 1 - windowxy1.x + 2), 0-1+ghorizcorrect, 0 },
{ (float)(windowxy2.x + 1 - windowxy1.x + 2), (float)(windowxy2.y + 1 - windowxy1.y + 2)+ghorizcorrect, 0 },
{ 0-1, (float)(windowxy2.y + 1 - windowxy1.y + 2)+ghorizcorrect, 0 } };
@ -2213,11 +2213,11 @@ void polymost_drawrooms()
for (auto & v : p)
{
//Tilt rotation (backwards)
vec2f_t const o = { (v.x-ghalfx)*ratio, (v.y-ghoriz)*ratio };
vec3f_t const o2 = { o.x*gctang + o.y*gstang, o.y*gctang - o.x*gstang + ghoriz2, ghalfx / gvrcorrection };
vec2f_t const o = { (v.X-ghalfx)*ratio, (v.Y-ghoriz)*ratio };
FVector3 const o2 = { o.x*gctang + o.y*gstang, o.y*gctang - o.x*gstang + ghoriz2, ghalfx / gvrcorrection };
//Up/down rotation (backwards)
v = { o2.x, o2.y * gchang + o2.z * gshang, o2.z * gchang - o2.y * gshang };
v = { o2.X, o2.Y * gchang + o2.Z * gshang, o2.Z * gchang - o2.Y * gshang };
}
if (inpreparemirror)
@ -2227,19 +2227,19 @@ void polymost_drawrooms()
//Clip to SCISDIST plane
int n = 0;
vec3f_t p2[6];
FVector3 p2[6];
for (bssize_t i=0; i<4; i++)
{
int const j = i < 3 ? i + 1 : 0;
if (p[i].z >= SCISDIST)
if (p[i].Z >= SCISDIST)
p2[n++] = p[i];
if ((p[i].z >= SCISDIST) != (p[j].z >= SCISDIST))
if ((p[i].Z >= SCISDIST) != (p[j].Z >= SCISDIST))
{
float const r = (SCISDIST - p[i].z) / (p[j].z - p[i].z);
p2[n++] = { (p[j].x - p[i].x) * r + p[i].x, (p[j].y - p[i].y) * r + p[i].y, SCISDIST };
float const r = (SCISDIST - p[i].Z) / (p[j].Z - p[i].Z);
p2[n++] = { (p[j].X - p[i].X) * r + p[i].X, (p[j].Y - p[i].Y) * r + p[i].Y, SCISDIST };
}
}
@ -2253,9 +2253,9 @@ void polymost_drawrooms()
for (bssize_t i = 0; i < n; i++)
{
float const r = (ghalfx / gvrcorrection) / p2[i].z;
sx[i] = p2[i].x * r + ghalfx;
sy[i] = p2[i].y * r + ghoriz;
float const r = (ghalfx / gvrcorrection) / p2[i].Z;
sx[i] = p2[i].X * r + ghalfx;
sy[i] = p2[i].Y * r + ghoriz;
}
polymost_initmosts(sx, sy, n);
@ -3811,35 +3811,35 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate)
}
vec3f_t m0 = { m->scale, m->scale, m->scale };
vec3f_t a0 = { 0, 0, m->zadd * m->scale };
FVector3 m0 = { m->scale, m->scale, m->scale };
FVector3 a0 = { 0, 0, m->zadd * m->scale };
k0 = m->bscale / 64.f;
f = (float)tspr->xrepeat * (256.f / 320.f) * k0;
if ((sprite[tspr->owner].cstat & 48) == 16)
{
f *= 1.25f;
a0.y -= tspr->xoffset * bcosf(spriteext[tspr->owner].angoff, -20);
a0.x += tspr->xoffset * bsinf(spriteext[tspr->owner].angoff, -20);
a0.Y -= tspr->xoffset * bcosf(spriteext[tspr->owner].angoff, -20);
a0.X += tspr->xoffset * bsinf(spriteext[tspr->owner].angoff, -20);
}
if (globalorientation & 8) { m0.z = -m0.z; a0.z = -a0.z; } //y-flipping
if (globalorientation & 4) { m0.x = -m0.x; a0.x = -a0.x; a0.y = -a0.y; } //x-flipping
if (globalorientation & 8) { m0.Z = -m0.Z; a0.Z = -a0.Z; } //y-flipping
if (globalorientation & 4) { m0.X = -m0.X; a0.X = -a0.X; a0.Y = -a0.Y; } //x-flipping
m0.x *= f; a0.x *= f; f = -f;
m0.y *= f; a0.y *= f;
m0.X *= f; a0.X *= f; f = -f;
m0.Y *= f; a0.Y *= f;
f = (float)tspr->yrepeat * k0;
m0.z *= f; a0.z *= f;
m0.Z *= f; a0.Z *= f;
k0 = (float)(tspr->z + spriteext[tspr->owner].position_offset.z);
f = ((globalorientation & 8) && (sprite[tspr->owner].cstat & 48) != 0) ? -4.f : 4.f;
k0 -= (tspr->yoffset * tspr->yrepeat) * f * m->bscale;
zoff = m->siz.z * .5f;
if (!(tspr->cstat & 128))
zoff += m->piv.z;
zoff += m->piv.Z;
else if ((tspr->cstat & 48) != 48)
{
zoff += m->piv.z;
zoff += m->piv.Z;
zoff -= m->siz.z * .5f;
}
if (globalorientation & 8) zoff = m->siz.z - zoff;
@ -3849,9 +3849,9 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate)
int const shadowHack = !!(tspr->clipdist & TSPR_FLAGS_MDHACK);
m0.y *= f; a0.y = (((float)(tspr->x + spriteext[tspr->owner].position_offset.x - globalposx)) * (1.f / 1024.f) + a0.y) * f;
m0.x *= -f; a0.x = (((float)(tspr->y + spriteext[tspr->owner].position_offset.y - globalposy)) * -(1.f / 1024.f) + a0.x) * -f;
m0.z *= g; a0.z = (((float)(k0 - globalposz - shadowHack)) * -(1.f / 16384.f) + a0.z) * g;
m0.Y *= f; a0.Y = (((float)(tspr->x + spriteext[tspr->owner].position_offset.x - globalposx)) * (1.f / 1024.f) + a0.Y) * f;
m0.X *= -f; a0.X = (((float)(tspr->y + spriteext[tspr->owner].position_offset.y - globalposy)) * -(1.f / 1024.f) + a0.X) * -f;
m0.Z *= g; a0.Z = (((float)(k0 - globalposz - shadowHack)) * -(1.f / 16384.f) + a0.Z) * g;
float mat[16];
md3_vox_calcmat_common(tspr, &a0, f, mat);
@ -3898,13 +3898,13 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr, bool rotate)
memcpy(omat, mat, sizeof(omat));
f = 1.f / 64.f;
g = m0.x * f; mat[0] *= g; mat[1] *= g; mat[2] *= g;
g = m0.y * f; mat[4] = omat[8] * g; mat[5] = omat[9] * g; mat[6] = omat[10] * g;
g = -m0.z * f; mat[8] = omat[4] * g; mat[9] = omat[5] * g; mat[10] = omat[6] * g;
g = m0.X * f; mat[0] *= g; mat[1] *= g; mat[2] *= g;
g = m0.Y * f; mat[4] = omat[8] * g; mat[5] = omat[9] * g; mat[6] = omat[10] * g;
g = -m0.Z * f; mat[8] = omat[4] * g; mat[9] = omat[5] * g; mat[10] = omat[6] * g;
//
mat[12] -= (m->piv.x * mat[0] + m->piv.y * mat[4] + zoff * mat[8]);
mat[13] -= (m->piv.x * mat[1] + m->piv.y * mat[5] + zoff * mat[9]);
mat[14] -= (m->piv.x * mat[2] + m->piv.y * mat[6] + zoff * mat[10]);
mat[12] -= (m->piv.X * mat[0] + m->piv.Y * mat[4] + zoff * mat[8]);
mat[13] -= (m->piv.X * mat[1] + m->piv.Y * mat[5] + zoff * mat[9]);
mat[14] -= (m->piv.X * mat[2] + m->piv.Y * mat[6] + zoff * mat[10]);
//
//Let OpenGL (and perhaps hardware :) handle the matrix rotation
mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f;

View file

@ -1941,7 +1941,7 @@ static bool parseModelHudBlock(FScanner& sc)
for (int i = starttile; i <= endtile; i++)
{
vec3f_t addf = { (float)add.X, (float)add.Y, (float)add.Z };
FVector3 addf = { (float)add.X, (float)add.Y, (float)add.Z };
int res = md_definehud(mdglobal.lastmodelid, i, addf, angadd, flags, fov);
if (res < 0)
{

View file

@ -74,9 +74,9 @@ static voxmodel_t* voxload(int lumpnum)
auto pivot = voxel->Mips[0].Pivot;
vm->mdnum = 1; //VOXel model id
vm->scale = vm->bscale = 1.f;
vm->piv.x = float(pivot.X);
vm->piv.y = float(pivot.Y);
vm->piv.z = float(pivot.Z);
vm->piv.X = float(pivot.X);
vm->piv.Y = float(pivot.Y);
vm->piv.Z = float(pivot.Z);
vm->siz.x = voxel->Mips[0].SizeX;
vm->siz.y = voxel->Mips[0].SizeY;
vm->siz.z = voxel->Mips[0].SizeZ;

View file

@ -8,7 +8,7 @@ struct voxmodel_t : public mdmodel_t
{
FVoxelModel* model = nullptr;
vec3_t siz;
vec3f_t piv;
FVector3 piv;
int32_t is8bit;
};

View file

@ -513,10 +513,10 @@ bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, se
float zoff = voxel->siz.z * .5f;
if (!(spr->cstat & CSTAT_SPRITE_YCENTER))
zoff += voxel->piv.z;
zoff += voxel->piv.Z;
else if ((spr->cstat & CSTAT_SPRITE_ALIGNMENT) != CSTAT_SPRITE_ALIGNMENT_SLAB)
{
zoff += voxel->piv.z;
zoff += voxel->piv.Z;
zoff -= voxel->siz.z * .5f;
}
if (spr->cstat & CSTAT_SPRITE_YFLIP) zoff = voxel->siz.z - zoff;
@ -526,7 +526,7 @@ bool HWSprite::ProcessVoxel(HWDrawInfo* di, voxmodel_t* vox, spritetype* spr, se
rotmat.rotate(buildang(ang).asdeg() - 90.f, 0, 1, 0);
rotmat.scale(scalevec.X, scalevec.Z, scalevec.Y);
// Apply pivot last
rotmat.translate(-voxel->piv.x, zoff, voxel->piv.y);
rotmat.translate(-voxel->piv.X, zoff, voxel->piv.Y);