entity_t *ent;
int i, j;
char name[32];
+ vec3_t org;
for (i = 0, ent = cl.entities;i < cl.num_entities;i++, ent++)
{
strlcpy(name, modelname, 25);
for (j = (int)strlen(name);j < 25;j++)
name[j] = ' ';
- Con_Printf("%3i: %s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.matrix.m[0][3], (int) ent->render.matrix.m[1][3], (int) ent->render.matrix.m[2][3], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
+ Matrix4x4_OriginFromMatrix(&ent->render.matrix, org);
+ Con_Printf("%3i: %s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) org[0], (int) org[1], (int) org[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
}
}
//static const vec3_t nomodelmaxs = {16, 16, 16};
void CL_BoundingBoxForEntity(entity_render_t *ent)
{
+ vec3_t org;
model_t *model = ent->model;
+ Matrix4x4_OriginFromMatrix(&ent->matrix, org);
if (model)
{
- //if (ent->angles[0] || ent->angles[2])
+ // NOTE: this directly extracts vector components from the matrix, which relies on the matrix orientation!
if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
{
// pitch or roll
- ent->mins[0] = ent->matrix.m[0][3] + model->rotatedmins[0];
- ent->mins[1] = ent->matrix.m[1][3] + model->rotatedmins[1];
- ent->mins[2] = ent->matrix.m[2][3] + model->rotatedmins[2];
- ent->maxs[0] = ent->matrix.m[0][3] + model->rotatedmaxs[0];
- ent->maxs[1] = ent->matrix.m[1][3] + model->rotatedmaxs[1];
- ent->maxs[2] = ent->matrix.m[2][3] + model->rotatedmaxs[2];
- //VectorAdd(ent->origin, model->rotatedmins, ent->mins);
- //VectorAdd(ent->origin, model->rotatedmaxs, ent->maxs);
+ ent->mins[0] = org[0] + model->rotatedmins[0];
+ ent->mins[1] = org[1] + model->rotatedmins[1];
+ ent->mins[2] = org[2] + model->rotatedmins[2];
+ ent->maxs[0] = org[0] + model->rotatedmaxs[0];
+ ent->maxs[1] = org[1] + model->rotatedmaxs[1];
+ ent->maxs[2] = org[2] + model->rotatedmaxs[2];
}
- //else if (ent->angles[1])
else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
{
// yaw
- ent->mins[0] = ent->matrix.m[0][3] + model->yawmins[0];
- ent->mins[1] = ent->matrix.m[1][3] + model->yawmins[1];
- ent->mins[2] = ent->matrix.m[2][3] + model->yawmins[2];
- ent->maxs[0] = ent->matrix.m[0][3] + model->yawmaxs[0];
- ent->maxs[1] = ent->matrix.m[1][3] + model->yawmaxs[1];
- ent->maxs[2] = ent->matrix.m[2][3] + model->yawmaxs[2];
- //VectorAdd(ent->origin, model->yawmins, ent->mins);
- //VectorAdd(ent->origin, model->yawmaxs, ent->maxs);
+ ent->mins[0] = org[0] + model->yawmins[0];
+ ent->mins[1] = org[1] + model->yawmins[1];
+ ent->mins[2] = org[2] + model->yawmins[2];
+ ent->maxs[0] = org[0] + model->yawmaxs[0];
+ ent->maxs[1] = org[1] + model->yawmaxs[1];
+ ent->maxs[2] = org[2] + model->yawmaxs[2];
}
else
{
- ent->mins[0] = ent->matrix.m[0][3] + model->normalmins[0];
- ent->mins[1] = ent->matrix.m[1][3] + model->normalmins[1];
- ent->mins[2] = ent->matrix.m[2][3] + model->normalmins[2];
- ent->maxs[0] = ent->matrix.m[0][3] + model->normalmaxs[0];
- ent->maxs[1] = ent->matrix.m[1][3] + model->normalmaxs[1];
- ent->maxs[2] = ent->matrix.m[2][3] + model->normalmaxs[2];
- //VectorAdd(ent->origin, model->normalmins, ent->mins);
- //VectorAdd(ent->origin, model->normalmaxs, ent->maxs);
+ ent->mins[0] = org[0] + model->normalmins[0];
+ ent->mins[1] = org[1] + model->normalmins[1];
+ ent->mins[2] = org[2] + model->normalmins[2];
+ ent->maxs[0] = org[0] + model->normalmaxs[0];
+ ent->maxs[1] = org[1] + model->normalmaxs[1];
+ ent->maxs[2] = org[2] + model->normalmaxs[2];
}
}
else
{
- ent->mins[0] = ent->matrix.m[0][3] - 16;
- ent->mins[1] = ent->matrix.m[1][3] - 16;
- ent->mins[2] = ent->matrix.m[2][3] - 16;
- ent->maxs[0] = ent->matrix.m[0][3] + 16;
- ent->maxs[1] = ent->matrix.m[1][3] + 16;
- ent->maxs[2] = ent->matrix.m[2][3] + 16;
- //VectorAdd(ent->origin, nomodelmins, ent->mins);
- //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
+ ent->mins[0] = org[0] - 16;
+ ent->mins[1] = org[1] - 16;
+ ent->mins[2] = org[2] - 16;
+ ent->maxs[0] = org[0] + 16;
+ ent->maxs[1] = org[1] + 16;
+ ent->maxs[2] = org[2] + 16;
}
}
memset (dl, 0, sizeof(*dl));
Matrix4x4_Normalize(&dl->matrix, matrix);
dl->ent = ent;
- dl->origin[0] = dl->matrix.m[0][3];
- dl->origin[1] = dl->matrix.m[1][3];
- dl->origin[2] = dl->matrix.m[2][3];
+ Matrix4x4_OriginFromMatrix(&dl->matrix, dl->origin);
CL_FindNonSolidLocation(dl->origin, dl->origin, 6);
- dl->matrix.m[0][3] = dl->origin[0];
- dl->matrix.m[1][3] = dl->origin[1];
- dl->matrix.m[2][3] = dl->origin[2];
+ Matrix4x4_SetOrigin(&dl->matrix, dl->origin[0], dl->origin[1], dl->origin[2]);
dl->radius = radius;
dl->color[0] = red;
dl->color[1] = green;
Matrix4x4_Transform(&e->render.matrix, o, origin);
}
else
- {
- origin[0] = e->render.matrix.m[0][3];
- origin[1] = e->render.matrix.m[1][3];
- origin[2] = e->render.matrix.m[2][3];
- }
+ Matrix4x4_OriginFromMatrix(&e->render.matrix, origin);
trailtype = EFFECT_NONE;
dlightradius = 0;
dlightcolor[0] = 0;
Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
trace = CL_TraceBox(origin, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
tempmatrix = e->render.matrix;
- tempmatrix.m[0][3] = trace.endpos[0];
- tempmatrix.m[1][3] = trace.endpos[1];
- tempmatrix.m[2][3] = trace.endpos[2];
+ Matrix4x4_SetOrigin(&tempmatrix, trace.endpos[0], trace.endpos[1], trace.endpos[2]);
CL_AllocDlight(NULL, &tempmatrix, 100, e->persistent.muzzleflash, e->persistent.muzzleflash, e->persistent.muzzleflash, 0, 0, 0, -1, true, 0, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
e->persistent.muzzleflash -= (cl.time - cl.oldtime) * 10;
}
//dlightmatrix = e->render.matrix;
// hack to make glowing player light shine on their gun
//if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
- // dlightmatrix.m[2][3] += 30;
+ // Matrix4x4_AdjustOrigin(&dlightmatrix, 0, 0, 30);
CL_AllocDlight(&e->render, &e->render.matrix, dlightradius, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
}
// custom rtlight
if (vid.stereobuffer || r_stereo_redblue.integer || r_stereo_redgreen.integer || r_stereo_redcyan.integer || r_stereo_sidebyside.integer)
{
matrix4x4_t originalmatrix = r_view.matrix;
- r_view.matrix.m[0][3] = originalmatrix.m[0][3] + r_stereo_separation.value * -0.5f * r_view.matrix.m[0][1];
- r_view.matrix.m[1][3] = originalmatrix.m[1][3] + r_stereo_separation.value * -0.5f * r_view.matrix.m[1][1];
- r_view.matrix.m[2][3] = originalmatrix.m[2][3] + r_stereo_separation.value * -0.5f * r_view.matrix.m[2][1];
+ matrix4x4_t offsetmatrix;
+ Matrix4x4_CreateTranslate(&offsetmatrix, 0, r_stereo_separation.value * -0.5f, 0);
+ Matrix4x4_Concat(&r_view.matrix, &offsetmatrix, &originalmatrix);
if (r_stereo_sidebyside.integer)
r_stereo_side = 0;
SCR_DrawScreen();
- r_view.matrix.m[0][3] = originalmatrix.m[0][3] + r_stereo_separation.value * 0.5f * r_view.matrix.m[0][1];
- r_view.matrix.m[1][3] = originalmatrix.m[1][3] + r_stereo_separation.value * 0.5f * r_view.matrix.m[1][1];
- r_view.matrix.m[2][3] = originalmatrix.m[2][3] + r_stereo_separation.value * 0.5f * r_view.matrix.m[2][1];
+ Matrix4x4_CreateTranslate(&offsetmatrix, 0, r_stereo_separation.value * 0.5f, 0);
+ Matrix4x4_Concat(&r_view.matrix, &offsetmatrix, &originalmatrix);
if (r_stereo_sidebyside.integer)
r_stereo_side = 1;
val->_float = 1;
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
Matrix4x4_Copy(&tagmatrix, out);
// finally transformate by matrix of tag on parent entity
Matrix4x4_Concat(out, &attachmatrix, &tagmatrix);
- out->m[0][3] = attachmatrix.m[0][3] + attachmatrix.m[0][0]*tagmatrix.m[0][3] + attachmatrix.m[0][1]*tagmatrix.m[1][3] + attachmatrix.m[0][2]*tagmatrix.m[2][3];
- out->m[1][3] = attachmatrix.m[1][3] + attachmatrix.m[1][0]*tagmatrix.m[0][3] + attachmatrix.m[1][1]*tagmatrix.m[1][3] + attachmatrix.m[1][2]*tagmatrix.m[2][3];
- out->m[2][3] = attachmatrix.m[2][3] + attachmatrix.m[2][0]*tagmatrix.m[0][3] + attachmatrix.m[2][1]*tagmatrix.m[1][3] + attachmatrix.m[2][2]*tagmatrix.m[2][3];
Matrix4x4_Copy(&tagmatrix, out);
ent = attachent;
// Alias models have inverse pitch, bmodels can't have tags, so don't check for modeltype...
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], -ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
if ((val = PRVM_GETEDICTFIELDVALUE(ent, csqc_fieldoff_renderflags)) && (RF_VIEWMODEL & (int)val->_float))
{// RENDER_VIEWMODEL magic
Matrix4x4_CreateFromQuakeEntity(&entitymatrix, csqc_origin[0], csqc_origin[1], csqc_origin[2], csqc_angles[0], csqc_angles[1], csqc_angles[2], val->_float);
Matrix4x4_Concat(out, &entitymatrix, &tagmatrix);
- out->m[0][3] = entitymatrix.m[0][3] + val->_float*(entitymatrix.m[0][0]*tagmatrix.m[0][3] + entitymatrix.m[0][1]*tagmatrix.m[1][3] + entitymatrix.m[0][2]*tagmatrix.m[2][3]);
- out->m[1][3] = entitymatrix.m[1][3] + val->_float*(entitymatrix.m[1][0]*tagmatrix.m[0][3] + entitymatrix.m[1][1]*tagmatrix.m[1][3] + entitymatrix.m[1][2]*tagmatrix.m[2][3]);
- out->m[2][3] = entitymatrix.m[2][3] + val->_float*(entitymatrix.m[2][0]*tagmatrix.m[0][3] + entitymatrix.m[2][1]*tagmatrix.m[1][3] + entitymatrix.m[2][2]*tagmatrix.m[2][3]);
/*
// Cl_bob, ported from rendering code
// (don't count Z, or jumping messes it up)
bob = sqrt(ent->fields.client->velocity[0]*ent->fields.client->velocity[0] + ent->fields.client->velocity[1]*ent->fields.client->velocity[1])*cl_bob.value;
bob = bob*0.3 + bob*0.7*cycle;
- out->m[2][3] += bound(-7, bob, 4);
+ Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
}
*/
}
// set view pyramid
qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR
qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR
- backend_projectmatrix.m[0][0] = m[0];
- backend_projectmatrix.m[1][0] = m[1];
- backend_projectmatrix.m[2][0] = m[2];
- backend_projectmatrix.m[3][0] = m[3];
- backend_projectmatrix.m[0][1] = m[4];
- backend_projectmatrix.m[1][1] = m[5];
- backend_projectmatrix.m[2][1] = m[6];
- backend_projectmatrix.m[3][1] = m[7];
- backend_projectmatrix.m[0][2] = m[8];
- backend_projectmatrix.m[1][2] = m[9];
- backend_projectmatrix.m[2][2] = m[10];
- backend_projectmatrix.m[3][2] = m[11];
- backend_projectmatrix.m[0][3] = m[12];
- backend_projectmatrix.m[1][3] = m[13];
- backend_projectmatrix.m[2][3] = m[14];
- backend_projectmatrix.m[3][3] = m[15];
+ Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
GL_SetupView_Orientation_Identity();
CHECKGLERROR
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
GL_SetupView_Orientation_Identity();
CHECKGLERROR
- backend_projectmatrix.m[0][0] = m[0];
- backend_projectmatrix.m[1][0] = m[1];
- backend_projectmatrix.m[2][0] = m[2];
- backend_projectmatrix.m[3][0] = m[3];
- backend_projectmatrix.m[0][1] = m[4];
- backend_projectmatrix.m[1][1] = m[5];
- backend_projectmatrix.m[2][1] = m[6];
- backend_projectmatrix.m[3][1] = m[7];
- backend_projectmatrix.m[0][2] = m[8];
- backend_projectmatrix.m[1][2] = m[9];
- backend_projectmatrix.m[2][2] = m[10];
- backend_projectmatrix.m[3][2] = m[11];
- backend_projectmatrix.m[0][3] = m[12];
- backend_projectmatrix.m[1][3] = m[13];
- backend_projectmatrix.m[2][3] = m[14];
- backend_projectmatrix.m[3][3] = m[15];
+ Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
}
void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar)
qglLoadIdentity();CHECKGLERROR
qglOrtho(x1, x2, y2, y1, zNear, zFar);CHECKGLERROR
qglGetDoublev(GL_PROJECTION_MATRIX, m);CHECKGLERROR
- backend_projectmatrix.m[0][0] = m[0];
- backend_projectmatrix.m[1][0] = m[1];
- backend_projectmatrix.m[2][0] = m[2];
- backend_projectmatrix.m[3][0] = m[3];
- backend_projectmatrix.m[0][1] = m[4];
- backend_projectmatrix.m[1][1] = m[5];
- backend_projectmatrix.m[2][1] = m[6];
- backend_projectmatrix.m[3][1] = m[7];
- backend_projectmatrix.m[0][2] = m[8];
- backend_projectmatrix.m[1][2] = m[9];
- backend_projectmatrix.m[2][2] = m[10];
- backend_projectmatrix.m[3][2] = m[11];
- backend_projectmatrix.m[0][3] = m[12];
- backend_projectmatrix.m[1][3] = m[13];
- backend_projectmatrix.m[2][3] = m[14];
- backend_projectmatrix.m[3][3] = m[15];
+ Matrix4x4_FromArrayDoubleGL(&backend_projectmatrix, m);
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
GL_SetupView_Orientation_Identity();
CHECKGLERROR
out->m[3][3]=1.0f;
}
-void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z)
+void Matrix4x4_CreateTranslate (matrix4x4_t *out, double x, double y, double z)
{
out->m[0][0]=1.0f;
out->m[0][1]=0.0f;
out->m[3][3]=1.0f;
}
-void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z)
+void Matrix4x4_CreateRotate (matrix4x4_t *out, double angle, double x, double y, double z)
{
- float len, c, s;
+ double len, c, s;
len = x*x+y*y+z*z;
if (len != 0.0f)
out->m[3][3]=1.0f;
}
-void Matrix4x4_CreateScale (matrix4x4_t *out, float x)
+void Matrix4x4_CreateScale (matrix4x4_t *out, double x)
{
out->m[0][0]=x;
out->m[0][1]=0.0f;
out->m[3][3]=1.0f;
}
-void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z)
+void Matrix4x4_CreateScale3 (matrix4x4_t *out, double x, double y, double z)
{
out->m[0][0]=x;
out->m[0][1]=0.0f;
out->m[3][3]=1.0f;
}
-void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale)
+void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale)
{
double angle, sr, sp, sy, cr, cp, cy;
out->m[3][3] = 1.0f;
}
-void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, float blend)
+void Matrix4x4_FromArrayDoubleGL (matrix4x4_t *out, const double in[16])
{
- float iblend = 1 - blend;
+ out->m[0][0] = in[0];
+ out->m[1][0] = in[1];
+ out->m[2][0] = in[2];
+ out->m[3][0] = in[3];
+ out->m[0][1] = in[4];
+ out->m[1][1] = in[5];
+ out->m[2][1] = in[6];
+ out->m[3][1] = in[7];
+ out->m[0][2] = in[8];
+ out->m[1][2] = in[9];
+ out->m[2][2] = in[10];
+ out->m[3][2] = in[11];
+ out->m[0][3] = in[12];
+ out->m[1][3] = in[13];
+ out->m[2][3] = in[14];
+ out->m[3][3] = in[15];
+}
+
+void Matrix4x4_FromArrayDoubleD3D (matrix4x4_t *out, const double in[16])
+{
+ out->m[0][0] = in[0];
+ out->m[0][1] = in[1];
+ out->m[0][2] = in[2];
+ out->m[0][3] = in[3];
+ out->m[1][0] = in[4];
+ out->m[1][1] = in[5];
+ out->m[1][2] = in[6];
+ out->m[1][3] = in[7];
+ out->m[2][0] = in[8];
+ out->m[2][1] = in[9];
+ out->m[2][2] = in[10];
+ out->m[2][3] = in[11];
+ out->m[3][0] = in[12];
+ out->m[3][1] = in[13];
+ out->m[3][2] = in[14];
+ out->m[3][3] = in[15];
+}
+
+void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12])
+{
+ out[ 0] = in->m[0][0];
+ out[ 1] = in->m[1][0];
+ out[ 2] = in->m[2][0];
+ out[ 3] = in->m[0][1];
+ out[ 4] = in->m[1][1];
+ out[ 5] = in->m[2][1];
+ out[ 6] = in->m[0][2];
+ out[ 7] = in->m[1][2];
+ out[ 8] = in->m[2][2];
+ out[ 9] = in->m[0][3];
+ out[10] = in->m[1][3];
+ out[11] = in->m[2][3];
+}
+
+void Matrix4x4_FromArray12FloatGL(matrix4x4_t *out, const float in[12])
+{
+ out->m[0][0] = in[0];
+ out->m[1][0] = in[1];
+ out->m[2][0] = in[2];
+ out->m[3][0] = 0;
+ out->m[0][1] = in[3];
+ out->m[1][1] = in[4];
+ out->m[2][1] = in[5];
+ out->m[3][1] = 0;
+ out->m[0][2] = in[6];
+ out->m[1][2] = in[7];
+ out->m[2][2] = in[8];
+ out->m[3][2] = 0;
+ out->m[0][3] = in[9];
+ out->m[1][3] = in[10];
+ out->m[2][3] = in[11];
+ out->m[3][3] = 1;
+}
+
+void Matrix4x4_ToArray12FloatD3D(const matrix4x4_t *in, float out[12])
+{
+ out[ 0] = in->m[0][0];
+ out[ 1] = in->m[0][1];
+ out[ 2] = in->m[0][2];
+ out[ 3] = in->m[0][3];
+ out[ 4] = in->m[1][0];
+ out[ 5] = in->m[1][1];
+ out[ 6] = in->m[1][2];
+ out[ 7] = in->m[1][3];
+ out[ 8] = in->m[2][0];
+ out[ 9] = in->m[2][1];
+ out[10] = in->m[2][2];
+ out[11] = in->m[2][3];
+}
+
+void Matrix4x4_FromArray12FloatD3D(matrix4x4_t *out, const float in[12])
+{
+ out->m[0][0] = in[0];
+ out->m[0][1] = in[1];
+ out->m[0][2] = in[2];
+ out->m[0][3] = in[3];
+ out->m[1][0] = in[4];
+ out->m[1][1] = in[5];
+ out->m[1][2] = in[6];
+ out->m[1][3] = in[7];
+ out->m[2][0] = in[8];
+ out->m[2][1] = in[9];
+ out->m[2][2] = in[10];
+ out->m[2][3] = in[11];
+ out->m[3][0] = 0;
+ out->m[3][1] = 0;
+ out->m[3][2] = 0;
+ out->m[3][3] = 1;
+}
+
+void Matrix4x4_FromOriginQuat(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z, double w)
+{
+ m->m[0][0]=1-2*(y*y+z*z);m->m[0][1]= 2*(x*y-z*w);m->m[0][2]= 2*(x*z+y*w);m->m[0][3]=ox;
+ m->m[1][0]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[1][2]= 2*(y*z-x*w);m->m[1][3]=oy;
+ m->m[2][0]= 2*(x*z-y*w);m->m[2][1]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[2][3]=oz;
+ m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]=1;
+}
+
+// LordHavoc: I got this code from:
+//http://www.doom3world.org/phpbb2/viewtopic.php?t=2884
+void Matrix4x4_FromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z)
+{
+ double w = 1.0 - (x*x+y*y+z*z);
+ w = w > 0.0 ? -sqrt(w) : 0.0;
+ m->m[0][0]=1-2*(y*y+z*z);m->m[0][1]= 2*(x*y-z*w);m->m[0][2]= 2*(x*z+y*w);m->m[0][3]=ox;
+ m->m[1][0]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[1][2]= 2*(y*z-x*w);m->m[1][3]=oy;
+ m->m[2][0]= 2*(x*z-y*w);m->m[2][1]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[2][3]=oz;
+ m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]=1;
+}
+
+void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend)
+{
+ double iblend = 1 - blend;
out->m[0][0] = in1->m[0][0] * iblend + in2->m[0][0] * blend;
out->m[0][1] = in1->m[0][1] * iblend + in2->m[0][1] * blend;
out->m[0][2] = in1->m[0][2] * iblend + in2->m[0][2] * blend;
/*
void Matrix4x4_SimpleUntransform (const matrix4x4_t *in, const float v[3], float out[3])
{
- float t[3];
+ double t[3];
t[0] = v[0] - in->m[0][3];
t[1] = v[1] - in->m[1][3];
t[2] = v[2] - in->m[2][3];
*/
// FIXME: optimize
-void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z)
+void Matrix4x4_ConcatTranslate (matrix4x4_t *out, double x, double y, double z)
{
matrix4x4_t base, temp;
base = *out;
}
// FIXME: optimize
-void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z)
+void Matrix4x4_ConcatRotate (matrix4x4_t *out, double angle, double x, double y, double z)
{
matrix4x4_t base, temp;
base = *out;
}
// FIXME: optimize
-void Matrix4x4_ConcatScale (matrix4x4_t *out, float x)
+void Matrix4x4_ConcatScale (matrix4x4_t *out, double x)
{
matrix4x4_t base, temp;
base = *out;
}
// FIXME: optimize
-void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z)
+void Matrix4x4_ConcatScale3 (matrix4x4_t *out, double x, double y, double z)
{
matrix4x4_t base, temp;
base = *out;
out[2] = in->m[2][3];
}
-float Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in)
+double Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in)
{
// we only support uniform scaling, so assume the first row is enough
return (float)sqrt(in->m[0][0] * in->m[0][0] + in->m[0][1] * in->m[0][1] + in->m[0][2] * in->m[0][2]);
}
+void Matrix4x4_SetOrigin (matrix4x4_t *out, double x, double y, double z)
+{
+ out->m[0][3] = x;
+ out->m[1][3] = y;
+ out->m[2][3] = z;
+}
+
+void Matrix4x4_AdjustOrigin (matrix4x4_t *out, double x, double y, double z)
+{
+ out->m[0][3] += x;
+ out->m[1][3] += y;
+ out->m[2][3] += z;
+}
+
void Matrix4x4_CreateIdentity (matrix4x4_t *out);
// creates a translate matrix
// (moves vectors)
-void Matrix4x4_CreateTranslate (matrix4x4_t *out, float x, float y, float z);
+void Matrix4x4_CreateTranslate (matrix4x4_t *out, double x, double y, double z);
// creates a rotate matrix
// (rotates vectors)
-void Matrix4x4_CreateRotate (matrix4x4_t *out, float angle, float x, float y, float z);
+void Matrix4x4_CreateRotate (matrix4x4_t *out, double angle, double x, double y, double z);
// creates a scaling matrix
// (expands or contracts vectors)
// (warning: do not apply this kind of matrix to direction vectors)
-void Matrix4x4_CreateScale (matrix4x4_t *out, float x);
+void Matrix4x4_CreateScale (matrix4x4_t *out, double x);
// creates a squishing matrix
// (expands or contracts vectors differently in different axis)
// (warning: this is not reversed by Invert_Simple)
// (warning: do not apply this kind of matrix to direction vectors)
-void Matrix4x4_CreateScale3 (matrix4x4_t *out, float x, float y, float z);
+void Matrix4x4_CreateScale3 (matrix4x4_t *out, double x, double y, double z);
// creates a matrix for a quake entity
-void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, float x, float y, float z, float pitch, float yaw, float roll, float scale);
+void Matrix4x4_CreateFromQuakeEntity(matrix4x4_t *out, double x, double y, double z, double pitch, double yaw, double roll, double scale);
// converts a matrix4x4 to a set of 3D vectors for the 3 axial directions, and the translate
void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float vz[3], float t[3]);
// creates a matrix4x4 from a set of 3D vectors for axial directions, and translate
void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
+// creates a matrix4x4 from a float[16] array in the OpenGL orientation
+void Matrix4x4_FromArrayDoubleGL(matrix4x4_t *out, const double in[16]);
+// creates a matrix4x4 from a float[16] array in the Direct3D orientation
+void Matrix4x4_FromArrayDoubleD3D(matrix4x4_t *out, const double in[16]);
+
+// converts a matrix4x4 to a float[12] array in the OpenGL orientation
+void Matrix4x4_ToArray12FloatGL(const matrix4x4_t *in, float out[12]);
+// creates a matrix4x4 from a float[12] array in the OpenGL orientation
+void Matrix4x4_FromArray12FloatGL(matrix4x4_t *out, const float in[12]);
+// converts a matrix4x4 to a float[12] array in the Direct3D orientation
+void Matrix4x4_ToArray12FloatD3D(const matrix4x4_t *in, float out[12]);
+// creates a matrix4x4 from a float[12] array in the Direct3D orientation
+void Matrix4x4_FromArray12FloatD3D(matrix4x4_t *out, const float in[12]);
+
+// creates a matrix4x4 from an origin and quaternion (used mostly with skeletal model formats such as PSK)
+void Matrix4x4_FromOriginQuat(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z, double w);
+// creates a matrix4x4 from an origin and canonical unit-length quaternion (used mostly with skeletal model formats such as MD5)
+void Matrix4x4_FromDoom3Joint(matrix4x4_t *m, double ox, double oy, double oz, double x, double y, double z);
+
// blends two matrices together, at a given percentage (blend controls percentage of in2)
-void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, float blend);
+void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend);
// transforms a 3D vector through a matrix4x4
void Matrix4x4_Transform (const matrix4x4_t *in, const float v[3], float out[3]);
// ease of use functions
// immediately applies a Translate to the matrix
-void Matrix4x4_ConcatTranslate (matrix4x4_t *out, float x, float y, float z);
+void Matrix4x4_ConcatTranslate (matrix4x4_t *out, double x, double y, double z);
// immediately applies a Rotate to the matrix
-void Matrix4x4_ConcatRotate (matrix4x4_t *out, float angle, float x, float y, float z);
+void Matrix4x4_ConcatRotate (matrix4x4_t *out, double angle, double x, double y, double z);
// immediately applies a Scale to the matrix
-void Matrix4x4_ConcatScale (matrix4x4_t *out, float x);
+void Matrix4x4_ConcatScale (matrix4x4_t *out, double x);
// immediately applies a Scale3 to the matrix
-void Matrix4x4_ConcatScale3 (matrix4x4_t *out, float x, float y, float z);
+void Matrix4x4_ConcatScale3 (matrix4x4_t *out, double x, double y, double z);
// extracts origin vector (translate) from matrix
void Matrix4x4_OriginFromMatrix (const matrix4x4_t *in, float *out);
// extracts scaling factor from matrix (only works for uniform scaling)
-float Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in);
+double Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in);
+
+// replaces origin vector (translate) in matrix
+void Matrix4x4_SetOrigin (matrix4x4_t *out, double x, double y, double z);
+// moves origin vector (translate) in matrix by a simple translate
+void Matrix4x4_AdjustOrigin (matrix4x4_t *out, double x, double y, double z);
#endif
R_ConcatTransforms(boneframe + model->data_bones[tagindex].parent * 12, tempbonematrix, bonematrix);
tagindex = model->data_bones[tagindex].parent;
}
- outmatrix->m[0][0] = bonematrix[0];
- outmatrix->m[0][1] = bonematrix[1];
- outmatrix->m[0][2] = bonematrix[2];
- outmatrix->m[0][3] = bonematrix[3];
- outmatrix->m[1][0] = bonematrix[4];
- outmatrix->m[1][1] = bonematrix[5];
- outmatrix->m[1][2] = bonematrix[6];
- outmatrix->m[1][3] = bonematrix[7];
- outmatrix->m[2][0] = bonematrix[8];
- outmatrix->m[2][1] = bonematrix[9];
- outmatrix->m[2][2] = bonematrix[10];
- outmatrix->m[2][3] = bonematrix[11];
- outmatrix->m[3][0] = 0;
- outmatrix->m[3][1] = 0;
- outmatrix->m[3][2] = 0;
- outmatrix->m[3][3] = 1;
+ Matrix4x4_FromArray12FloatD3D(outmatrix, bonematrix);
}
else if (model->num_tags)
{
loadmodel->surfmesh.isanimated = loadmodel->numframes > 1 || loadmodel->animscenes[0].framecount > 1;
}
-static void Mod_PSKMODEL_AnimKeyToMatrix(float *origin, float *quat, matrix4x4_t *m)
-{
- float x = quat[0], y = quat[1], z = quat[2], w = quat[3];
- m->m[0][0]=1-2*(y*y+z*z);m->m[0][1]= 2*(x*y-z*w);m->m[0][2]= 2*(x*z+y*w);m->m[0][3]=origin[0];
- m->m[1][0]= 2*(x*y+z*w);m->m[1][1]=1-2*(x*x+z*z);m->m[1][2]= 2*(y*z-x*w);m->m[1][3]=origin[1];
- m->m[2][0]= 2*(x*z-y*w);m->m[2][1]= 2*(y*z+x*w);m->m[2][2]=1-2*(x*x+y*y);m->m[2][3]=origin[2];
- m->m[3][0]= 0 ;m->m[3][1]= 0 ;m->m[3][2]= 0 ;m->m[3][3]=1;
-}
-
// no idea why PSK/PSA files contain weird quaternions but they do...
#define PSKQUATNEGATIONS
void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend)
// load the poses from the animkeys
for (index = 0;index < numanimkeys;index++)
{
+ pskanimkeys_t *k = animkeys + index;
matrix4x4_t matrix;
- Mod_PSKMODEL_AnimKeyToMatrix(animkeys[index].origin, animkeys[index].quat, &matrix);
- loadmodel->data_poses[index*12+0] = matrix.m[0][0];
- loadmodel->data_poses[index*12+1] = matrix.m[0][1];
- loadmodel->data_poses[index*12+2] = matrix.m[0][2];
- loadmodel->data_poses[index*12+3] = matrix.m[0][3];
- loadmodel->data_poses[index*12+4] = matrix.m[1][0];
- loadmodel->data_poses[index*12+5] = matrix.m[1][1];
- loadmodel->data_poses[index*12+6] = matrix.m[1][2];
- loadmodel->data_poses[index*12+7] = matrix.m[1][3];
- loadmodel->data_poses[index*12+8] = matrix.m[2][0];
- loadmodel->data_poses[index*12+9] = matrix.m[2][1];
- loadmodel->data_poses[index*12+10] = matrix.m[2][2];
- loadmodel->data_poses[index*12+11] = matrix.m[2][3];
+ Matrix4x4_FromOriginQuat(&matrix, k->origin[0], k->origin[1], k->origin[2], k->quat[0], k->quat[1], k->quat[2], k->quat[3]);
+ Matrix4x4_ToArray12FloatD3D(&matrix, loadmodel->data_poses + index*12);
}
Mod_FreeSkinFiles(skinfiles);
Mem_Free(animfilebuffer);
float scale;
// nudge it toward the view to make sure it isn't in a wall
- org[0] = ent->matrix.m[0][3] - r_view.forward[0];
- org[1] = ent->matrix.m[1][3] - r_view.forward[1];
- org[2] = ent->matrix.m[2][3] - r_view.forward[2];
+ Matrix4x4_OriginFromMatrix(&ent->matrix, org);
+ VectorSubtract(org, r_view.forward, org);
switch(model->sprite.sprnum_type)
{
case SPR_VP_PARALLEL_UPRIGHT:
// (don't count Z, or jumping messes it up)
bob = sqrt(ent->fields.server->velocity[0]*ent->fields.server->velocity[0] + ent->fields.server->velocity[1]*ent->fields.server->velocity[1])*cl_bob.value;
bob = bob*0.3 + bob*0.7*cycle;
- out->m[2][3] += bound(-7, bob, 4);
+ Matrix4x4_AdjustOrigin(out, 0, 0, bound(-7, bob, 4));
}
*/
}
0 feature darkplaces renderer: add rtlight "avelocity" parameter to make lights that spin, useful with cubemaps (romi)
0 feature darkplaces renderer: make showfps display GL renderer string and CPU - figure out how to detect this from the OS
0 feature darkplaces renderer: save r_shadow_glsl* cvars (and possibly a few others) to config because they are useful user settings (SavageX)
+0 feature darkplaces renderer: support tcgen in q3 shaders (ob3lisk)
0 feature darkplaces server: DP_SV_FINDPVS
0 feature darkplaces server: add .maxspeed field to control player movement speed in engine code, call it QW_SV_MAXSPEED (Carni)
0 feature darkplaces server: add DP_QC_STRTOKEN extension with these functions: float strtokens(string s, string separator) = #;string strtoken(string s, string separator, float index) = #; (FrikaC)
else
{
r_view.matrix = ent->render.matrix;
- r_view.matrix.m[2][3] += cl.stats[STAT_VIEWHEIGHT];
+ Matrix4x4_AdjustOrigin(&r_view.matrix, 0, 0, cl.stats[STAT_VIEWHEIGHT]);
}
viewmodelmatrix = r_view.matrix;
}