mirror of
https://github.com/nzp-team/glquake.git
synced 2024-11-24 21:11:53 +00:00
Add entity scalefactor
This commit is contained in:
parent
9d29f00bc6
commit
79ce3c6bc3
8 changed files with 549 additions and 17 deletions
|
@ -549,6 +549,11 @@ if (bits&(1<<i))
|
|||
ent->rendercolor[2] = 0;
|
||||
// Tomaz - QC Alpha Scale Glow End
|
||||
|
||||
if (bits & U_SCALE)
|
||||
ent->scale = MSG_ReadByte();
|
||||
else
|
||||
ent->scale = ENTSCALE_DEFAULT;
|
||||
|
||||
if ( bits & U_NOLERP )
|
||||
ent->forcelink = true;
|
||||
|
||||
|
|
|
@ -157,13 +157,18 @@ qboolean R_CullBox (vec3_t mins, vec3_t maxs)
|
|||
}
|
||||
|
||||
|
||||
void R_RotateForEntity (entity_t *e)
|
||||
void R_RotateForEntity (entity_t *e, unsigned char scale)
|
||||
{
|
||||
glTranslatef (e->origin[0], e->origin[1], e->origin[2]);
|
||||
|
||||
glRotatef (e->angles[1], 0, 0, 1);
|
||||
glRotatef (-e->angles[0], 0, 1, 0);
|
||||
glRotatef (e->angles[2], 1, 0, 0);
|
||||
|
||||
if (scale != ENTSCALE_DEFAULT && scale != 0) {
|
||||
float scalefactor = ENTSCALE_DECODE(scale);
|
||||
glScalef(scalefactor, scalefactor, scalefactor);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -261,6 +266,8 @@ void R_DrawSpriteModel (entity_t *e)
|
|||
float *up, *right;
|
||||
vec3_t v_forward, v_right, v_up;
|
||||
msprite_t *psprite;
|
||||
float scale = ENTSCALE_DECODE(e->scale);
|
||||
if (scale == 0) scale = 1.0f;
|
||||
|
||||
// don't even bother culling, because it's just a single
|
||||
// polygon without a surface cache
|
||||
|
@ -294,23 +301,23 @@ void R_DrawSpriteModel (entity_t *e)
|
|||
glBegin (GL_QUADS);
|
||||
|
||||
glTexCoord2f (0, 1);
|
||||
VectorMA (e->origin, frame->down, up, point);
|
||||
VectorMA (point, frame->left, right, point);
|
||||
VectorMA (e->origin, frame->down * scale, up, point);
|
||||
VectorMA (point, frame->left * scale, right, point);
|
||||
glVertex3fv (point);
|
||||
|
||||
glTexCoord2f (0, 0);
|
||||
VectorMA (e->origin, frame->up, up, point);
|
||||
VectorMA (point, frame->left, right, point);
|
||||
VectorMA (e->origin, frame->up * scale, up, point);
|
||||
VectorMA (point, frame->left * scale, right, point);
|
||||
glVertex3fv (point);
|
||||
|
||||
glTexCoord2f (1, 0);
|
||||
VectorMA (e->origin, frame->up, up, point);
|
||||
VectorMA (point, frame->right, right, point);
|
||||
VectorMA (e->origin, frame->up * scale, up, point);
|
||||
VectorMA (point, frame->right * scale, right, point);
|
||||
glVertex3fv (point);
|
||||
|
||||
glTexCoord2f (1, 1);
|
||||
VectorMA (e->origin, frame->down, up, point);
|
||||
VectorMA (point, frame->right, right, point);
|
||||
VectorMA (e->origin, frame->down * scale, up, point);
|
||||
VectorMA (point, frame->right * scale, right, point);
|
||||
glVertex3fv (point);
|
||||
|
||||
glEnd ();
|
||||
|
@ -697,7 +704,7 @@ void R_DrawZombieLimb (entity_t *e, int which)
|
|||
}
|
||||
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, e->scale);
|
||||
|
||||
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
|
||||
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
|
||||
|
@ -814,7 +821,7 @@ void R_DrawTransparentAliasModel (entity_t *e)
|
|||
lightcolor[0] = lightcolor[1] = lightcolor[2] = 256.0f;
|
||||
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, e->scale);
|
||||
|
||||
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
|
||||
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
|
||||
|
@ -851,7 +858,7 @@ void R_DrawTransparentAliasModel (entity_t *e)
|
|||
if (r_shadows.value)
|
||||
{
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, e->scale);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glEnable (GL_BLEND);
|
||||
glColor4f (0,0,0,0.5);
|
||||
|
@ -1005,7 +1012,7 @@ void R_DrawAliasModel (entity_t *e)
|
|||
}
|
||||
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, ENTSCALE_DEFAULT);
|
||||
|
||||
if (!strcmp (clmodel->name, "progs/eyes.mdl") && gl_doubleeyes.value) {
|
||||
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2] - (22 + 8));
|
||||
|
@ -1016,11 +1023,14 @@ void R_DrawAliasModel (entity_t *e)
|
|||
// Special handling of view model to keep FOV from altering look. Pretty good. Not perfect but rather close.
|
||||
if ((e == &cl.viewent || e == &cl.viewent2) && scr_fov_viewmodel.value) {
|
||||
float scale = 1.0f / tan (DEG2RAD (scr_fov.value / 2.0f)) * scr_fov_viewmodel.value / 90.0f;
|
||||
if (e->scale != ENTSCALE_DEFAULT && e->scale != 0) scale *= ENTSCALE_DECODE(e->scale);
|
||||
glTranslatef (paliashdr->scale_origin[0] * scale, paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
|
||||
glScalef (paliashdr->scale[0] * scale, paliashdr->scale[1], paliashdr->scale[2]);
|
||||
} else {
|
||||
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
|
||||
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
|
||||
float scale = 1.0f;
|
||||
if (e->scale != ENTSCALE_DEFAULT && e->scale != 0) scale *= ENTSCALE_DECODE(e->scale);
|
||||
glTranslatef (paliashdr->scale_origin[0] * scale, paliashdr->scale_origin[1] * scale, paliashdr->scale_origin[2] * scale);
|
||||
glScalef (paliashdr->scale[0] * scale, paliashdr->scale[1] * scale, paliashdr->scale[2] * scale);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1095,7 +1105,7 @@ void R_DrawAliasModel (entity_t *e)
|
|||
if (r_shadows.value)
|
||||
{
|
||||
glPushMatrix ();
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, e->scale);
|
||||
glDisable (GL_TEXTURE_2D);
|
||||
glEnable (GL_BLEND);
|
||||
glColor4f (0,0,0,0.5);
|
||||
|
|
|
@ -1212,7 +1212,7 @@ void R_DrawBrushModel (entity_t *e)
|
|||
*/
|
||||
|
||||
e->angles[0] = -e->angles[0]; // stupid quake bug
|
||||
R_RotateForEntity (e);
|
||||
R_RotateForEntity (e, e->scale);
|
||||
e->angles[0] = -e->angles[0]; // stupid quake bug
|
||||
|
||||
//
|
||||
|
|
506
source/matrixlib.c
Normal file
506
source/matrixlib.c
Normal file
|
@ -0,0 +1,506 @@
|
|||
/*
|
||||
matrixlib.c - internal matrixlib
|
||||
Copyright (C) 2010 Uncle Mike
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "quakedef.h"
|
||||
#include <math.h>
|
||||
|
||||
|
||||
const matrix3x4 matrix3x4_identity =
|
||||
{
|
||||
{ 1, 0, 0, 0 }, // PITCH [forward], org[0]
|
||||
{ 0, 1, 0, 0 }, // YAW [right] , org[1]
|
||||
{ 0, 0, 1, 0 }, // ROLL [up] , org[2]
|
||||
};
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
Matrix3x4 operations
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
void Matrix3x4_VectorTransform( const matrix3x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] + in[0][3];
|
||||
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] + in[1][3];
|
||||
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2] + in[2][3];
|
||||
}
|
||||
|
||||
void Matrix3x4_VectorITransform( const matrix3x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
vec3_t dir;
|
||||
|
||||
dir[0] = v[0] - in[0][3];
|
||||
dir[1] = v[1] - in[1][3];
|
||||
dir[2] = v[2] - in[2][3];
|
||||
|
||||
out[0] = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0];
|
||||
out[1] = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1];
|
||||
out[2] = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix3x4_VectorRotate( const matrix3x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2];
|
||||
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2];
|
||||
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix3x4_VectorIRotate( const matrix3x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0];
|
||||
out[1] = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1];
|
||||
out[2] = v[0] * in[0][2] + v[1] * in[1][2] + v[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix3x4_ConcatTransforms( matrix3x4 out, const matrix3x4 in1, const matrix3x4 in2 )
|
||||
{
|
||||
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
|
||||
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
|
||||
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2];
|
||||
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + in1[0][2] * in2[2][3] + in1[0][3];
|
||||
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + in1[1][2] * in2[2][0];
|
||||
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + in1[1][2] * in2[2][1];
|
||||
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + in1[1][2] * in2[2][2];
|
||||
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + in1[1][2] * in2[2][3] + in1[1][3];
|
||||
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + in1[2][2] * in2[2][0];
|
||||
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1];
|
||||
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2];
|
||||
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3];
|
||||
}
|
||||
|
||||
void Matrix3x4_SetOrigin( matrix3x4 out, float x, float y, float z )
|
||||
{
|
||||
out[0][3] = x;
|
||||
out[1][3] = y;
|
||||
out[2][3] = z;
|
||||
}
|
||||
|
||||
void Matrix3x4_OriginFromMatrix( const matrix3x4 in, float *out )
|
||||
{
|
||||
out[0] = in[0][3];
|
||||
out[1] = in[1][3];
|
||||
out[2] = in[2][3];
|
||||
}
|
||||
|
||||
void Matrix3x4_FromOriginQuat( matrix3x4 out, const vec4_t quaternion, const vec3_t origin )
|
||||
{
|
||||
out[0][0] = 1.0f - 2.0f * quaternion[1] * quaternion[1] - 2.0f * quaternion[2] * quaternion[2];
|
||||
out[1][0] = 2.0f * quaternion[0] * quaternion[1] + 2.0f * quaternion[3] * quaternion[2];
|
||||
out[2][0] = 2.0f * quaternion[0] * quaternion[2] - 2.0f * quaternion[3] * quaternion[1];
|
||||
|
||||
out[0][1] = 2.0f * quaternion[0] * quaternion[1] - 2.0f * quaternion[3] * quaternion[2];
|
||||
out[1][1] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[2] * quaternion[2];
|
||||
out[2][1] = 2.0f * quaternion[1] * quaternion[2] + 2.0f * quaternion[3] * quaternion[0];
|
||||
|
||||
out[0][2] = 2.0f * quaternion[0] * quaternion[2] + 2.0f * quaternion[3] * quaternion[1];
|
||||
out[1][2] = 2.0f * quaternion[1] * quaternion[2] - 2.0f * quaternion[3] * quaternion[0];
|
||||
out[2][2] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[1] * quaternion[1];
|
||||
|
||||
out[0][3] = origin[0];
|
||||
out[1][3] = origin[1];
|
||||
out[2][3] = origin[2];
|
||||
}
|
||||
|
||||
void Matrix3x4_CreateFromEntity( matrix3x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
||||
{
|
||||
float angle, sr, sp, sy, cr, cp, cy;
|
||||
|
||||
if( angles[ROLL] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
angle = angles[PITCH] * (M_PI*2 / 360);
|
||||
sincos( angle, &sp, &cp );
|
||||
angle = angles[ROLL] * (M_PI*2 / 360);
|
||||
sincos( angle, &sr, &cr );
|
||||
|
||||
out[0][0] = (cp*cy) * scale;
|
||||
out[0][1] = (sr*sp*cy+cr*-sy) * scale;
|
||||
out[0][2] = (cr*sp*cy+-sr*-sy) * scale;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (cp*sy) * scale;
|
||||
out[1][1] = (sr*sp*sy+cr*cy) * scale;
|
||||
out[1][2] = (cr*sp*sy+-sr*cy) * scale;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = (-sp) * scale;
|
||||
out[2][1] = (sr*cp) * scale;
|
||||
out[2][2] = (cr*cp) * scale;
|
||||
out[2][3] = origin[2];
|
||||
}
|
||||
else if( angles[PITCH] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
angle = angles[PITCH] * (M_PI*2 / 360);
|
||||
sincos( angle, &sp, &cp );
|
||||
|
||||
out[0][0] = (cp*cy) * scale;
|
||||
out[0][1] = (-sy) * scale;
|
||||
out[0][2] = (sp*cy) * scale;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (cp*sy) * scale;
|
||||
out[1][1] = (cy) * scale;
|
||||
out[1][2] = (sp*sy) * scale;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = (-sp) * scale;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = (cp) * scale;
|
||||
out[2][3] = origin[2];
|
||||
}
|
||||
else if( angles[YAW] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
|
||||
out[0][0] = (cy) * scale;
|
||||
out[0][1] = (-sy) * scale;
|
||||
out[0][2] = 0;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (sy) * scale;
|
||||
out[1][1] = (cy) * scale;
|
||||
out[1][2] = 0;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = 0;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = scale;
|
||||
out[2][3] = origin[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
out[0][0] = scale;
|
||||
out[0][1] = 0;
|
||||
out[0][2] = 0;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = 0;
|
||||
out[1][1] = scale;
|
||||
out[1][2] = 0;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = 0;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = scale;
|
||||
out[2][3] = origin[2];
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix3x4_TransformPositivePlane( const matrix3x4 in, const vec3_t normal, float d, vec3_t out, float *dist )
|
||||
{
|
||||
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] );
|
||||
float iscale = 1.0f / scale;
|
||||
|
||||
out[0] = (normal[0] * in[0][0] + normal[1] * in[0][1] + normal[2] * in[0][2]) * iscale;
|
||||
out[1] = (normal[0] * in[1][0] + normal[1] * in[1][1] + normal[2] * in[1][2]) * iscale;
|
||||
out[2] = (normal[0] * in[2][0] + normal[1] * in[2][1] + normal[2] * in[2][2]) * iscale;
|
||||
*dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] );
|
||||
}
|
||||
|
||||
void Matrix3x4_Invert_Simple( matrix3x4 out, const matrix3x4 in1 )
|
||||
{
|
||||
// we only support uniform scaling, so assume the first row is enough
|
||||
// (note the lack of sqrt here, because we're trying to undo the scaling,
|
||||
// this means multiplying by the inverse scale twice - squaring it, which
|
||||
// makes the sqrt a waste of time)
|
||||
float scale = 1.0 / (in1[0][0] * in1[0][0] + in1[0][1] * in1[0][1] + in1[0][2] * in1[0][2]);
|
||||
|
||||
// invert the rotation by transposing and multiplying by the squared
|
||||
// recipricol of the input matrix scale as described above
|
||||
out[0][0] = in1[0][0] * scale;
|
||||
out[0][1] = in1[1][0] * scale;
|
||||
out[0][2] = in1[2][0] * scale;
|
||||
out[1][0] = in1[0][1] * scale;
|
||||
out[1][1] = in1[1][1] * scale;
|
||||
out[1][2] = in1[2][1] * scale;
|
||||
out[2][0] = in1[0][2] * scale;
|
||||
out[2][1] = in1[1][2] * scale;
|
||||
out[2][2] = in1[2][2] * scale;
|
||||
|
||||
// invert the translate
|
||||
out[0][3] = -(in1[0][3] * out[0][0] + in1[1][3] * out[0][1] + in1[2][3] * out[0][2]);
|
||||
out[1][3] = -(in1[0][3] * out[1][0] + in1[1][3] * out[1][1] + in1[2][3] * out[1][2]);
|
||||
out[2][3] = -(in1[0][3] * out[2][0] + in1[1][3] * out[2][1] + in1[2][3] * out[2][2]);
|
||||
}
|
||||
|
||||
const matrix4x4 matrix4x4_identity =
|
||||
{
|
||||
{ 1, 0, 0, 0 }, // PITCH
|
||||
{ 0, 1, 0, 0 }, // YAW
|
||||
{ 0, 0, 1, 0 }, // ROLL
|
||||
{ 0, 0, 0, 1 }, // ORIGIN
|
||||
};
|
||||
|
||||
/*
|
||||
========================================================================
|
||||
|
||||
Matrix4x4 operations
|
||||
|
||||
========================================================================
|
||||
*/
|
||||
void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] + in[0][3];
|
||||
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] + in[1][3];
|
||||
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2] + in[2][3];
|
||||
}
|
||||
|
||||
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
vec3_t dir;
|
||||
|
||||
dir[0] = v[0] - in[0][3];
|
||||
dir[1] = v[1] - in[1][3];
|
||||
dir[2] = v[2] - in[2][3];
|
||||
|
||||
out[0] = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0];
|
||||
out[1] = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1];
|
||||
out[2] = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix4x4_VectorRotate( const matrix4x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2];
|
||||
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2];
|
||||
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix4x4_VectorIRotate( const matrix4x4 in, const float v[3], float out[3] )
|
||||
{
|
||||
out[0] = v[0] * in[0][0] + v[1] * in[1][0] + v[2] * in[2][0];
|
||||
out[1] = v[0] * in[0][1] + v[1] * in[1][1] + v[2] * in[2][1];
|
||||
out[2] = v[0] * in[0][2] + v[1] * in[1][2] + v[2] * in[2][2];
|
||||
}
|
||||
|
||||
void Matrix4x4_ConcatTransforms( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 )
|
||||
{
|
||||
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
|
||||
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
|
||||
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] + in1[0][2] * in2[2][2];
|
||||
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] + in1[0][2] * in2[2][3] + in1[0][3];
|
||||
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] + in1[1][2] * in2[2][0];
|
||||
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] + in1[1][2] * in2[2][1];
|
||||
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] + in1[1][2] * in2[2][2];
|
||||
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] + in1[1][2] * in2[2][3] + in1[1][3];
|
||||
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] + in1[2][2] * in2[2][0];
|
||||
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] + in1[2][2] * in2[2][1];
|
||||
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] + in1[2][2] * in2[2][2];
|
||||
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] + in1[2][2] * in2[2][3] + in1[2][3];
|
||||
}
|
||||
|
||||
void Matrix4x4_SetOrigin( matrix4x4 out, float x, float y, float z )
|
||||
{
|
||||
out[0][3] = x;
|
||||
out[1][3] = y;
|
||||
out[2][3] = z;
|
||||
}
|
||||
|
||||
void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out )
|
||||
{
|
||||
out[0] = in[0][3];
|
||||
out[1] = in[1][3];
|
||||
out[2] = in[2][3];
|
||||
}
|
||||
|
||||
void Matrix4x4_FromOriginQuat( matrix4x4 out, const vec4_t quaternion, const vec3_t origin )
|
||||
{
|
||||
out[0][0] = 1.0f - 2.0f * quaternion[1] * quaternion[1] - 2.0f * quaternion[2] * quaternion[2];
|
||||
out[1][0] = 2.0f * quaternion[0] * quaternion[1] + 2.0f * quaternion[3] * quaternion[2];
|
||||
out[2][0] = 2.0f * quaternion[0] * quaternion[2] - 2.0f * quaternion[3] * quaternion[1];
|
||||
out[0][3] = origin[0];
|
||||
out[0][1] = 2.0f * quaternion[0] * quaternion[1] - 2.0f * quaternion[3] * quaternion[2];
|
||||
out[1][1] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[2] * quaternion[2];
|
||||
out[2][1] = 2.0f * quaternion[1] * quaternion[2] + 2.0f * quaternion[3] * quaternion[0];
|
||||
out[1][3] = origin[1];
|
||||
out[0][2] = 2.0f * quaternion[0] * quaternion[2] + 2.0f * quaternion[3] * quaternion[1];
|
||||
out[1][2] = 2.0f * quaternion[1] * quaternion[2] - 2.0f * quaternion[3] * quaternion[0];
|
||||
out[2][2] = 1.0f - 2.0f * quaternion[0] * quaternion[0] - 2.0f * quaternion[1] * quaternion[1];
|
||||
out[2][3] = origin[2];
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
||||
|
||||
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale )
|
||||
{
|
||||
float angle, sr, sp, sy, cr, cp, cy;
|
||||
|
||||
if( angles[ROLL] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
angle = angles[PITCH] * (M_PI*2 / 360);
|
||||
sincos( angle, &sp, &cp );
|
||||
angle = angles[ROLL] * (M_PI*2 / 360);
|
||||
sincos( angle, &sr, &cr );
|
||||
|
||||
out[0][0] = (cp*cy) * scale;
|
||||
out[0][1] = (sr*sp*cy+cr*-sy) * scale;
|
||||
out[0][2] = (cr*sp*cy+-sr*-sy) * scale;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (cp*sy) * scale;
|
||||
out[1][1] = (sr*sp*sy+cr*cy) * scale;
|
||||
out[1][2] = (cr*sp*sy+-sr*cy) * scale;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = (-sp) * scale;
|
||||
out[2][1] = (sr*cp) * scale;
|
||||
out[2][2] = (cr*cp) * scale;
|
||||
out[2][3] = origin[2];
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
||||
else if( angles[PITCH] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
angle = angles[PITCH] * (M_PI*2 / 360);
|
||||
sincos( angle, &sp, &cp );
|
||||
|
||||
out[0][0] = (cp*cy) * scale;
|
||||
out[0][1] = (-sy) * scale;
|
||||
out[0][2] = (sp*cy) * scale;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (cp*sy) * scale;
|
||||
out[1][1] = (cy) * scale;
|
||||
out[1][2] = (sp*sy) * scale;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = (-sp) * scale;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = (cp) * scale;
|
||||
out[2][3] = origin[2];
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
||||
else if( angles[YAW] )
|
||||
{
|
||||
angle = angles[YAW] * (M_PI*2 / 360);
|
||||
sincos( angle, &sy, &cy );
|
||||
|
||||
out[0][0] = (cy) * scale;
|
||||
out[0][1] = (-sy) * scale;
|
||||
out[0][2] = 0;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = (sy) * scale;
|
||||
out[1][1] = (cy) * scale;
|
||||
out[1][2] = 0;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = 0;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = scale;
|
||||
out[2][3] = origin[2];
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
out[0][0] = scale;
|
||||
out[0][1] = 0;
|
||||
out[0][2] = 0;
|
||||
out[0][3] = origin[0];
|
||||
out[1][0] = 0;
|
||||
out[1][1] = scale;
|
||||
out[1][2] = 0;
|
||||
out[1][3] = origin[1];
|
||||
out[2][0] = 0;
|
||||
out[2][1] = 0;
|
||||
out[2][2] = scale;
|
||||
out[2][3] = origin[2];
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin )
|
||||
{
|
||||
float xyDist = sqrt( in[0][0] * in[0][0] + in[1][0] * in[1][0] );
|
||||
|
||||
// enough here to get angles?
|
||||
if( xyDist > 0.001f )
|
||||
{
|
||||
angles[0] = RAD2DEG( atan2( -in[2][0], xyDist ) );
|
||||
angles[1] = RAD2DEG( atan2( in[1][0], in[0][0] ) );
|
||||
angles[2] = RAD2DEG( atan2( in[2][1], in[2][2] ) );
|
||||
}
|
||||
else // forward is mostly Z, gimbal lock
|
||||
{
|
||||
angles[0] = RAD2DEG( atan2( -in[2][0], xyDist ) );
|
||||
angles[1] = RAD2DEG( atan2( -in[0][1], in[1][1] ) );
|
||||
angles[2] = 0;
|
||||
}
|
||||
|
||||
origin[0] = in[0][3];
|
||||
origin[1] = in[1][3];
|
||||
origin[2] = in[2][3];
|
||||
}
|
||||
|
||||
void Matrix4x4_TransformPositivePlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist )
|
||||
{
|
||||
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] );
|
||||
float iscale = 1.0f / scale;
|
||||
|
||||
out[0] = (normal[0] * in[0][0] + normal[1] * in[0][1] + normal[2] * in[0][2]) * iscale;
|
||||
out[1] = (normal[0] * in[1][0] + normal[1] * in[1][1] + normal[2] * in[1][2]) * iscale;
|
||||
out[2] = (normal[0] * in[2][0] + normal[1] * in[2][1] + normal[2] * in[2][2]) * iscale;
|
||||
*dist = d * scale + ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] );
|
||||
}
|
||||
|
||||
void Matrix4x4_TransformStandardPlane( const matrix4x4 in, const vec3_t normal, float d, vec3_t out, float *dist )
|
||||
{
|
||||
float scale = sqrt( in[0][0] * in[0][0] + in[0][1] * in[0][1] + in[0][2] * in[0][2] );
|
||||
float iscale = 1.0f / scale;
|
||||
|
||||
out[0] = (normal[0] * in[0][0] + normal[1] * in[0][1] + normal[2] * in[0][2]) * iscale;
|
||||
out[1] = (normal[0] * in[1][0] + normal[1] * in[1][1] + normal[2] * in[1][2]) * iscale;
|
||||
out[2] = (normal[0] * in[2][0] + normal[1] * in[2][1] + normal[2] * in[2][2]) * iscale;
|
||||
*dist = d * scale - ( out[0] * in[0][3] + out[1] * in[1][3] + out[2] * in[2][3] );
|
||||
}
|
||||
|
||||
void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 )
|
||||
{
|
||||
// we only support uniform scaling, so assume the first row is enough
|
||||
// (note the lack of sqrt here, because we're trying to undo the scaling,
|
||||
// this means multiplying by the inverse scale twice - squaring it, which
|
||||
// makes the sqrt a waste of time)
|
||||
float scale = 1.0f / (in1[0][0] * in1[0][0] + in1[0][1] * in1[0][1] + in1[0][2] * in1[0][2]);
|
||||
|
||||
// invert the rotation by transposing and multiplying by the squared
|
||||
// recipricol of the input matrix scale as described above
|
||||
out[0][0] = in1[0][0] * scale;
|
||||
out[0][1] = in1[1][0] * scale;
|
||||
out[0][2] = in1[2][0] * scale;
|
||||
out[1][0] = in1[0][1] * scale;
|
||||
out[1][1] = in1[1][1] * scale;
|
||||
out[1][2] = in1[2][1] * scale;
|
||||
out[2][0] = in1[0][2] * scale;
|
||||
out[2][1] = in1[1][2] * scale;
|
||||
out[2][2] = in1[2][2] * scale;
|
||||
|
||||
// invert the translate
|
||||
out[0][3] = -(in1[0][3] * out[0][0] + in1[1][3] * out[0][1] + in1[2][3] * out[0][2]);
|
||||
out[1][3] = -(in1[0][3] * out[1][0] + in1[1][3] * out[1][1] + in1[2][3] * out[1][2]);
|
||||
out[2][3] = -(in1[0][3] * out[2][0] + in1[1][3] * out[2][1] + in1[2][3] * out[2][2]);
|
||||
|
||||
// don't know if there's anything worth doing here
|
||||
out[3][0] = 0;
|
||||
out[3][1] = 0;
|
||||
out[3][2] = 0;
|
||||
out[3][3] = 1;
|
||||
}
|
|
@ -184,6 +184,7 @@ typedef struct
|
|||
float currentmag2;
|
||||
float maxspeed;
|
||||
float facingenemy;
|
||||
float scale;
|
||||
} entvars_t;
|
||||
|
||||
#define PROGHEADER_CRC 5927
|
||||
|
|
|
@ -50,6 +50,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define U_EXTEND2 (1<<21) // another byte to follow
|
||||
#define U_FRAMETIME (1<<22) // another byte to follow
|
||||
// Tomaz - QC Alpha Scale Glow Control End
|
||||
#define U_SCALE (1<<23)
|
||||
|
||||
#define SU_VIEWHEIGHT (1<<0)
|
||||
#define SU_IDEALPITCH (1<<1)
|
||||
|
@ -74,6 +75,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#define SND_ATTENUATION (1<<1) // a byte
|
||||
#define SND_LOOPING (1<<2) // a long
|
||||
|
||||
#define ENTSCALE_DEFAULT 16 // Equivalent to float 1.0f due to byte packing.
|
||||
#define ENTSCALE_ENCODE(a) ((a) ? ((a) * ENTSCALE_DEFAULT) : ENTSCALE_DEFAULT) // Convert to byte
|
||||
#define ENTSCALE_DECODE(a) ((float)(a) / ENTSCALE_DEFAULT) // Convert to float for rendering
|
||||
|
||||
// defaults for clientinfo messages
|
||||
#define DEFAULT_VIEWHEIGHT 22
|
||||
|
|
|
@ -63,6 +63,7 @@ typedef struct entity_s
|
|||
float rendercolor[3];
|
||||
//Crow_bar
|
||||
|
||||
unsigned char scale;
|
||||
struct model_s *model; // NULL = no model
|
||||
struct efrag_s *efrag; // linked list of efrags
|
||||
int frame;
|
||||
|
|
|
@ -514,6 +514,9 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
|
|||
if (ent->baseline.modelindex != ent->v.modelindex)
|
||||
bits |= U_MODEL;
|
||||
|
||||
if (ent->v.scale != ENTSCALE_DEFAULT && ent->v.scale != 0)
|
||||
bits |= U_SCALE;
|
||||
|
||||
// Tomaz - QC Alpha Scale Glow Begin
|
||||
|
||||
{
|
||||
|
@ -626,6 +629,8 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
|
|||
MSG_WriteFloat(msg, rendercolor[2]);
|
||||
// Tomaz - QC Alpha Scale Glow End
|
||||
|
||||
if (bits & U_SCALE)
|
||||
MSG_WriteByte(msg, ENTSCALE_ENCODE(ent->v.scale));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue