diff --git a/include/QF/render.h b/include/QF/render.h index 99fb105a9..adc5e141e 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -32,6 +32,7 @@ #include "QF/model.h" #include "QF/qdefs.h" // FIXME #include "QF/vid.h" +#include "QF/simd/types.h" typedef enum { pt_static, @@ -131,10 +132,7 @@ typedef struct entity_s { renderer_t renderer; int active; //XXX FIXME XXX should not be here - float scale; - vec3_t origin; - vec3_t old_origin; - vec3_t angles; + vec4f_t old_origin; } entity_t; // !!! if this is changed, it must be changed in asm_draw.h too !!! @@ -159,8 +157,9 @@ typedef struct { float xOrigin; // should probably always be 0.5 float yOrigin; // between be around 0.3 to 0.5 - vec3_t vieworg; - vec3_t viewangles; + //FIXME was vec3_t, need to deal with asm (maybe? is it worth it?) + vec4f_t viewposition; + vec4f_t viewrotation; float fov_x, fov_y; diff --git a/include/client/entities.h b/include/client/entities.h index fda534295..5981d1c9d 100644 --- a/include/client/entities.h +++ b/include/client/entities.h @@ -71,6 +71,7 @@ extern entstates_t qw_entstates; extern vec3_t ent_colormod[256]; struct entity_s; -void CL_TransformEntity (struct entity_s *ent, const vec3_t angles); +void CL_TransformEntity (struct entity_s *ent, float scale, + const vec3_t angles, vec4f_t position); #endif//__client_entities_h diff --git a/include/client/view.h b/include/client/view.h index 756eb1d21..40ad78df3 100644 --- a/include/client/view.h +++ b/include/client/view.h @@ -37,6 +37,21 @@ #define INFO_CSHIFT_DAMAGE (1 << 2) #define INFO_CSHIFT_POWERUP (1 << 3) +typedef struct viewstate_s { + vec4f_t movecmd; + vec4f_t velocity; + vec4f_t origin; + vec3_t angles; + int weaponframe; + int onground; + uint32_t flags; + float frametime; + vec4f_t punchangle; +} viewstate_t; + +#define VF_DEAD 1 +#define VF_GIB 2 + void V_Init (void); void V_Init_Cvars (void); void V_RenderView (void); diff --git a/libs/client/cl_effects.c b/libs/client/cl_effects.c index af40dc62c..707699141 100644 --- a/libs/client/cl_effects.c +++ b/libs/client/cl_effects.c @@ -123,7 +123,8 @@ CL_ModelEffects (entity_t *ent, int num, int glow_color, double time) if (model->flags & EF_ROCKET) { dl = r_funcs->R_AllocDlight (num); if (dl) { - VectorCopy (ent->origin, dl->origin); + VectorCopy (Transform_GetWorldPosition (ent->transform), + dl->origin); dl->radius = 200.0; dl->die = time + 0.1; //FIXME VectorCopy (r_firecolor->vec, dl->color); diff --git a/libs/client/cl_entities.c b/libs/client/cl_entities.c index 837cfbe60..599576863 100644 --- a/libs/client/cl_entities.c +++ b/libs/client/cl_entities.c @@ -346,21 +346,14 @@ vec3_t ent_colormod[256] = { }; void -CL_TransformEntity (entity_t *ent, const vec3_t angles) +CL_TransformEntity (entity_t *ent, float scale, const vec3_t angles, + vec4f_t position) { - union { - quat_t q; - vec4f_t v; - } rotation; - vec4f_t position; - vec4f_t scale; + vec4f_t rotation; + vec4f_t scalevec = { scale, scale, scale, 1}; - VectorCopy (ent->origin, position); - position[3] = 1; - VectorSet (ent->scale, ent->scale, ent->scale, scale); - scale[3] = 1; if (VectorIsZero (angles)) { - QuatSet (0, 0, 0, 1, rotation.q); + rotation = (vec4f_t) { 0, 0, 0, 1 }; } else { vec3_t ang; VectorCopy (angles, ang); @@ -370,7 +363,7 @@ CL_TransformEntity (entity_t *ent, const vec3_t angles) // to everything else? ang[PITCH] = -ang[PITCH]; } - AngleQuat (ang, rotation.q); + AngleQuat (ang, &rotation[0]);//FIXME } - Transform_SetLocalTransform (ent->transform, scale, rotation.v, position); + Transform_SetLocalTransform (ent->transform, scalevec, rotation, position); } diff --git a/libs/client/cl_temp_entities.c b/libs/client/cl_temp_entities.c index 0b6672f0f..03fab9b73 100644 --- a/libs/client/cl_temp_entities.c +++ b/libs/client/cl_temp_entities.c @@ -61,7 +61,8 @@ typedef struct { int entity; struct model_s *model; float endtime; - vec3_t start, end; + vec4f_t start, end; + vec4f_t rotation; tent_t *tents; int seed; } beam_t; @@ -100,6 +101,8 @@ static model_t *cl_mod_bolt3; static model_t *cl_spr_explod; static model_t *cl_spike; +static vec4f_t beam_rolls[360]; + static void CL_TEnts_Precache (int phase) { @@ -132,6 +135,10 @@ CL_TEnts_Init (void) { QFS_GamedirCallback (CL_TEnts_Precache); CL_TEnts_Precache (1); + for (int i = 0; i < 360; i++) { + float ang = i * M_PI / 360; + beam_rolls[i] = (vec4f_t) { sin (ang), 0, 0, cos (ang) }; + } } void @@ -145,7 +152,6 @@ CL_Init_Entity (entity_t *ent) ent->transform = Transform_New (0); ent->renderer.skin = 0; QuatSet (1.0, 1.0, 1.0, 1.0, ent->renderer.colormod); - ent->scale = 1.0; ent->animation.pose1 = ent->animation.pose2 = -1; } @@ -255,57 +261,52 @@ static inline void beam_setup (beam_t *b, qboolean transform, double time, TEntContext_t *ctx) { tent_t *tent; - float forward, pitch, yaw, d; + float d; int ent_count; - vec3_t dist, org, ang; + vec4f_t dist, org; + vec4f_t rotation; + vec4f_t scale = { 1, 1, 1, 1 }; unsigned seed; // calculate pitch and yaw - VectorSubtract (b->end, b->start, dist); + dist = b->end - b->start; - if (dist[1] == 0 && dist[0] == 0) { - yaw = 0; - if (dist[2] > 0) - pitch = 90; - else - pitch = 270; + // FIXME interpolation may be off when passing through the -x axis + if (dist[0] < 0 && dist[1] == 0 && dist[2] == 0) { + // anti-parallel with the +x axis, so assome 180 degree rotation around + // the z-axis + rotation = (vec4f_t) { 0, 0, 1, 0 }; } else { - yaw = (int) (atan2 (dist[1], dist[0]) * 180 / M_PI); - if (yaw < 0) - yaw += 360; - - forward = sqrt (dist[0] * dist[0] + dist[1] * dist[1]); - pitch = (int) (atan2 (dist[2], forward) * 180 / M_PI); - if (pitch < 0) - pitch += 360; + rotation = qrotf ((vec4f_t) { 1, 0, 0, 0 }, dist); } + b->rotation = rotation; // add new entities for the lightning - VectorCopy (b->start, org); - d = VectorNormalize (dist); - VectorScale (dist, 30, dist); + org = b->start; + d = magnitudef (dist)[0]; + dist = normalf (dist) * 30; ent_count = ceil (d / 30); d = 0; seed = b->seed + ((int) (time * BEAM_SEED_INTERVAL) % BEAM_SEED_INTERVAL); - ang[ROLL] = 0; while (ent_count--) { tent = new_temp_entity (); tent->next = b->tents; b->tents = tent; - VectorMultAdd (org, d, dist, tent->ent.origin); + vec4f_t position = org + d * dist; d += 1.0; tent->ent.renderer.model = b->model; - ang[PITCH] = pitch; - ang[YAW] = yaw; if (transform) { seed = seed * BEAM_SEED_PRIME; - ang[ROLL] = seed % 360; - CL_TransformEntity (&tent->ent, ang); + Transform_SetLocalTransform (tent->ent.transform, scale, + qmulf (rotation, + beam_rolls[seed % 360]), + position); + } else { + Transform_SetLocalPosition (tent->ent.transform, position); } - VectorCopy (ang, tent->ent.angles); r_funcs->R_AddEfrags (&ctx->worldModel->brush, &tent->ent); } } @@ -404,14 +405,14 @@ parse_tent (qmsg_t *net_message, double time, TEntContext_t *ctx, ex = &to->to.ex; ex->tent = new_temp_entity (); - VectorCopy (position, ex->tent->ent.origin); ex->start = time; //FIXME need better model management if (!cl_spr_explod->cache.data) { cl_spr_explod = Mod_ForName ("progs/s_explod.spr", true); } ex->tent->ent.renderer.model = cl_spr_explod; - CL_TransformEntity (&ex->tent->ent, ex->tent->ent.angles); + Transform_SetLocalPosition (ex->tent->ent.transform,//FIXME + (vec4f_t) {VectorExpand (position), 1}); break; case TE_Explosion2: MSG_ReadCoordV (net_message, position); @@ -635,8 +636,9 @@ CL_UpdateBeams (double time, TEntContext_t *ctx) // add new entities for the lightning for (t = b->tents; t; t = t->next) { seed = seed * BEAM_SEED_PRIME; - t->ent.angles[ROLL] = seed % 360; - CL_TransformEntity (&t->ent, t->ent.angles); + Transform_SetLocalRotation (t->ent.transform, + qmulf (b->rotation, + beam_rolls[seed % 360])); } } } @@ -727,6 +729,8 @@ CL_ParseProjectiles (qmsg_t *net_message, qboolean nail2, TEntContext_t *ctx) byte bits[6]; int i, c, j, num; entity_t *pr; + vec4f_t position = { 0, 0, 0, 1 }; + vec3_t angles; c = MSG_ReadByte (net_message); @@ -747,13 +751,13 @@ CL_ParseProjectiles (qmsg_t *net_message, qboolean nail2, TEntContext_t *ctx) pr = &tent->ent; pr->renderer.model = cl_spike; pr->renderer.skin = 0; - pr->origin[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096; - pr->origin[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096; - pr->origin[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096; - pr->angles[0] = (bits[4] >> 4) * (360.0 / 16.0); - pr->angles[1] = bits[5] * (360.0 / 256.0); - pr->angles[2] = 0; - CL_TransformEntity (&tent->ent, tent->ent.angles); + position[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096; + position[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096; + position[2] = ((bits[3] + ((bits[4] & 15) << 8)) << 1) - 4096; + angles[0] = (bits[4] >> 4) * (360.0 / 16.0); + angles[1] = bits[5] * (360.0 / 256.0); + angles[2] = 0; + CL_TransformEntity (&tent->ent, 1, angles, position); r_funcs->R_AddEfrags (&ctx->worldModel->brush, &tent->ent); } diff --git a/libs/client/locs.c b/libs/client/locs.c index 07deee426..2ab477921 100644 --- a/libs/client/locs.c +++ b/libs/client/locs.c @@ -140,7 +140,7 @@ locs_load (const char *filename) const char *tmp; char *t1, *t2; const char *line; - vec4f_t loc; + vec4f_t loc = { 0, 0, 0, 1 }; QFile *file; tmp = va (0, "maps/%s", filename); diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index 5aa093813..13afc1fe9 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -42,6 +42,7 @@ #include "QF/cmd.h" #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/mersenne.h" #include "QF/qargs.h" #include "QF/quakefs.h" @@ -521,12 +522,14 @@ R_RocketTrail_QF (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (1.5); @@ -555,12 +558,14 @@ R_GrenadeTrail_QF (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 6.0 + qfrandom (7.0); @@ -590,12 +595,14 @@ R_BloodTrail_QF (const entity_t *ent) float len = 0.0; int j; vec3_t old_origin, porg, pvel, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 5.0 + qfrandom (10.0); @@ -630,12 +637,14 @@ R_SlightBloodTrail_QF (const entity_t *ent) float len = 0.0; int j; vec3_t old_origin, porg, pvel, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (7.5); @@ -670,12 +679,14 @@ R_WizTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -711,12 +722,14 @@ R_FlameTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -752,12 +765,14 @@ R_VoorTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; int j; vec3_t subtract, old_origin, porg, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -790,7 +805,8 @@ R_GlowTrail_QF (const entity_t *ent, int glow_color) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, (maxlen - dist), subtract); @@ -869,12 +885,14 @@ R_RocketTrail_EE (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (1.5); @@ -904,12 +922,14 @@ R_GrenadeTrail_EE (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 6.0 + qfrandom (7.0); @@ -1143,7 +1163,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) // l = r_maxparticles - numparticles; // } - VectorCopy (ent->origin, org); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); for (i = -16; i < 16; i += 8) { dir [1] = i * 8; @@ -1177,6 +1197,7 @@ R_EntityParticles_ID (const entity_t *ent) float angle, sp, sy, cp, cy; // cr, sr float beamlength = 16.0, dist = 64.0; vec3_t forward, porg; + vec3_t org; if (numparticles + j >= r_maxparticles) { return; @@ -1184,6 +1205,8 @@ R_EntityParticles_ID (const entity_t *ent) j = r_maxparticles - numparticles; } + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + if (!avelocities[0][0]) { for (i = 0; i < NUMVERTEXNORMALS; i++) { int k; @@ -1209,11 +1232,11 @@ R_EntityParticles_ID (const entity_t *ent) forward[1] = cp * sy; forward[2] = -sp; - porg[0] = ent->origin[0] + r_avertexnormals[i][0] * dist + + porg[0] = org[0] + r_avertexnormals[i][0] * dist + forward[0] * beamlength; - porg[1] = ent->origin[1] + r_avertexnormals[i][1] * dist + + porg[1] = org[1] + r_avertexnormals[i][1] * dist + forward[1] * beamlength; - porg[2] = ent->origin[2] + r_avertexnormals[i][2] * dist + + porg[2] = org[2] + r_avertexnormals[i][2] * dist + forward[2] * beamlength; particle_new (pt_explode, part_tex_dot, porg, 1.0, vec3_origin, vr_data.realtime + 0.01, 0x6f, 1.0, 0); @@ -1232,7 +1255,8 @@ R_RocketTrail_ID (const entity_t *ent) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, (maxlen - dist), subtract); @@ -1264,7 +1288,8 @@ R_GrenadeTrail_ID (const entity_t *ent) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1291,12 +1316,14 @@ R_BloodTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; unsigned int rnd; vec3_t old_origin, subtract, vec, porg; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1322,12 +1349,14 @@ R_SlightBloodTrail_ID (const entity_t *ent) float dist = 6.0, len = 0.0; unsigned int rnd; vec3_t old_origin, porg, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1353,12 +1382,14 @@ R_WizTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1390,12 +1421,14 @@ R_FlameTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1427,12 +1460,14 @@ R_VoorTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; unsigned int rnd; vec3_t old_origin, porg, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1471,7 +1506,7 @@ gl_R_DrawParticles (void) qfglDepthMask (GL_FALSE); qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray); - minparticledist = DotProduct (r_refdef.vieworg, vpn) + + minparticledist = DotProduct (r_refdef.viewposition, vpn) + r_particles_nearclip->value; activeparticles = 0; diff --git a/libs/video/renderer/gl/gl_lightmap.c b/libs/video/renderer/gl/gl_lightmap.c index d46c35014..2ea33a8c0 100644 --- a/libs/video/renderer/gl/gl_lightmap.c +++ b/libs/video/renderer/gl/gl_lightmap.c @@ -43,6 +43,7 @@ #include #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" #include "QF/GL/defines.h" @@ -117,16 +118,22 @@ R_AddDynamicLights_1 (msurface_t *surf) unsigned int sdtable[18]; unsigned int *bl; vec3_t impact, local; + vec4f_t entorigin = { 0, 0, 0, 1 }; smax = (surf->extents[0] >> 4) + 1; smax_bytes = smax * gl_internalformat; tmax = (surf->extents[1] >> 4) + 1; + if (currententity->transform) { + //FIXME give world entity a transform + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light - VectorSubtract (r_dlights[lnum].origin, currententity->origin, local); + VectorSubtract (r_dlights[lnum].origin, entorigin, local); dist = DotProduct (local, surf->plane->normal) - surf->plane->dist; VectorMultSub (r_dlights[lnum].origin, dist, surf->plane->normal, impact); @@ -182,16 +189,21 @@ R_AddDynamicLights_3 (msurface_t *surf) unsigned int sdtable[18]; unsigned int *bl; vec3_t impact, local; + vec4f_t entorigin = { 0, 0, 0, 1 }; smax = (surf->extents[0] >> 4) + 1; smax_bytes = smax * gl_internalformat; tmax = (surf->extents[1] >> 4) + 1; + if (currententity->transform) { + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light - VectorSubtract (r_dlights[lnum].origin, currententity->origin, local); + VectorSubtract (r_dlights[lnum].origin, entorigin, local); dist = DotProduct (local, surf->plane->normal) - surf->plane->dist; VectorMultSub (r_dlights[lnum].origin, dist, surf->plane->normal, impact); diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index 92c67038d..3f96b4364 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -196,8 +196,10 @@ GL_DrawAliasShadowTri (const aliashdr_t *paliashdr, const vert_order_t *vo) vec3_t point; const vec_t *scale = paliashdr->mdl.scale; const vec_t *scale_origin = paliashdr->mdl.scale_origin; + vec4f_t entorigin; - lheight = currententity->origin[2] - lightspot[2]; + entorigin = Transform_GetWorldPosition (currententity->transform); + lheight = entorigin[2] - lightspot[2]; height = -lheight + 1.0; qfglBegin (GL_TRIANGLES); @@ -232,8 +234,10 @@ GL_DrawAliasShadow (const aliashdr_t *paliashdr, const vert_order_t *vo) const int *order = vo->order; vec3_t point; const blended_vert_t *verts = vo->verts; + vec4f_t entorigin; - lheight = currententity->origin[2] - lightspot[2]; + entorigin = Transform_GetWorldPosition (currententity->transform); + lheight = entorigin[2] - lightspot[2]; height = -lheight + 1.0; while ((count = *order++)) { @@ -413,17 +417,23 @@ gl_R_DrawAliasModel (entity_t *e) dlight_t *l; model_t *model; vec3_t dist, scale; + vec4f_t origin; vert_order_t *vo; model = e->renderer.model; radius = model->radius; - if (e->scale != 1.0) - radius *= e->scale; - if (R_CullSphere (e->origin, radius)) + origin = Transform_GetWorldPosition (e->transform); + VectorCopy (Transform_GetWorldScale (e->transform), scale); + //FIXME assumes uniform scale + if (scale[0] != 1.0) { + radius *= scale[0]; + } + if (R_CullSphere (&origin[0], radius)) {//FIXME return; + } - VectorSubtract (r_origin, e->origin, modelorg); + VectorSubtract (r_origin, origin, modelorg); gl_modelalpha = e->renderer.colormod[3]; @@ -436,7 +446,7 @@ gl_R_DrawAliasModel (entity_t *e) float lightadj; // get lighting information - R_LightPoint (&r_worldentity.renderer.model->brush, e->origin); + R_LightPoint (&r_worldentity.renderer.model->brush, &origin[0]);//FIXME lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0; @@ -457,7 +467,7 @@ gl_R_DrawAliasModel (entity_t *e) if (gl_vector_light->int_val) { for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) { if (l->die >= vr_data.realtime) { - VectorSubtract (l->origin, e->origin, dist); + VectorSubtract (l->origin, origin, dist); if ((d = DotProduct (dist, dist)) > // Out of range ((l->radius + radius) * (l->radius + radius))) { continue; @@ -508,7 +518,7 @@ gl_R_DrawAliasModel (entity_t *e) for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) { if (l->die >= vr_data.realtime) { - VectorSubtract (l->origin, e->origin, dist); + VectorSubtract (l->origin, origin, dist); if ((d = DotProduct (dist, dist)) > (l->radius + radius) * (l->radius + radius)) { @@ -567,10 +577,12 @@ gl_R_DrawAliasModel (entity_t *e) if (paliashdr->mdl.ident == HEADER_MDL16) { // because we multipled by 256 when we loaded the verts, we have to // scale by 1/256 when drawing. - VectorScale (paliashdr->mdl.scale, e->scale / 256.0, scale); + //FIXME see scaling above + VectorScale (paliashdr->mdl.scale, 1 / 256.0, scale); vo = GL_GetAliasFrameVerts16 (paliashdr, e); } else { - VectorScale (paliashdr->mdl.scale, e->scale, scale); + //FIXME see scaling above + VectorScale (paliashdr->mdl.scale, 1, scale); vo = GL_GetAliasFrameVerts (paliashdr, e); } diff --git a/libs/video/renderer/gl/gl_mod_iqm.c b/libs/video/renderer/gl/gl_mod_iqm.c index 601a76fbf..f66c2c7ca 100644 --- a/libs/video/renderer/gl/gl_mod_iqm.c +++ b/libs/video/renderer/gl/gl_mod_iqm.c @@ -103,7 +103,6 @@ gl_R_DrawIQMModel (entity_t *ent) qfglPushMatrix (); gl_R_RotateForEntity (ent); - qfglScalef (ent->scale, ent->scale, ent->scale); for (i = 0; i < iqm->num_meshes; i++) { qfglBindTexture (GL_TEXTURE_2D, gl->textures[i]); diff --git a/libs/video/renderer/gl/gl_mod_sprite.c b/libs/video/renderer/gl/gl_mod_sprite.c index d0dd91444..d4b1c1f86 100644 --- a/libs/video/renderer/gl/gl_mod_sprite.c +++ b/libs/video/renderer/gl/gl_mod_sprite.c @@ -123,10 +123,6 @@ R_DrawSpriteModel_f (entity_t *e) VectorCopy (vup, up); VectorCopy (vright, right); } - if (e->scale != 1.0) { - up *= e->scale; - right *= e->scale; - } VectorCopy (e->renderer.colormod, color); modelalpha = color[3] = e->renderer.colormod[3]; @@ -194,10 +190,6 @@ R_DrawSpriteModel_VA_f (entity_t *e) VectorCopy (vup, up); VectorCopy (vright, right); } - if (e->scale != 1.0) { - up *= e->scale; - right *= e->scale; - } for (i = 0; i < 4; i++) { color[i] = e->renderer.colormod[i] * 255; diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index 8079b790b..8bf8ec46a 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -74,7 +74,7 @@ qboolean gl_mirror; plane_t *gl_mirror_plane; float gl_r_world_matrix[16]; -static float r_base_world_matrix[16]; +//FIXME static float r_base_world_matrix[16]; //vec3_t gl_shadecolor; // Ender (Extend) Colormod float gl_modelalpha; // Ender (Extend) Alpha @@ -344,9 +344,12 @@ gl_R_SetupFrame (void) gl_Fog_SetupFrame (); // build the transformation matrix for the given view angles - VectorCopy (r_refdef.vieworg, r_origin); + VectorCopy (r_refdef.viewposition, r_origin); + + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); R_SetFrustum (); @@ -419,13 +422,19 @@ R_SetupGL (void) qfglMatrixMode (GL_MODELVIEW); qfglLoadIdentity (); - qfglRotatef (-90, 1, 0, 0); // put Z going up - qfglRotatef (90, 0, 0, 1); // put Z going up - qfglRotatef (-r_refdef.viewangles[ROLL], 1, 0, 0); - qfglRotatef (-r_refdef.viewangles[PITCH], 0, 1, 0); - qfglRotatef (-r_refdef.viewangles[YAW], 0, 0, 1); - qfglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], - -r_refdef.vieworg[2]); + static mat4f_t z_up = { + { 0, 0, -1, 0}, + {-1, 0, 0, 0}, + { 0, 1, 0, 0}, + { 0, 0, 0, 1}, + }; + mat4f_t view; + mat4fquat (view, qconjf (r_refdef.viewrotation)); + mmulf (view, z_up, view); + vec4f_t offset = -r_refdef.viewposition; + offset[3] = 1; + view[3] = mvmulf (view, offset); + qfglLoadMatrixf (&view[0][0]); qfglGetFloatv (GL_MODELVIEW_MATRIX, gl_r_world_matrix); @@ -480,12 +489,12 @@ R_RenderScene (void) static void R_Mirror (void) { - float d; + //float d; // msurface_t *s; // if (!gl_mirror) // FIXME: Broken return; - +/* memcpy (r_base_world_matrix, gl_r_world_matrix, sizeof (r_base_world_matrix)); @@ -551,6 +560,7 @@ R_Mirror (void) r_worldentity.model->textures[gl_mirrortexturenum]->texturechain = NULL; #endif qfglColor3ubv (color_white); +*/ } /* @@ -584,6 +594,18 @@ R_RenderView_ (void) R_ZGraph (); } +//FIXME static void R_RenderViewFishEye (void); + +void +gl_R_RenderView (void) +{ + R_RenderView_ (); + /*if(!scr_fisheye->int_val) + R_RenderView_ (); + else + R_RenderViewFishEye ();*/ +} +/*FIXME // Algorithm: // Draw up to six views, one in each direction. // Save the picture to cube map texture, use GL_ARB_texture_cube_map. @@ -593,17 +615,6 @@ R_RenderView_ (void) // grid vertices coordinates. // Render view. Fisheye is done. -static void R_RenderViewFishEye (void); - -void -gl_R_RenderView (void) -{ - if(!scr_fisheye->int_val) - R_RenderView_ (); - else - R_RenderViewFishEye (); -} - #define BOX_FRONT 0 #define BOX_RIGHT 1 #define BOX_BEHIND 2 @@ -891,7 +902,7 @@ R_RenderViewFishEye (void) R_SetupGL_Viewport_and_Perspective (); qfglMatrixMode (GL_MODELVIEW); qfglCallList (fisheye_grid); -} +}*/ void gl_R_ClearState (void) diff --git a/libs/video/renderer/gl/gl_rmisc.c b/libs/video/renderer/gl/gl_rmisc.c index d9a1c6797..de34bb203 100644 --- a/libs/video/renderer/gl/gl_rmisc.c +++ b/libs/video/renderer/gl/gl_rmisc.c @@ -74,6 +74,7 @@ static void R_Envmap_f (void) { + /*FIXME update for simd byte buffer[256 * 256 * 4]; qfglDrawBuffer (GL_FRONT); @@ -122,7 +123,7 @@ R_Envmap_f (void) gl_envmap = false; qfglDrawBuffer (GL_BACK); qfglReadBuffer (GL_BACK); - gl_ctx->end_rendering (); + gl_ctx->end_rendering ();*/ } void @@ -250,6 +251,7 @@ gl_R_ViewChanged (float aspect) void gl_R_TimeRefresh_f (void) { +/*FIXME update for simd double start, stop, time; int i; @@ -265,4 +267,5 @@ gl_R_TimeRefresh_f (void) stop = Sys_DoubleTime (); time = stop - start; Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time); +*/ } diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index b954fc066..96d1ec93f 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -545,12 +545,13 @@ gl_R_DrawBrushModel (entity_t *e) if (e->scale != 1.0) radius *= e->scale; #endif - if (R_CullSphere (e->origin, radius)) + if (R_CullSphere (&worldMatrix[3][0], radius)) {//FIXME return; + } } else { rotated = false; - VectorAdd (e->origin, model->mins, mins); - VectorAdd (e->origin, model->maxs, maxs); + VectorAdd (worldMatrix[3], model->mins, mins); + VectorAdd (worldMatrix[3], model->maxs, maxs); #if 0 // QSG FIXME if (e->scale != 1.0) { VectorScale (mins, e->scale, mins); @@ -561,7 +562,7 @@ gl_R_DrawBrushModel (entity_t *e) return; } - VectorSubtract (r_refdef.vieworg, e->origin, modelorg); + VectorSubtract (r_refdef.viewposition, worldMatrix[3], modelorg); if (rotated) { vec4f_t temp = { modelorg[0], modelorg[1], modelorg[2], 0 }; @@ -579,7 +580,7 @@ gl_R_DrawBrushModel (entity_t *e) || (!r_dlights[k].radius)) continue; - VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); + VectorSubtract (r_dlights[k].origin, worldMatrix[3], lightorigin); R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k, brush->nodes + brush->hulls[0].firstclipnode); } @@ -723,7 +724,7 @@ gl_R_DrawWorld (void) memset (&worldent, 0, sizeof (worldent)); worldent.renderer.model = r_worldentity.renderer.model; - VectorCopy (r_refdef.vieworg, modelorg); + VectorCopy (r_refdef.viewposition, modelorg); currententity = &worldent; diff --git a/libs/video/renderer/gl/gl_sky.c b/libs/video/renderer/gl/gl_sky.c index cb3258246..db289326b 100644 --- a/libs/video/renderer/gl/gl_sky.c +++ b/libs/video/renderer/gl/gl_sky.c @@ -189,9 +189,9 @@ R_DrawSkyBox (void) float *v = (float *) gl_skyvec[i][j]; qfglTexCoord2fv (v); - qfglVertex3f (r_refdef.vieworg[0] + v[2], - r_refdef.vieworg[1] + v[3], - r_refdef.vieworg[2] + v[4]); + qfglVertex3f (r_refdef.viewposition[0] + v[2], + r_refdef.viewposition[1] + v[3], + r_refdef.viewposition[2] + v[4]); } qfglEnd (); } @@ -219,7 +219,7 @@ skydome_vertex (const vec3_t v, float speedscale) s = speedscale + dir[0]; t = speedscale + dir[1]; - VectorAdd (r_refdef.vieworg, v, point); + VectorAdd (r_refdef.viewposition, v, point); qfglTexCoord2f (s, t); qfglVertex3fv (point); @@ -242,7 +242,7 @@ skydome_debug (void) h = 1; t = 0; - VectorAdd (zenith, r_refdef.vieworg, v[0]); + VectorAdd (zenith, r_refdef.viewposition, v[0]); for (b = 1; b <= 8; b++) { x = gl_bubble_costable[b + 8]; y = -gl_bubble_sintable[b + 8]; @@ -250,7 +250,7 @@ skydome_debug (void) v[h][0] = a1x * x; v[h][1] = a1y * x; v[h][2] = y * domescale[2]; - VectorAdd (v[h], r_refdef.vieworg, v[h]); + VectorAdd (v[h], r_refdef.viewposition, v[h]); for (i = t; i != h; i = (i + 1) % 3) { qfglVertex3fv (v[i]); qfglVertex3fv (v[h]); @@ -262,7 +262,7 @@ skydome_debug (void) v[h][0] = a2x * x; v[h][1] = a2y * x; v[h][2] = y * domescale[2]; - VectorAdd (v[h], r_refdef.vieworg, v[h]); + VectorAdd (v[h], r_refdef.viewposition, v[h]); for (i = t; i != h; i = (i + 1) % 3) { qfglVertex3fv (v[i]); qfglVertex3fv (v[h]); @@ -274,7 +274,7 @@ skydome_debug (void) h = 1; t = 0; - VectorAdd (nadir, r_refdef.vieworg, v[0]); + VectorAdd (nadir, r_refdef.viewposition, v[0]); for (b = 15; b >= 8; b--) { x = gl_bubble_costable[b + 8]; y = -gl_bubble_sintable[b + 8]; @@ -282,7 +282,7 @@ skydome_debug (void) v[h][0] = a2x * x; v[h][1] = a2y * x; v[h][2] = y * domescale[2]; - VectorAdd (v[h], r_refdef.vieworg, v[h]); + VectorAdd (v[h], r_refdef.viewposition, v[h]); for (i = t; i != h; i = (i + 1) % 3) { qfglVertex3fv (v[i]); qfglVertex3fv (v[h]); @@ -294,7 +294,7 @@ skydome_debug (void) v[h][0] = a1x * x; v[h][1] = a1y * x; v[h][2] = y * domescale[2]; - VectorAdd (v[h], r_refdef.vieworg, v[h]); + VectorAdd (v[h], r_refdef.viewposition, v[h]); for (i = t; i != h; i = (i + 1) % 3) { qfglVertex3fv (v[i]); qfglVertex3fv (v[h]); diff --git a/libs/video/renderer/gl/gl_sky_clip.c b/libs/video/renderer/gl/gl_sky_clip.c index 44a560005..697403eb9 100644 --- a/libs/video/renderer/gl/gl_sky_clip.c +++ b/libs/video/renderer/gl/gl_sky_clip.c @@ -220,14 +220,14 @@ find_cube_vertex (int face1, int face2, int face3, vec3_t v) set_vertex add the vertex to the polygon describing the face of the cube. Offsets - the vertex relative to r_refdef.vieworg so the cube is always centered + the vertex relative to r_refdef.viewposition so the cube is always centered on the player and also calculates the texture coordinates of the vertex (wish I could find a cleaner way of calculating s and t). */ static void set_vertex (struct box_def *box, int face, int ind, const vec3_t v) { - VectorAdd (v, r_refdef.vieworg, box->face[face].poly.verts[ind]); + VectorAdd (v, r_refdef.viewposition, box->face[face].poly.verts[ind]); switch (face) { case 0: box->face[face].poly.verts[ind][3] = (1024 - v[1] + 4) / BOX_WIDTH; @@ -601,14 +601,14 @@ R_DrawSkyBoxPoly (const glpoly_t *poly) Sys_Error ("too many verts!"); } - VectorSubtract (poly->verts[poly->numverts - 1], r_refdef.vieworg, last_v); + VectorSubtract (poly->verts[poly->numverts - 1], r_refdef.viewposition, last_v); prev_face = determine_face (last_v); box.visited_faces[0].face = prev_face; box.face_count = 1; for (i = 0; i < poly->numverts; i++) { - VectorSubtract (poly->verts[i], r_refdef.vieworg, v); + VectorSubtract (poly->verts[i], r_refdef.viewposition, v); face = determine_face (v); if (face != prev_face) { if ((face_axis[face]) == (face_axis[prev_face])) { @@ -864,11 +864,11 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain) vec3_t x, c = { 0, 0, 0 }; for (i = 0; i < p->numverts; i++) { - VectorSubtract (p->verts[i], r_refdef.vieworg, x); + VectorSubtract (p->verts[i], r_refdef.viewposition, x); VectorAdd (x, c, c); } VectorScale (c, 1.0 / p->numverts, c); - VectorAdd (c, r_refdef.vieworg, c); + VectorAdd (c, r_refdef.viewposition, c); qfglVertex3fv (c); p = p->next; } @@ -889,7 +889,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain) qfglBegin (GL_LINE_LOOP); for (j = 0; j < 4; j++) { VectorScale (&gl_skyvec[i][j][2], 1.0 / 128.0, v); - VectorAdd (v, r_refdef.vieworg, v); + VectorAdd (v, r_refdef.viewposition, v); qfglVertex3fv (v); } qfglEnd (); diff --git a/libs/video/renderer/glsl/glsl_alias.c b/libs/video/renderer/glsl/glsl_alias.c index e0c29cfe4..22983ceef 100644 --- a/libs/video/renderer/glsl/glsl_alias.c +++ b/libs/video/renderer/glsl/glsl_alias.c @@ -157,17 +157,20 @@ calc_lighting (entity_t *ent, float *ambient, float *shadelight, unsigned i; float add; vec3_t dist; + vec4f_t entorigin; int light; + entorigin = Transform_GetWorldPosition (ent->transform); + VectorSet ( -1, 0, 0, lightvec); //FIXME - light = R_LightPoint (&r_worldentity.renderer.model->brush, ent->origin); + light = R_LightPoint (&r_worldentity.renderer.model->brush, &entorigin[0]); *ambient = max (light, max (ent->renderer.model->min_light, ent->renderer.min_light) * 128); *shadelight = *ambient; for (i = 0; i < r_maxdlights; i++) { if (r_dlights[i].die >= vr_data.realtime) { - VectorSubtract (ent->origin, r_dlights[i].origin, dist); + VectorSubtract (entorigin, r_dlights[i].origin, dist); add = r_dlights[i].radius - VectorLength (dist); if (add > 0) *ambient += add; diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 3fc716cf8..50a4e98af 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -660,7 +660,8 @@ R_DrawBrushModel (entity_t *e) plane_t *plane; msurface_t *surf; qboolean rotated; - vec3_t mins, maxs, org; + vec3_t mins, maxs; + vec4f_t org; mod_brush_t *brush; model = e->renderer.model; @@ -671,19 +672,20 @@ R_DrawBrushModel (entity_t *e) if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { rotated = true; radius = model->radius; - if (R_CullSphere (e->origin, radius)) + if (R_CullSphere (&mat[3][0], radius)) { // FIXME return; + } } else { rotated = false; - VectorAdd (e->origin, model->mins, mins); - VectorAdd (e->origin, model->maxs, maxs); + VectorAdd (mat[3], model->mins, mins); + VectorAdd (mat[3], model->maxs, maxs); if (R_CullBox (mins, maxs)) return; } - VectorSubtract (r_refdef.vieworg, e->origin, org); + org = r_refdef.viewposition - mat[3]; if (rotated) { - vec4f_t temp = { org[0], org[1], org[2], 0 }; + vec4f_t temp = org; org[0] = dotf (temp, mat[0])[0]; org[1] = dotf (temp, mat[1])[0]; @@ -699,7 +701,7 @@ R_DrawBrushModel (entity_t *e) || (!r_dlights[k].radius)) continue; - VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); + VectorSubtract (r_dlights[k].origin, mat[3], lightorigin); R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k, brush->nodes + brush->hulls[0].firstclipnode); } diff --git a/libs/video/renderer/glsl/glsl_iqm.c b/libs/video/renderer/glsl/glsl_iqm.c index 76a9ae85e..93a25e982 100644 --- a/libs/video/renderer/glsl/glsl_iqm.c +++ b/libs/video/renderer/glsl/glsl_iqm.c @@ -214,22 +214,24 @@ glsl_R_DrawIQM (void) dlight_t *lights[MAX_IQM_LIGHTS]; int i; vec_t norm_mat[9]; + vec4f_t entorigin; mat4f_t mvp_mat; float blend; iqmframe_t *frame; - R_LightPoint (&r_worldentity.renderer.model->brush, ent->origin);//FIXME min_light? - VectorScale (ambientcolor, 1/255.0, ambientcolor); - R_FindNearLights (ent->origin, MAX_IQM_LIGHTS, lights); - // we need only the rotation for normals. mat4f_t mat; Transform_GetWorldMatrix (ent->transform, mat); VectorCopy (mat[0], norm_mat + 0); VectorCopy (mat[1], norm_mat + 3); VectorCopy (mat[2], norm_mat + 6); + entorigin = mat[3]; mmulf (mvp_mat, iqm_vp, mat); + R_LightPoint (&r_worldentity.renderer.model->brush, &entorigin[0]);//FIXME min_light? + VectorScale (ambientcolor, 1/255.0, ambientcolor); + R_FindNearLights (&entorigin[0], MAX_IQM_LIGHTS, lights);//FIXME + blend = R_IQMGetLerpedFrames (ent, iqm); frame = R_IQMBlendFrames (iqm, ent->animation.pose1, ent->animation.pose2, blend, 0); @@ -240,7 +242,7 @@ glsl_R_DrawIQM (void) lightpar_t *l = &iqm_shader.lights[i]; if (!lights[i]) break; - VectorSubtract (lights[i]->origin, ent->origin, val); + VectorSubtract (lights[i]->origin, entorigin, val); val[3] = lights[i]->radius; qfeglUniform4fv (l->position.location, 1, val); qfeglUniform4fv (l->color.location, 1, lights[i]->color); diff --git a/libs/video/renderer/glsl/glsl_lightmap.c b/libs/video/renderer/glsl/glsl_lightmap.c index 65af9d238..f34de4692 100644 --- a/libs/video/renderer/glsl/glsl_lightmap.c +++ b/libs/video/renderer/glsl/glsl_lightmap.c @@ -44,6 +44,7 @@ #endif #include +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" @@ -70,6 +71,7 @@ R_AddDynamicLights_1 (msurface_t *surf) int sd, td; float dist, rad, minlight; vec3_t impact, local, lightorigin; + vec4f_t entorigin = { 0, 0, 0, 1}; int s, t; int smax, tmax; mtexinfo_t *tex; @@ -78,12 +80,16 @@ R_AddDynamicLights_1 (msurface_t *surf) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; + if (currententity->transform) { + //FIXME give world entity a transform + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light - VectorSubtract (r_dlights[lnum].origin, currententity->origin, - lightorigin); + VectorSubtract (r_dlights[lnum].origin, entorigin, lightorigin); rad = r_dlights[lnum].radius; dist = DotProduct (lightorigin, surf->plane->normal) - surf->plane->dist; diff --git a/libs/video/renderer/glsl/glsl_main.c b/libs/video/renderer/glsl/glsl_main.c index ba8c2dce7..fed46ed3a 100644 --- a/libs/video/renderer/glsl/glsl_main.c +++ b/libs/video/renderer/glsl/glsl_main.c @@ -113,8 +113,11 @@ glsl_R_SetupFrame (void) R_ClearEnts (); r_framecount++; - VectorCopy (r_refdef.vieworg, r_origin); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); + VectorCopy (r_refdef.viewposition, r_origin); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); + R_SetFrustum (); @@ -131,7 +134,6 @@ R_SetupView (void) { 0, 1, 0, 0}, { 0, 0, 0, 1}, }; - vec4f_t rotation; vec4f_t offset = { 0, 0, 0, 1 }; x = r_refdef.vrect.x; @@ -140,11 +142,10 @@ R_SetupView (void) h = r_refdef.vrect.height; qfeglViewport (x, y, w, h); - AngleQuat (r_refdef.viewangles, &rotation[0]); - rotation = qconjf (rotation); - mat4fquat (glsl_view, rotation); + mat4fquat (glsl_view, qconjf (r_refdef.viewrotation)); mmulf (glsl_view, z_up, glsl_view); - VectorNegate (r_refdef.vieworg, offset); + offset = -r_refdef.viewposition; + offset[3] = 1; glsl_view[3] = mvmulf (glsl_view, offset); qfeglEnable (GL_CULL_FACE); @@ -304,6 +305,7 @@ glsl_R_ClearState (void) void glsl_R_TimeRefresh_f (void) { +/* FIXME update for simd double start, stop, time; int i; @@ -319,4 +321,5 @@ glsl_R_TimeRefresh_f (void) stop = Sys_DoubleTime (); time = stop - start; Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time); +*/ } diff --git a/libs/video/renderer/glsl/glsl_particles.c b/libs/video/renderer/glsl/glsl_particles.c index eb7eccb6d..de8c64602 100644 --- a/libs/video/renderer/glsl/glsl_particles.c +++ b/libs/video/renderer/glsl/glsl_particles.c @@ -42,6 +42,7 @@ #include "QF/cmd.h" #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/image.h" #include "QF/mersenne.h" #include "QF/qargs.h" @@ -629,12 +630,14 @@ R_RocketTrail_QF (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (1.5); @@ -663,12 +666,14 @@ R_GrenadeTrail_QF (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 6.0 + qfrandom (7.0); @@ -698,12 +703,14 @@ R_BloodTrail_QF (const entity_t *ent) float len = 0.0; int j; vec3_t old_origin, porg, pvel, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 5.0 + qfrandom (10.0); @@ -738,12 +745,14 @@ R_SlightBloodTrail_QF (const entity_t *ent) float len = 0.0; int j; vec3_t old_origin, porg, pvel, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (7.5); @@ -778,12 +787,14 @@ R_WizTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -819,12 +830,14 @@ R_FlameTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -860,12 +873,14 @@ R_VoorTrail_QF (const entity_t *ent) float dist = 3.0, len = 0.0; int j; vec3_t subtract, old_origin, porg, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, maxlen - dist, subtract); @@ -898,7 +913,8 @@ R_GlowTrail_QF (const entity_t *ent, int glow_color) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; VectorScale (vec, (maxlen - dist), subtract); @@ -977,12 +993,14 @@ R_RocketTrail_EE (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 1.5 + qfrandom (1.5); @@ -1012,12 +1030,14 @@ R_GrenadeTrail_EE (const entity_t *ent) float dist, maxlen, origlen, percent, pscale, pscalenext; float len = 0.0; vec3_t old_origin, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); origlen = vr_data.frametime / maxlen; pscale = 6.0 + qfrandom (7.0); @@ -1251,7 +1271,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) // l = r_maxparticles - numparticles; // } - VectorCopy (ent->origin, org); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); for (i = -16; i < 16; i += 8) { dir [1] = i * 8; @@ -1285,6 +1305,7 @@ R_EntityParticles_ID (const entity_t *ent) float angle, sp, sy, cp, cy; // cr, sr float beamlength = 16.0, dist = 64.0; vec3_t forward, porg; + vec3_t org; if (numparticles + j >= r_maxparticles) { return; @@ -1292,6 +1313,8 @@ R_EntityParticles_ID (const entity_t *ent) j = r_maxparticles - numparticles; } + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + for (i = 0; i < NUMVERTEXNORMALS; i++) { int k; for (k = 0; k < 3; k++) { @@ -1315,11 +1338,11 @@ R_EntityParticles_ID (const entity_t *ent) forward[1] = cp * sy; forward[2] = -sp; - porg[0] = ent->origin[0] + vertex_normals[i][0] * dist + + porg[0] = org[0] + vertex_normals[i][0] * dist + forward[0] * beamlength; - porg[1] = ent->origin[1] + vertex_normals[i][1] * dist + + porg[1] = org[1] + vertex_normals[i][1] * dist + forward[1] * beamlength; - porg[2] = ent->origin[2] + vertex_normals[i][2] * dist + + porg[2] = org[2] + vertex_normals[i][2] * dist + forward[2] * beamlength; particle_new (pt_explode, part_tex_dot, porg, 1.0, vec3_origin, vr_data.realtime + 0.01, 0x6f, 1.0, 0); @@ -1338,7 +1361,8 @@ R_RocketTrail_ID (const entity_t *ent) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, (maxlen - dist), subtract); @@ -1370,7 +1394,8 @@ R_GrenadeTrail_ID (const entity_t *ent) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1397,12 +1422,14 @@ R_BloodTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; unsigned int rnd; vec3_t old_origin, subtract, vec, porg; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1428,12 +1455,14 @@ R_SlightBloodTrail_ID (const entity_t *ent) float dist = 6.0, len = 0.0; unsigned int rnd; vec3_t old_origin, porg, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1459,12 +1488,14 @@ R_WizTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1496,12 +1527,14 @@ R_FlameTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; static int tracercount; vec3_t old_origin, pvel, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1533,12 +1566,14 @@ R_VoorTrail_ID (const entity_t *ent) float dist = 3.0, len = 0.0; unsigned int rnd; vec3_t old_origin, porg, subtract, vec; + vec3_t org; if (numparticles >= r_maxparticles) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); maxlen = VectorNormalize (vec); VectorScale (vec, maxlen - dist, subtract); @@ -1594,7 +1629,7 @@ draw_qf_particles (void) // LordHavoc: particles should not affect zbuffer qfeglDepthMask (GL_FALSE); - minparticledist = DotProduct (r_refdef.vieworg, vpn) + + minparticledist = DotProduct (r_refdef.viewposition, vpn) + r_particles_nearclip->value; activeparticles = 0; @@ -1736,7 +1771,7 @@ draw_id_particles (void) qfeglEnable (GL_TEXTURE_2D); qfeglBindTexture (GL_TEXTURE_2D, glsl_palette); - minparticledist = DotProduct (r_refdef.vieworg, vpn) + + minparticledist = DotProduct (r_refdef.viewposition, vpn) + r_particles_nearclip->value; activeparticles = 0; diff --git a/libs/video/renderer/glsl/glsl_sprite.c b/libs/video/renderer/glsl/glsl_sprite.c index 4d35bc8d6..7eecea5dd 100644 --- a/libs/video/renderer/glsl/glsl_sprite.c +++ b/libs/video/renderer/glsl/glsl_sprite.c @@ -185,6 +185,7 @@ make_quad (mspriteframe_t *frame, vec4f_t vpn, vec4f_t vright, { vec4f_t left, up, right, down; vec4f_t ul, ur, ll, lr; + vec4f_t origin = Transform_GetWorldPosition (currententity->transform); // build the sprite poster in worldspace // first, rotate the sprite axes into world space @@ -198,12 +199,12 @@ make_quad (mspriteframe_t *frame, vec4f_t vpn, vec4f_t vright, ll = down + left; lr = down + right; // finally, translate the sprite corners, creating two triangles - VectorAdd (currententity->origin, ul, verts[0]); // first triangle - VectorAdd (currententity->origin, ur, verts[1]); - VectorAdd (currententity->origin, lr, verts[2]); - VectorAdd (currententity->origin, ul, verts[3]); // second triangle - VectorAdd (currententity->origin, lr, verts[4]); - VectorAdd (currententity->origin, ll, verts[5]); + VectorAdd (origin, ul, verts[0]); // first triangle + VectorAdd (origin, ur, verts[1]); + VectorAdd (origin, lr, verts[2]); + VectorAdd (origin, ul, verts[3]); // second triangle + VectorAdd (origin, lr, verts[4]); + VectorAdd (origin, ll, verts[5]); } void @@ -212,9 +213,9 @@ R_DrawSprite (void) entity_t *ent = currententity; msprite_t *sprite = (msprite_t *) ent->renderer.model->cache.data; mspriteframe_t *frame1, *frame2; - float blend, sr, cr, dot, angle; + float blend, sr, cr, dot; vec3_t tvec; - vec4f_t svpn = {}, svright = {}, svup = {}; + vec4f_t svpn = {}, svright = {}, svup = {}, rot; static quat_t color = { 1, 1, 1, 1}; float vertsa[6][3], vertsb[6][3]; static float uvab[6][4] = { @@ -284,9 +285,10 @@ R_DrawSprite (void) // rotated in that plane round the center according to the sprite // entity's roll angle. Thus svpn stays the same, but svright and // svup rotate - angle = currententity->angles[ROLL] * (M_PI / 180); - sr = sin (angle); - cr = cos (angle); + rot = Transform_GetLocalRotation (currententity->transform); + //FIXME assumes the entity is only rolled + sr = 2 * rot[0] * rot[3]; + cr = rot[3] * rot[3] - rot[0] * rot[0]; VectorCopy (vpn, svpn); VectorScale (vright, cr, svright); VectorMultAdd (svright, sr, vup, svright); diff --git a/libs/video/renderer/r_efrag.c b/libs/video/renderer/r_efrag.c index 86d494b6d..eb559e9cd 100644 --- a/libs/video/renderer/r_efrag.c +++ b/libs/video/renderer/r_efrag.c @@ -30,6 +30,7 @@ #include +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" @@ -210,8 +211,9 @@ R_AddEfrags (mod_brush_t *brush, entity_t *ent) entmodel = ent->renderer.model; - VectorAdd (ent->origin, entmodel->mins, emins); - VectorAdd (ent->origin, entmodel->maxs, emaxs); + vec4f_t org = Transform_GetWorldPosition (ent->transform); + VectorAdd (org, entmodel->mins, emins); + VectorAdd (org, entmodel->maxs, emaxs); ent->visibility.topnode = 0; R_SplitEntityOnNode (brush, ent, emins, emaxs); diff --git a/libs/video/renderer/sw/d_edge.c b/libs/video/renderer/sw/d_edge.c index f510e2063..d1e8a4e29 100644 --- a/libs/video/renderer/sw/d_edge.c +++ b/libs/video/renderer/sw/d_edge.c @@ -29,6 +29,7 @@ #endif #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/render.h" #include "d_local.h" @@ -207,7 +208,8 @@ D_DrawSurfaces (void) // TODO: store once at start of frame currententity = s->entity; // FIXME: make this passed in // to R_RotateBmodel () - VectorSubtract (r_origin, currententity->origin, + VectorSubtract (r_origin, + Transform_GetWorldPosition (currententity->transform), local_modelorg); TransformVector (local_modelorg, transformed_modelorg); @@ -240,7 +242,8 @@ D_DrawSurfaces (void) // TODO: store once at start of frame currententity = s->entity; // FIXME: make this passed in // to R_RotateBmodel () - VectorSubtract (r_origin, currententity->origin, + VectorSubtract (r_origin, + Transform_GetWorldPosition (currententity->transform), local_modelorg); TransformVector (local_modelorg, transformed_modelorg); diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index 8ab480bcc..63eecbb60 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -362,16 +362,16 @@ R_DrawEntitiesOnList (void) for (ent = r_ent_queue; ent; ent = ent->next) { currententity = ent; + VectorCopy (Transform_GetWorldPosition (currententity->transform), + r_entorigin); switch (currententity->renderer.model->type) { case mod_sprite: - VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); R_DrawSprite (); break; case mod_alias: case mod_iqm: - VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); minlight = max (currententity->renderer.model->min_light, @@ -384,7 +384,7 @@ R_DrawEntitiesOnList (void) || R_AliasCheckBBox ()) { // 128 instead of 255 due to clamping below j = max (R_LightPoint (&r_worldentity.renderer.model->brush, - currententity->origin), minlight * 128); + r_entorigin), minlight * 128); lighting.ambientlight = j; lighting.shadelight = j; @@ -393,7 +393,7 @@ R_DrawEntitiesOnList (void) for (lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= vr_data.realtime) { - VectorSubtract (currententity->origin, + VectorSubtract (r_entorigin, r_dlights[lnum].origin, dist); add = r_dlights[lnum].radius - VectorLength (dist); @@ -443,7 +443,8 @@ R_DrawViewModel (void) if (!currententity->renderer.model) return; - VectorCopy (currententity->origin, r_entorigin); + VectorCopy (Transform_GetWorldPosition (currententity->transform), + r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); VectorCopy (vup, viewlightvec); @@ -453,7 +454,7 @@ R_DrawViewModel (void) currententity->renderer.model->min_light); j = max (R_LightPoint (&r_worldentity.renderer.model->brush, - currententity->origin), minlight * 128); + r_entorigin), minlight * 128); r_viewlighting.ambientlight = j; r_viewlighting.shadelight = j; @@ -468,7 +469,7 @@ R_DrawViewModel (void) if (dl->die < vr_data.realtime) continue; - VectorSubtract (currententity->origin, dl->origin, dist); + VectorSubtract (r_entorigin, dl->origin, dist); add = dl->radius - VectorLength (dist); if (add > 0) r_viewlighting.ambientlight += add; @@ -498,7 +499,7 @@ R_BmodelCheckBBox (model_t *clmodel, float *minmaxs) Transform_GetWorldMatrix (currententity->transform, mat); if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { for (i = 0; i < 4; i++) { - d = DotProduct (currententity->origin, view_clipplanes[i].normal); + d = DotProduct (mat[3], view_clipplanes[i].normal); d -= view_clipplanes[i].dist; if (d <= -clmodel->radius) @@ -546,6 +547,7 @@ R_DrawBEntitiesOnList (void) int j, clipflags; unsigned int k; vec3_t oldorigin; + vec3_t origin; model_t *clmodel; float minmaxs[6]; entity_t *ent; @@ -559,6 +561,8 @@ R_DrawBEntitiesOnList (void) for (ent = r_ent_queue; ent; ent = ent->next) { currententity = ent; + VectorCopy (Transform_GetWorldPosition (currententity->transform), + origin); switch (currententity->renderer.model->type) { case mod_brush: clmodel = currententity->renderer.model; @@ -566,16 +570,15 @@ R_DrawBEntitiesOnList (void) // see if the bounding box lets us trivially reject, also // sets trivial accept status for (j = 0; j < 3; j++) { - minmaxs[j] = currententity->origin[j] + clmodel->mins[j]; - minmaxs[3 + j] = currententity->origin[j] + - clmodel->maxs[j]; + minmaxs[j] = origin[j] + clmodel->mins[j]; + minmaxs[3 + j] = origin[j] + clmodel->maxs[j]; } clipflags = R_BmodelCheckBBox (clmodel, minmaxs); if (clipflags != BMODEL_FULLY_CLIPPED) { mod_brush_t *brush = &clmodel->brush; - VectorCopy (currententity->origin, r_entorigin); + VectorCopy (origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); // FIXME: is this needed? @@ -594,8 +597,7 @@ R_DrawBEntitiesOnList (void) if ((r_dlights[k].die < vr_data.realtime) || (!r_dlights[k].radius)) continue; - VectorSubtract (r_dlights[k].origin, - currententity->origin, + VectorSubtract (r_dlights[k].origin, origin, lightorigin); R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k, @@ -829,7 +831,7 @@ R_RenderView_ (void) R_HighFPPrecision (); } -static void R_RenderViewFishEye (void); +//XXX FIXME static void R_RenderViewFishEye (void); void R_RenderView (void) @@ -849,11 +851,12 @@ R_RenderView (void) if ((intptr_t) (&r_warpbuffer) & 3) Sys_Error ("Globals are missaligned"); - + R_RenderView_ (); +/*XXX FIXME if (!scr_fisheye->int_val) R_RenderView_ (); else - R_RenderViewFishEye (); + R_RenderViewFishEye ();*/ } void @@ -867,7 +870,7 @@ R_InitTurb (void) // AMP2 not 20 } } - +/*XXX FIXME #define BOX_FRONT 0 #define BOX_BEHIND 2 #define BOX_LEFT 3 @@ -1152,7 +1155,7 @@ R_RenderViewFishEye (void) r_refdef.viewangles[PITCH] = pitch; r_refdef.viewangles[ROLL] = roll; renderlookup (offs, scrbufs); -} +}*/ void R_ClearState (void) diff --git a/libs/video/renderer/sw/sw_rmisc.c b/libs/video/renderer/sw/sw_rmisc.c index dee5c780e..2ea74ad4e 100644 --- a/libs/video/renderer/sw/sw_rmisc.c +++ b/libs/video/renderer/sw/sw_rmisc.c @@ -53,6 +53,7 @@ R_CheckVariables (void) void R_TimeRefresh_f (void) { +/* FIXME update for simd int i; float start, stop, time; int startangle; @@ -82,6 +83,7 @@ R_TimeRefresh_f (void) Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time); r_refdef.viewangles[1] = startangle; +*/ } void @@ -237,10 +239,12 @@ R_SetupFrame (void) #endif // build the transformation matrix for the given view angles - VectorCopy (r_refdef.vieworg, modelorg); - VectorCopy (r_refdef.vieworg, r_origin); + VectorCopy (r_refdef.viewposition, modelorg); + VectorCopy (r_refdef.viewposition, r_origin); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); R_SetFrustum (); // current viewleaf diff --git a/libs/video/renderer/sw/sw_rpart.c b/libs/video/renderer/sw/sw_rpart.c index d154ad739..c429279b2 100644 --- a/libs/video/renderer/sw/sw_rpart.c +++ b/libs/video/renderer/sw/sw_rpart.c @@ -37,6 +37,7 @@ #endif #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/mersenne.h" #include "QF/qargs.h" #include "QF/quakefs.h" @@ -386,9 +387,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) if (!r_particles->int_val) return; - org[0] = ent->origin[0]; - org[1] = ent->origin[1]; - org[2] = ent->origin[2]; + VectorCopy (Transform_GetWorldPosition (ent->transform), org); for (i = -16; i < 16; i += 8) { for (j = -16; j < 16; j += 8) { for (k = 0; k < 32; k += 8) { @@ -431,10 +430,13 @@ R_EntityParticles_ID (const entity_t *ent) float beamlength = 16.0, dist = 64.0; particle_t *p; vec3_t forward; + vec3_t org; if (!r_particles->int_val) return; + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + for (i = 0; i < NUMVERTEXNORMALS; i++) { int k; for (k = 0; k < 3; k++) { @@ -470,11 +472,11 @@ R_EntityParticles_ID (const entity_t *ent) p->type = pt_explode; p->phys = R_ParticlePhysics (p->type); - p->org[0] = ent->origin[0] + r_avertexnormals[i][0] * dist + + p->org[0] = org[0] + r_avertexnormals[i][0] * dist + forward[0] * beamlength; - p->org[1] = ent->origin[1] + r_avertexnormals[i][1] * dist + + p->org[1] = org[1] + r_avertexnormals[i][1] * dist + forward[1] * beamlength; - p->org[2] = ent->origin[2] + r_avertexnormals[i][2] * dist + + p->org[2] = org[2] + r_avertexnormals[i][2] * dist + forward[2] * beamlength; } } @@ -486,12 +488,14 @@ R_RocketTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; + VectorCopy (Transform_GetWorldPosition (ent->transform), org); VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -525,12 +529,14 @@ R_GrenadeTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -564,12 +570,14 @@ R_BloodTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -602,12 +610,14 @@ R_SlightBloodTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -639,12 +649,14 @@ R_WizTrail_QF (const entity_t *ent) float len; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -686,12 +698,14 @@ R_FlameTrail_QF (const entity_t *ent) float len; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -734,12 +748,14 @@ R_VoorTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { diff --git a/libs/video/renderer/sw/sw_rsprite.c b/libs/video/renderer/sw/sw_rsprite.c index 8eb4151e7..6a70d2f4f 100644 --- a/libs/video/renderer/sw/sw_rsprite.c +++ b/libs/video/renderer/sw/sw_rsprite.c @@ -286,7 +286,7 @@ R_DrawSprite (void) int i; msprite_t *psprite; vec3_t tvec; - float dot, angle, sr, cr; + float dot, sr, cr; psprite = currententity->renderer.model->cache.data; @@ -371,9 +371,10 @@ R_DrawSprite (void) // generate the sprite's axes, parallel to the viewplane, but rotated // in that plane around the center according to the sprite entity's // roll angle. So vpn stays the same, but vright and vup rotate - angle = currententity->angles[ROLL] * (M_PI * 2 / 360); - sr = sin (angle); - cr = cos (angle); + vec4f_t rot = Transform_GetLocalRotation (currententity->transform); + //FIXME assumes the entity is only rolled + sr = 2 * rot[0] * rot[3]; + cr = rot[3] * rot[3] - rot[0] * rot[0]; for (i = 0; i < 3; i++) { r_spritedesc.vpn[i] = vpn[i]; diff --git a/libs/video/renderer/sw/sw_rsurf.c b/libs/video/renderer/sw/sw_rsurf.c index 1dded8c00..36ea5fe79 100644 --- a/libs/video/renderer/sw/sw_rsurf.c +++ b/libs/video/renderer/sw/sw_rsurf.c @@ -28,6 +28,7 @@ # include "config.h" #endif +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" @@ -78,6 +79,7 @@ R_AddDynamicLights (void) int sd, td; float dist, rad, minlight; vec3_t impact, local, lightorigin; + vec4f_t entorigin = { 0, 0, 0, 1 }; int s, t; int i; int smax, tmax; @@ -88,12 +90,16 @@ R_AddDynamicLights (void) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; + if (currententity->transform) { + //FIXME give world entity a transform + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light - VectorSubtract (r_dlights[lnum].origin, currententity->origin, - lightorigin); + VectorSubtract (r_dlights[lnum].origin, entorigin, lightorigin); rad = r_dlights[lnum].radius; dist = DotProduct (lightorigin, surf->plane->normal) - surf->plane->dist; diff --git a/libs/video/renderer/sw32/d_edge.c b/libs/video/renderer/sw32/d_edge.c index 6fa0b131a..6015eaf23 100644 --- a/libs/video/renderer/sw32/d_edge.c +++ b/libs/video/renderer/sw32/d_edge.c @@ -32,6 +32,7 @@ #include "namehack.h" #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" @@ -243,7 +244,8 @@ sw32_D_DrawSurfaces (void) // TODO: store once at start of frame currententity = s->entity; // FIXME: make this passed in // to sw32_R_RotateBmodel () - VectorSubtract (r_origin, currententity->origin, + VectorSubtract (r_origin, + Transform_GetWorldPosition (currententity->transform), local_modelorg); sw32_TransformVector (local_modelorg, transformed_modelorg); @@ -276,7 +278,8 @@ sw32_D_DrawSurfaces (void) // TODO: store once at start of frame currententity = s->entity; // FIXME: make this passed in // to sw32_R_RotateBmodel () - VectorSubtract (r_origin, currententity->origin, + VectorSubtract (r_origin, + Transform_GetWorldPosition (currententity->transform), local_modelorg); sw32_TransformVector (local_modelorg, transformed_modelorg); diff --git a/libs/video/renderer/sw32/sw32_rmain.c b/libs/video/renderer/sw32/sw32_rmain.c index 36d94fd2a..d6dfd7670 100644 --- a/libs/video/renderer/sw32/sw32_rmain.c +++ b/libs/video/renderer/sw32/sw32_rmain.c @@ -369,16 +369,16 @@ R_DrawEntitiesOnList (void) for (ent = r_ent_queue; ent; ent = ent->next) { currententity = ent; + VectorCopy (Transform_GetWorldPosition (currententity->transform), + r_entorigin); switch (currententity->renderer.model->type) { case mod_sprite: - VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); sw32_R_DrawSprite (); break; case mod_alias: case mod_iqm: - VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); minlight = max (currententity->renderer.min_light, @@ -391,7 +391,7 @@ R_DrawEntitiesOnList (void) || sw32_R_AliasCheckBBox ()) { // 128 instead of 255 due to clamping below j = max (R_LightPoint (&r_worldentity.renderer.model->brush, - currententity->origin), + r_entorigin), minlight * 128); lighting.ambientlight = j; @@ -401,7 +401,7 @@ R_DrawEntitiesOnList (void) for (lnum = 0; lnum < r_maxdlights; lnum++) { if (r_dlights[lnum].die >= vr_data.realtime) { - VectorSubtract (currententity->origin, + VectorSubtract (r_entorigin, r_dlights[lnum].origin, dist); add = r_dlights[lnum].radius - VectorLength (dist); @@ -450,7 +450,8 @@ R_DrawViewModel (void) if (!currententity->renderer.model) return; - VectorCopy (currententity->origin, r_entorigin); + VectorCopy (Transform_GetWorldPosition (currententity->transform), + r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); VectorCopy (vup, viewlightvec); @@ -460,7 +461,7 @@ R_DrawViewModel (void) currententity->renderer.model->min_light); j = max (R_LightPoint (&r_worldentity.renderer.model->brush, - currententity->origin), minlight * 128); + r_entorigin), minlight * 128); r_viewlighting.ambientlight = j; r_viewlighting.shadelight = j; @@ -475,7 +476,7 @@ R_DrawViewModel (void) if (dl->die < vr_data.realtime) continue; - VectorSubtract (currententity->origin, dl->origin, dist); + VectorSubtract (r_entorigin, dl->origin, dist); add = dl->radius - VectorLength (dist); if (add > 0) r_viewlighting.ambientlight += add; @@ -505,7 +506,7 @@ R_BmodelCheckBBox (model_t *clmodel, float *minmaxs) Transform_GetWorldMatrix (currententity->transform, mat); if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { for (i = 0; i < 4; i++) { - d = DotProduct (currententity->origin, sw32_view_clipplanes[i].normal); + d = DotProduct (mat[3], sw32_view_clipplanes[i].normal); d -= sw32_view_clipplanes[i].dist; if (d <= -clmodel->radius) @@ -553,6 +554,7 @@ R_DrawBEntitiesOnList (void) int j, clipflags; unsigned int k; vec3_t oldorigin; + vec3_t origin; model_t *clmodel; float minmaxs[6]; entity_t *ent; @@ -566,6 +568,8 @@ R_DrawBEntitiesOnList (void) for (ent = r_ent_queue; ent; ent = ent->next) { currententity = ent; + VectorCopy (Transform_GetWorldPosition (currententity->transform), + origin); switch (currententity->renderer.model->type) { case mod_brush: clmodel = currententity->renderer.model; @@ -573,16 +577,15 @@ R_DrawBEntitiesOnList (void) // see if the bounding box lets us trivially reject, also // sets trivial accept status for (j = 0; j < 3; j++) { - minmaxs[j] = currententity->origin[j] + clmodel->mins[j]; - minmaxs[3 + j] = currententity->origin[j] + - clmodel->maxs[j]; + minmaxs[j] = origin[j] + clmodel->mins[j]; + minmaxs[3 + j] = origin[j] + clmodel->maxs[j]; } clipflags = R_BmodelCheckBBox (clmodel, minmaxs); if (clipflags != BMODEL_FULLY_CLIPPED) { mod_brush_t *brush = &clmodel->brush; - VectorCopy (currententity->origin, r_entorigin); + VectorCopy (origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); // FIXME: is this needed? @@ -601,8 +604,7 @@ R_DrawBEntitiesOnList (void) if ((r_dlights[k].die < vr_data.realtime) || (!r_dlights[k].radius)) continue; - VectorSubtract (r_dlights[k].origin, - currententity->origin, + VectorSubtract (r_dlights[k].origin, origin, lightorigin); R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k, diff --git a/libs/video/renderer/sw32/sw32_rmisc.c b/libs/video/renderer/sw32/sw32_rmisc.c index 753268993..390b13b86 100644 --- a/libs/video/renderer/sw32/sw32_rmisc.c +++ b/libs/video/renderer/sw32/sw32_rmisc.c @@ -55,6 +55,7 @@ R_CheckVariables (void) void sw32_R_TimeRefresh_f (void) { +/* FIXME update for simd int i; float start, stop, time; int startangle; @@ -84,6 +85,7 @@ sw32_R_TimeRefresh_f (void) Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time); r_refdef.viewangles[1] = startangle; +*/ } void @@ -233,10 +235,12 @@ sw32_R_SetupFrame (void) #endif // build the transformation matrix for the given view angles - VectorCopy (r_refdef.vieworg, modelorg); - VectorCopy (r_refdef.vieworg, r_origin); + VectorCopy (r_refdef.viewposition, modelorg); + VectorCopy (r_refdef.viewposition, r_origin); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); R_SetFrustum (); // current viewleaf diff --git a/libs/video/renderer/sw32/sw32_rpart.c b/libs/video/renderer/sw32/sw32_rpart.c index fc640bc8e..851618819 100644 --- a/libs/video/renderer/sw32/sw32_rpart.c +++ b/libs/video/renderer/sw32/sw32_rpart.c @@ -40,6 +40,7 @@ #endif #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/mersenne.h" #include "QF/qargs.h" #include "QF/quakefs.h" @@ -330,9 +331,7 @@ R_DarkFieldParticles_ID (const entity_t *ent) particle_t *p; vec3_t dir, org; - org[0] = ent->origin[0]; - org[1] = ent->origin[1]; - org[2] = ent->origin[2]; + VectorCopy (Transform_GetWorldPosition (ent->transform), org); for (i = -16; i < 16; i += 8) { for (j = -16; j < 16; j += 8) { for (k = 0; k < 32; k += 8) { @@ -376,6 +375,9 @@ R_EntityParticles_ID (const entity_t *ent) float beamlength = 16.0, dist = 64.0; particle_t *p; vec3_t forward; + vec3_t org; + + VectorCopy (Transform_GetWorldPosition (ent->transform), org); for (i = 0; i < NUMVERTEXNORMALS; i++) { int k; @@ -412,11 +414,11 @@ R_EntityParticles_ID (const entity_t *ent) p->type = pt_explode; p->phys = R_ParticlePhysics (p->type); - p->org[0] = ent->origin[0] + r_avertexnormals[i][0] * dist + + p->org[0] = org[0] + r_avertexnormals[i][0] * dist + forward[0] * beamlength; - p->org[1] = ent->origin[1] + r_avertexnormals[i][1] * dist + + p->org[1] = org[1] + r_avertexnormals[i][1] * dist + forward[1] * beamlength; - p->org[2] = ent->origin[2] + r_avertexnormals[i][2] * dist + + p->org[2] = org[2] + r_avertexnormals[i][2] * dist + forward[2] * beamlength; } } @@ -499,12 +501,14 @@ R_RocketTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, ent->old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, ent->old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -538,12 +542,14 @@ R_GrenadeTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -577,12 +583,14 @@ R_BloodTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -615,12 +623,14 @@ R_SlightBloodTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -652,12 +662,14 @@ R_WizTrail_QF (const entity_t *ent) float len; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -699,12 +711,14 @@ R_FlameTrail_QF (const entity_t *ent) float len; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { @@ -747,12 +761,14 @@ R_VoorTrail_QF (const entity_t *ent) int j; particle_t *p; vec3_t old_origin, vec; + vec3_t org; if (!r_particles->int_val) return; VectorCopy (ent->old_origin, old_origin); - VectorSubtract (ent->origin, old_origin, vec); + VectorCopy (Transform_GetWorldPosition (ent->transform), org); + VectorSubtract (org, old_origin, vec); len = VectorNormalize (vec); while (len > 0) { diff --git a/libs/video/renderer/sw32/sw32_rsprite.c b/libs/video/renderer/sw32/sw32_rsprite.c index 9c6cb7221..bbdc1996f 100644 --- a/libs/video/renderer/sw32/sw32_rsprite.c +++ b/libs/video/renderer/sw32/sw32_rsprite.c @@ -282,7 +282,7 @@ sw32_R_DrawSprite (void) int i; msprite_t *psprite; vec3_t tvec; - float dot, angle, sr, cr; + float dot, sr, cr; psprite = currententity->renderer.model->cache.data; @@ -367,9 +367,10 @@ sw32_R_DrawSprite (void) // generate the sprite's axes, parallel to the viewplane, but rotated // in that plane around the center according to the sprite entity's // roll angle. So vpn stays the same, but vright and vup rotate - angle = currententity->angles[ROLL] * (M_PI * 2 / 360); - sr = sin (angle); - cr = cos (angle); + vec4f_t rot = Transform_GetLocalRotation (currententity->transform); + //FIXME assumes the entity is only rolled + sr = 2 * rot[0] * rot[3]; + cr = rot[3] * rot[3] - rot[0] * rot[0]; for (i = 0; i < 3; i++) { sw32_r_spritedesc.vpn[i] = vpn[i]; diff --git a/libs/video/renderer/sw32/sw32_rsurf.c b/libs/video/renderer/sw32/sw32_rsurf.c index dfc9c31cc..9eba575a9 100644 --- a/libs/video/renderer/sw32/sw32_rsurf.c +++ b/libs/video/renderer/sw32/sw32_rsurf.c @@ -31,6 +31,7 @@ #define NH_DEFINE #include "namehack.h" +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" @@ -96,6 +97,7 @@ R_AddDynamicLights (void) int sd, td; float dist, rad, minlight; vec3_t impact, local, lightorigin; + vec4f_t entorigin = { 0, 0, 0, 1 }; int s, t; int i; int smax, tmax; @@ -106,12 +108,16 @@ R_AddDynamicLights (void) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; + if (currententity->transform) { + //FIXME give world entity a transform + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light - VectorSubtract (r_dlights[lnum].origin, currententity->origin, - lightorigin); + VectorSubtract (r_dlights[lnum].origin, entorigin, lightorigin); rad = r_dlights[lnum].radius; dist = DotProduct (lightorigin, surf->plane->normal) - surf->plane->dist; diff --git a/libs/video/renderer/vulkan/shader/lighting.frag b/libs/video/renderer/vulkan/shader/lighting.frag index e2db7cc78..7468e4dec 100644 --- a/libs/video/renderer/vulkan/shader/lighting.frag +++ b/libs/video/renderer/vulkan/shader/lighting.frag @@ -44,7 +44,7 @@ main (void) vec3 c = subpassLoad (color).rgb; vec3 n = subpassLoad (normal).rgb; vec3 p = subpassLoad (position).rgb; - vec3 light = vec3 (0); + vec3 light = vec3 (0.8); if (MaxLights > 0) { for (int i = 0; i < lightCount; i++) { diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index 38aa57ee9..f1ba6e472 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -610,7 +610,8 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx) plane_t *plane; msurface_t *surf; qboolean rotated; - vec3_t mins, maxs, org; + vec3_t mins, maxs; + vec4f_t org; mod_brush_t *brush; model = e->renderer.model; @@ -621,21 +622,21 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx) if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { rotated = true; radius = model->radius; - if (R_CullSphere (e->origin, radius)) + if (R_CullSphere (&mat[3][0], radius)) { //FIXME return; + } } else { rotated = false; - VectorAdd (e->origin, model->mins, mins); - VectorAdd (e->origin, model->maxs, maxs); + VectorAdd (mat[3], model->mins, mins); + VectorAdd (mat[3], model->maxs, maxs); if (R_CullBox (mins, maxs)) return; } - VectorSubtract (r_refdef.vieworg, e->origin, org); + org = r_refdef.viewposition - mat[3]; if (rotated) { - vec3_t temp; + vec4f_t temp = org; - VectorCopy (org, temp); org[0] = DotProduct (temp, mat[0]); org[1] = DotProduct (temp, mat[1]); org[2] = DotProduct (temp, mat[2]); @@ -650,7 +651,7 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx) || (!r_dlights[k].radius)) continue; - VectorSubtract (r_dlights[k].origin, e->origin, lightorigin); + VectorSubtract (r_dlights[k].origin, mat[3], lightorigin); R_RecursiveMarkLights (brush, lightorigin, &r_dlights[k], k, brush->nodes + brush->hulls[0].firstclipnode); } diff --git a/libs/video/renderer/vulkan/vulkan_lightmap.c b/libs/video/renderer/vulkan/vulkan_lightmap.c index 97c30c667..3cfbcb7ba 100644 --- a/libs/video/renderer/vulkan/vulkan_lightmap.c +++ b/libs/video/renderer/vulkan/vulkan_lightmap.c @@ -41,6 +41,7 @@ #include #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/render.h" #include "QF/sys.h" #include "QF/Vulkan/qf_bsp.h" @@ -61,6 +62,7 @@ add_dynamic_lights (msurface_t *surf, float *block) int sd, td; float dist, rad, minlight; vec3_t impact, local, lightorigin; + vec4f_t entorigin = { 0, 0, 0, 1 }; int smax, tmax; int s, t; mtexinfo_t *tex; @@ -71,13 +73,18 @@ add_dynamic_lights (msurface_t *surf, float *block) tex = surf->texinfo; plane = surf->plane; + if (currententity->transform) { + //FIXME give world entity a transform + entorigin = Transform_GetWorldPosition (currententity->transform); + } + for (lnum = 0; lnum < r_maxdlights; lnum++) { if (!(surf->dlightbits[lnum / 32] & (1 << (lnum % 32)))) continue; // not lit by this light dlight_t *light = &r_dlights[lnum]; - VectorSubtract (light->origin, currententity->origin, lightorigin); + VectorSubtract (light->origin, entorigin, lightorigin); rad = light->radius; dist = DotProduct (lightorigin, plane->normal) - plane->dist; rad -= fabs (dist); diff --git a/libs/video/renderer/vulkan/vulkan_main.c b/libs/video/renderer/vulkan/vulkan_main.c index e63ff0b03..a7ed49669 100644 --- a/libs/video/renderer/vulkan/vulkan_main.c +++ b/libs/video/renderer/vulkan/vulkan_main.c @@ -66,8 +66,11 @@ setup_frame (vulkan_ctx_t *ctx) R_ClearEnts (); r_framecount++; - VectorCopy (r_refdef.vieworg, r_origin); - AngleVectors (r_refdef.viewangles, vpn, vright, vup); + VectorCopy (r_refdef.viewposition, r_origin); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); + R_SetFrustum (); r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.renderer.model); @@ -76,14 +79,14 @@ setup_frame (vulkan_ctx_t *ctx) static void setup_view (vulkan_ctx_t *ctx) { - mat4_t mat; - float *view = ctx->matrices.view_3d; - static mat4_t z_up = { - 0, 0, -1, 0, - -1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 0, 1, + mat4f_t view; + static mat4f_t z_up = { + { 0, 0, -1, 0}, + {-1, 0, 0, 0}, + { 0, 1, 0, 0}, + { 0, 0, 0, 1}, }; + vec4f_t offset = { 0, 0, 0, 1 }; /*x = r_refdef.vrect.x; y = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)); @@ -91,17 +94,12 @@ setup_view (vulkan_ctx_t *ctx) h = r_refdef.vrect.height; qfeglViewport (x, y, w, h);*/ - Mat4Zero (mat); - VectorCopy (vpn, mat + 0); - VectorNegate (vright, mat + 4); // we want vleft - VectorCopy (vup, mat + 8); - mat[15] = 1; - Mat4Transpose (mat, mat);//AngleVectors gives the transpose of what we want - Mat4Mult (z_up, mat, view); - - Mat4Identity (mat); - VectorNegate (r_refdef.vieworg, mat + 12); - Mat4Mult (view, mat, view); + mat4fquat (view, qconjf (r_refdef.viewrotation)); + mmulf (view, z_up, view); + offset = -r_refdef.viewposition; + offset[3] = 1; + view[3] = mvmulf (view, offset); + memcpy (ctx->matrices.view_3d, view, sizeof (view)); } static void diff --git a/nq/include/client.h b/nq/include/client.h index 4af07cd24..5d98e437b 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -38,6 +38,7 @@ #include "QF/render.h" #include "client/entities.h" +#include "client/view.h" #include "game.h" #include "netmain.h" @@ -165,11 +166,9 @@ typedef struct { int frameIndex; vec3_t frameViewAngles[2]; // During demo playback viewangles is lerped // between these - vec3_t viewangles; vec4f_t frameVelocity[2]; // Update by server, used for lean+bob // (0 is newest) - vec4f_t velocity; // Lerped between frameVelocity[0] and [1] - vec3_t punchangle; // Temporary offset + viewstate_t viewstate; // pitch drifting vars float idealpitch; diff --git a/nq/source/cl_chase.c b/nq/source/cl_chase.c index 5d23817cd..6f0c430c6 100644 --- a/nq/source/cl_chase.c +++ b/nq/source/cl_chase.c @@ -41,16 +41,19 @@ #include "QF/mathlib.h" #include "QF/plugin/vid_render.h" +#include "QF/simd/vec4f.h" #include "world.h" #include "nq/include/chase.h" #include "nq/include/client.h" -vec3_t camera_origin = {0,0,0}; -vec3_t camera_angles = {0,0,0}; -vec3_t player_origin = {0,0,0}; -vec3_t player_angles = {0,0,0}; + +vec4f_t camera_origin = {0,0,0,1}; +vec4f_t player_origin = {0,0,0,1}; +vec4f_t player_angles = {0,0,0,1}; + +vec3_t camera_angles = {0,0,0}; vec3_t chase_angles; vec3_t chase_dest; @@ -94,19 +97,17 @@ TraceLine (vec3_t start, vec3_t end, vec3_t impact) void Chase_Update (void) { - float pitch, yaw, fwd; - int i; - usercmd_t cmd; // movement direction - vec3_t forward, up, right, stop, dir; + float pitch, yaw, fwd; + usercmd_t cmd; // movement direction + vec4f_t forward = {}, up = {}, right = {}, stop = {}, dir = {}; // lazy camera, look toward player entity if (chase_active->int_val == 2 || chase_active->int_val == 3) { // control camera angles with key/mouse/joy-look - - camera_angles[PITCH] += cl.viewangles[PITCH] - player_angles[PITCH]; - camera_angles[YAW] += cl.viewangles[YAW] - player_angles[YAW]; - camera_angles[ROLL] += cl.viewangles[ROLL] - player_angles[ROLL]; + vec3_t d; + VectorSubtract (cl.viewstate.angles, player_angles, d); + VectorAdd (camera_angles, d, camera_angles); if (chase_active->int_val == 2) { if (camera_angles[PITCH] < -60) @@ -118,48 +119,48 @@ Chase_Update (void) // move camera, it's not enough to just change the angles because // the angles are automatically changed to look toward the player - if (chase_active->int_val == 3) - VectorCopy (r_data->refdef->vieworg, player_origin); + if (chase_active->int_val == 3) { + player_origin = r_data->refdef->viewposition; + } - AngleVectors (camera_angles, forward, right, up); - VectorScale (forward, chase_back->value, forward); - VectorSubtract (player_origin, forward, camera_origin); + AngleVectors (camera_angles, &forward[0], &right[0], &up[0]); + camera_origin = player_origin - chase_back->value * forward; if (chase_active->int_val == 2) { - VectorCopy (r_data->refdef->vieworg, player_origin); + player_origin = r_data->refdef->viewposition; // don't let camera get too low - if (camera_origin[2] < player_origin[2] + chase_up->value) + if (camera_origin[2] < player_origin[2] + chase_up->value) { camera_origin[2] = player_origin[2] + chase_up->value; + } } // don't let camera get too far from player - VectorSubtract (camera_origin, player_origin, dir); - VectorCopy (dir, forward); - VectorNormalize (forward); + dir = camera_origin - player_origin; + forward = normalf (dir); - if (VectorLength (dir) > chase_back->value) { - VectorScale (forward, chase_back->value, dir); - VectorAdd (player_origin, dir, camera_origin); + if (magnitudef (dir)[0] > chase_back->value) { + camera_origin = player_origin + forward * chase_back->value; } // check for walls between player and camera - VectorScale (forward, 8, forward); - VectorAdd (camera_origin, forward, camera_origin); - TraceLine (player_origin, camera_origin, stop); - if (VectorLength (stop) != 0) - VectorSubtract (stop, forward, camera_origin); + camera_origin += 8 * forward; + //FIXME + TraceLine (&player_origin[0], &camera_origin[0], &stop[0]); + stop[3] = 1; + if (magnitude3f (stop)[0] != 0) { + camera_origin = stop - forward; + } - VectorSubtract (camera_origin, r_data->refdef->vieworg, dir); - VectorCopy (dir, forward); - VectorNormalize (forward); + dir = camera_origin - r_data->refdef->viewposition; + forward = normalf (dir); if (chase_active->int_val == 2) { if (dir[1] == 0 && dir[0] == 0) { // look straight up or down -// camera_angles[YAW] = r_data->refdef->viewangles[YAW]; +// camera_angles[YAW] = r_data->refdef->viewstate.angles[YAW]; if (dir[2] > 0) camera_angles[PITCH] = 90; else @@ -182,13 +183,13 @@ Chase_Update (void) } } - VectorCopy (camera_angles, r_data->refdef->viewangles);// rotate camera - VectorCopy (camera_origin, r_data->refdef->vieworg); // move camera + AngleQuat (camera_angles, &r_data->refdef->viewrotation[0]);//FIXME rotate camera + r_data->refdef->viewposition = camera_origin; // move camera // get basic movement from keyboard memset (&cmd, 0, sizeof (cmd)); -// VectorCopy (cl.viewangles, cmd.angles); +// VectorCopy (cl.viewstate.angles, cmd.angles); if (in_strafe.state & 1) { cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_right); @@ -208,54 +209,54 @@ Chase_Update (void) } // mouse and joystick controllers add to movement - VectorSet (0, cl.viewangles[1] - camera_angles[1], 0, dir); - AngleVectors (dir, forward, right, up); - VectorScale (forward, viewdelta.position[2] * m_forward->value, - forward); - VectorScale (right, viewdelta.position[0] * m_side->value, right); - VectorAdd (forward, right, dir); + VectorSet (0, cl.viewstate.angles[1] - camera_angles[1], 0, dir); + AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME + forward *= viewdelta.position[2] * m_forward->value; + right *= viewdelta.position[0] * m_side->value; + dir = forward + right; cmd.forwardmove += dir[0]; cmd.sidemove -= dir[1]; VectorSet (0, camera_angles[1], 0, dir); - AngleVectors (dir, forward, right, up); + AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME VectorScale (forward, cmd.forwardmove, forward); VectorScale (right, cmd.sidemove, right); VectorAdd (forward, right, dir); if (dir[1] || dir[0]) { - cl.viewangles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI); - if (cl.viewangles[YAW] < 0) cl.viewangles[YAW] += 360; -// if (cl.viewangles[YAW] < 180) -// cl.viewangles[YAW] += 180; -// else -// cl.viewangles[YAW] -= 180; + cl.viewstate.angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI); + if (cl.viewstate.angles[YAW] < 0) { + cl.viewstate.angles[YAW] += 360; + } } - cl.viewangles[PITCH] = 0; + cl.viewstate.angles[PITCH] = 0; // remember the new angle to calculate the difference next frame - VectorCopy (cl.viewangles, player_angles); + VectorCopy (cl.viewstate.angles, player_angles); return; } // regular camera, faces same direction as player - AngleVectors (cl.viewangles, forward, right, up); + //FIXME + AngleVectors (cl.viewstate.angles, &forward[0], &right[0], &up[0]); // calc exact destination - for (i = 0; i < 3; i++) - camera_origin[i] = r_data->refdef->vieworg[i] - - forward[i] * chase_back->value - right[i] * chase_right->value; + camera_origin = r_data->refdef->viewposition + - forward * chase_back->value - right * chase_right->value; + // chase_up is world up camera_origin[2] += chase_up->value; // check for walls between player and camera - TraceLine (r_data->refdef->vieworg, camera_origin, stop); - if (VectorLength (stop) != 0) - for (i = 0; i < 3; i++) - camera_origin[i] = stop[i] + forward[i] * 8; + //FIXME + TraceLine (&r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]); + stop[3] = 1; + if (magnitude3f (stop)[0] != 0) { + camera_origin = stop + forward * 8; + } - VectorCopy (camera_origin, r_data->refdef->vieworg); + r_data->refdef->viewposition = camera_origin; } diff --git a/nq/source/cl_demo.c b/nq/source/cl_demo.c index 39cdf9d24..03950998a 100644 --- a/nq/source/cl_demo.c +++ b/nq/source/cl_demo.c @@ -105,7 +105,7 @@ CL_WriteDemoMessage (sizebuf_t *msg) len = LittleLong (msg->cursize); Qwrite (cls.demofile, &len, 4); for (i = 0; i < 3; i++) { - f = LittleFloat (cl.viewangles[i]); + f = LittleFloat (cl.viewstate.angles[i]); Qwrite (cls.demofile, &f, 4); } Qwrite (cls.demofile, msg->data, msg->cursize); diff --git a/nq/source/cl_ents.c b/nq/source/cl_ents.c index e8aecb26c..2e04ff885 100644 --- a/nq/source/cl_ents.c +++ b/nq/source/cl_ents.c @@ -144,10 +144,9 @@ CL_RelinkEntities (void) entity_state_t *new, *old; renderer_t *renderer; animation_t *animation; - float bobjrotate, frac, f, d; + float bobjrotate, frac, f; int i, j; int entvalid; - vec3_t delta; int model_flags; r_data->player_entity = &cl_entities[cl.viewentity]; @@ -156,19 +155,21 @@ CL_RelinkEntities (void) frac = CL_LerpPoint (); // interpolate player info - cl.velocity = cl.frameVelocity[1] + cl.viewstate.velocity = cl.frameVelocity[1] + frac * (cl.frameVelocity[0] - cl.frameVelocity[1]); if (cls.demoplayback) { // interpolate the angles + vec3_t d; + VectorSubtract (cl.frameViewAngles[0], cl.frameViewAngles[1], d); for (j = 0; j < 3; j++) { - d = cl.frameViewAngles[0][j] - cl.frameViewAngles[1][j]; - if (d > 180) - d -= 360; - else if (d < -180) - d += 360; - cl.viewangles[j] = cl.frameViewAngles[1][j] + frac * d; + if (d[j] > 180) { + d[j] -= 360; + } else if (d[j] < -180) { + d[j] += 360; + } } + VectorMultAdd (cl.frameViewAngles[1], frac, d, cl.viewstate.angles); } bobjrotate = anglemod (100 * cl.time); @@ -184,8 +185,8 @@ CL_RelinkEntities (void) // if the object wasn't included in the last packet, remove it entvalid = cl_msgtime[i] == cl.mtime[0]; if (entvalid && !new->modelindex) { - VectorCopy (new->origin, ent->origin); - VectorCopy (new->angles, ent->angles); + CL_TransformEntity (ent, new->scale / 16.0, new->angles, + new->origin); entvalid = 0; } if (!entvalid) { @@ -220,7 +221,6 @@ CL_RelinkEntities (void) cl.scores[i - 1].bottomcolor); } } - ent->scale = new->scale / 16.0; VectorCopy (ent_colormod[new->colormod], renderer->colormod); renderer->colormod[3] = ENTALPHA_DECODE (new->alpha); @@ -234,32 +234,30 @@ CL_RelinkEntities (void) // The entity was not updated in the last message so move to the // final spot animation->pose1 = animation->pose2 = -1; - VectorCopy (new->origin, ent->origin); - if (!(model_flags & EF_ROTATE)) - CL_TransformEntity (ent, new->angles); + CL_TransformEntity (ent, new->scale / 16.0, new->angles, + new->origin); if (i != cl.viewentity || chase_active->int_val) { if (ent->visibility.efrag) { r_funcs->R_RemoveEfrags (ent); } r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } - VectorCopy (ent->origin, ent->old_origin); + ent->old_origin = new->origin; } else { + vec4f_t delta = new->origin - old->origin; f = frac; - VectorCopy (ent->origin, ent->old_origin); - VectorSubtract (new->origin, old->origin, delta); + ent->old_origin = Transform_GetWorldPosition (ent->transform); // If the delta is large, assume a teleport and don't lerp if (fabs (delta[0]) > 100 || fabs (delta[1] > 100) || fabs (delta[2]) > 100) { // assume a teleportation, not a motion - VectorCopy (new->origin, ent->origin); - if (!(model_flags & EF_ROTATE)) - CL_TransformEntity (ent, new->angles); + CL_TransformEntity (ent, new->scale / 16.0, new->angles, + new->origin); animation->pose1 = animation->pose2 = -1; } else { - vec3_t angles, d; // interpolate the origin and angles - VectorMultAdd (old->origin, f, delta, ent->origin); + vec3_t angles, d; + vec4f_t origin = old->origin + f * delta; if (!(model_flags & EF_ROTATE)) { VectorSubtract (new->angles, old->angles, d); for (j = 0; j < 3; j++) { @@ -269,12 +267,14 @@ CL_RelinkEntities (void) d[j] += 360; } VectorMultAdd (old->angles, f, d, angles); - CL_TransformEntity (ent, angles); } + CL_TransformEntity (ent, new->scale / 16.0, angles, origin); } if (i != cl.viewentity || chase_active->int_val) { if (ent->visibility.efrag) { - if (!VectorCompare (ent->origin, ent->old_origin)) { + vec4f_t org + = Transform_GetWorldPosition (ent->transform); + if (!VectorCompare (org, ent->old_origin)) {//FIXME r_funcs->R_RemoveEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } @@ -289,17 +289,20 @@ CL_RelinkEntities (void) vec3_t angles; VectorCopy (new->angles, angles); angles[YAW] = bobjrotate; - CL_TransformEntity (ent, angles); + CL_TransformEntity (ent, new->scale / 16.0, angles, new->origin); } CL_EntityEffects (i, ent, new, cl.time); - vec4f_t org = { VectorExpand (ent->origin), 1}; //FIXME + vec4f_t org = Transform_GetWorldPosition (ent->transform); CL_NewDlight (i, org, new->effects, new->glow_size, new->glow_color, cl.time); - if (VectorDistance_fast (old->origin, ent->origin) > (256 * 256)) - VectorCopy (ent->origin, old->origin); + if (VectorDistance_fast (old->origin, org) > (256 * 256)) { + old->origin = org; + } if (model_flags & ~EF_ROTATE) CL_ModelEffects (ent, i, new->glow_color, cl.time); cl_forcelink[i] = false; } + cl.viewstate.origin + = Transform_GetWorldPosition (cl_entities[cl.viewentity].transform); } diff --git a/nq/source/cl_input.c b/nq/source/cl_input.c index dd980e814..291f0ecac 100644 --- a/nq/source/cl_input.c +++ b/nq/source/cl_input.c @@ -438,35 +438,35 @@ CL_AdjustAngles (void) yawspeed *= host_frametime; if (!(in_strafe.state & 1)) { - cl.viewangles[YAW] -= yawspeed * CL_KeyState (&in_right); - cl.viewangles[YAW] += yawspeed * CL_KeyState (&in_left); - cl.viewangles[YAW] = anglemod (cl.viewangles[YAW]); + cl.viewstate.angles[YAW] -= yawspeed * CL_KeyState (&in_right); + cl.viewstate.angles[YAW] += yawspeed * CL_KeyState (&in_left); + cl.viewstate.angles[YAW] = anglemod (cl.viewstate.angles[YAW]); } if (in_klook.state & 1) { V_StopPitchDrift (); - cl.viewangles[PITCH] -= pitchspeed * CL_KeyState (&in_forward); - cl.viewangles[PITCH] += pitchspeed * CL_KeyState (&in_back); + cl.viewstate.angles[PITCH] -= pitchspeed * CL_KeyState (&in_forward); + cl.viewstate.angles[PITCH] += pitchspeed * CL_KeyState (&in_back); } up = CL_KeyState (&in_lookup); down = CL_KeyState (&in_lookdown); - cl.viewangles[PITCH] -= pitchspeed * up; - cl.viewangles[PITCH] += pitchspeed * down; + cl.viewstate.angles[PITCH] -= pitchspeed * up; + cl.viewstate.angles[PITCH] += pitchspeed * down; if (up || down) V_StopPitchDrift (); // FIXME: Need to clean up view angle limits - if (cl.viewangles[PITCH] > 80) - cl.viewangles[PITCH] = 80; - if (cl.viewangles[PITCH] < -70) - cl.viewangles[PITCH] = -70; + if (cl.viewstate.angles[PITCH] > 80) + cl.viewstate.angles[PITCH] = 80; + if (cl.viewstate.angles[PITCH] < -70) + cl.viewstate.angles[PITCH] = -70; - if (cl.viewangles[ROLL] > 50) - cl.viewangles[ROLL] = 50; - if (cl.viewangles[ROLL] < -50) - cl.viewangles[ROLL] = -50; + if (cl.viewstate.angles[ROLL] > 50) + cl.viewstate.angles[ROLL] = 50; + if (cl.viewstate.angles[ROLL] < -50) + cl.viewstate.angles[ROLL] = -50; } /* @@ -516,12 +516,13 @@ CL_BaseMove (usercmd_t *cmd) IN_Move (); // adjust for chase camera angles + /*FIXME:chase figure out just what this does and get it working if (cl.chase && (chase_active->int_val == 2 || chase_active->int_val == 3)) { vec3_t forward, right, up, f, r; vec3_t dir = {0, 0, 0}; - dir[1] = r_data->refdef->viewangles[1] - cl.viewangles[1]; + dir[1] = r_data->refdef->viewangles[1] - cl.viewstate.angles[1]; AngleVectors (dir, forward, right, up); VectorScale (forward, cmd->forwardmove, f); VectorScale (right, cmd->sidemove, r); @@ -532,16 +533,18 @@ CL_BaseMove (usercmd_t *cmd) viewdelta.position[2] = f[0] + r[0]; viewdelta.position[0] = (f[1] + r[1]) * -1; } + */ cmd->forwardmove += viewdelta.position[2] * m_forward->value; cmd->sidemove += viewdelta.position[0] * m_side->value; cmd->upmove += viewdelta.position[1]; - cl.viewangles[PITCH] += viewdelta.angles[PITCH] * m_pitch->value; - cl.viewangles[YAW] += viewdelta.angles[YAW] * m_yaw->value; - cl.viewangles[ROLL] += viewdelta.angles[ROLL]; + cl.viewstate.angles[PITCH] += viewdelta.angles[PITCH] * m_pitch->value; + cl.viewstate.angles[YAW] += viewdelta.angles[YAW] * m_yaw->value; + cl.viewstate.angles[ROLL] += viewdelta.angles[ROLL]; if (freelook && !(in_strafe.state & 1)) { - cl.viewangles[PITCH] = bound (-70, cl.viewangles[PITCH], 80); + cl.viewstate.angles[PITCH] + = bound (-70, cl.viewstate.angles[PITCH], 80); } } @@ -564,7 +567,7 @@ CL_SendMove (usercmd_t *cmd) MSG_WriteFloat (&buf, cl.mtime[0]); // so server can get ping times - write_angles (&buf, cl.viewangles); + write_angles (&buf, cl.viewstate.angles); MSG_WriteShort (&buf, cmd->forwardmove); MSG_WriteShort (&buf, cmd->sidemove); diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index e2c222713..e52eb5fea 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -34,6 +34,7 @@ #include "QF/console.h" #include "QF/cvar.h" #include "QF/draw.h" +#include "QF/entity.h" #include "QF/input.h" #include "QF/joystick.h" #include "QF/keys.h" @@ -52,7 +53,6 @@ #include "sbar.h" #include "client/temp_entities.h" -#include "client/view.h" #include "nq/include/chase.h" #include "nq/include/cl_skin.h" @@ -409,10 +409,11 @@ CL_PrintEntities_f (void) Sys_Printf ("EMPTY\n"); continue; } - Sys_Printf ("%s:%2i (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n", + vec4f_t org = Transform_GetWorldPosition (ent->transform); + vec4f_t rot = Transform_GetWorldRotation (ent->transform); + Sys_Printf ("%s:%2i "VEC4F_FMT" "VEC4F_FMT"\n", ent->renderer.model->path, ent->animation.frame, - VectorExpand (ent->origin), - VectorExpand (ent->angles)); + VEC4_EXP (org), VEC4_EXP (rot)); } } @@ -426,12 +427,13 @@ CL_ReadFromServer (void) { int ret; TEntContext_t tentCtx = { - {VectorExpand (cl_entities[cl.viewentity].origin), 1}, + Transform_GetWorldPosition (cl_entities[cl.viewentity].transform), cl.worldmodel, cl.viewentity }; cl.oldtime = cl.time; cl.time += host_frametime; + cl.viewstate.frametime = host_frametime; do { ret = CL_GetMessage (); @@ -535,7 +537,7 @@ CL_SetState (cactive_t state) static void Force_CenterView_f (void) { - cl.viewangles[PITCH] = 0; + cl.viewstate.angles[PITCH] = 0; } void diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index ccf535e18..e74a65976 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -41,6 +41,7 @@ #include "QF/console.h" #include "QF/cvar.h" #include "QF/dstring.h" +#include "QF/entity.h" #include "QF/idparse.h" #include "QF/input.h" #include "QF/msg.h" @@ -661,17 +662,18 @@ CL_ParseClientdata (void) cl.idealpitch = 0; cl.frameVelocity[1] = cl.frameVelocity[0]; + vec3_t punchangle = { }; for (i = 0; i < 3; i++) { - if (bits & (SU_PUNCH1 << i)) - cl.punchangle[i] = ((signed char) MSG_ReadByte (net_message)); - else - cl.punchangle[i] = 0; + if (bits & (SU_PUNCH1 << i)) { + punchangle[i] = ((signed char) MSG_ReadByte (net_message)); + } if (bits & (SU_VELOCITY1 << i)) cl.frameVelocity[0][i] = ((signed char) MSG_ReadByte (net_message)) * 16; else cl.frameVelocity[0][i] = 0; } + AngleQuat (punchangle, &cl.viewstate.punchangle[0]);//FIXME //FIXME //if (!VectorCompare (v_punchangles[0], cl.punchangle[0])) { @@ -794,9 +796,9 @@ CL_ParseStatic (int version) ent->renderer.skinnum = baseline.skinnum; VectorCopy (ent_colormod[baseline.colormod], ent->renderer.colormod); ent->renderer.colormod[3] = ENTALPHA_DECODE (baseline.alpha); - ent->scale = baseline.scale / 16.0; - VectorCopy (baseline.origin, ent->origin); - CL_TransformEntity (ent, baseline.angles); + + CL_TransformEntity (ent, baseline.scale / 16.0, baseline.angles, + baseline.origin); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } @@ -839,7 +841,7 @@ CL_ParseServerMessage (void) signon_t so; TEntContext_t tentCtx = { - {VectorExpand (cl_entities[cl.viewentity].origin), 1}, + Transform_GetWorldPosition (cl_entities[cl.viewentity].transform), cl.worldmodel, cl.viewentity }; @@ -948,7 +950,7 @@ CL_ParseServerMessage (void) case svc_setangle: { - vec_t *dest = cl.viewangles; + vec_t *dest = cl.viewstate.angles; MSG_ReadAngleV (net_message, dest); break; diff --git a/nq/source/cl_screen.c b/nq/source/cl_screen.c index 509352a1c..78d231953 100644 --- a/nq/source/cl_screen.c +++ b/nq/source/cl_screen.c @@ -86,7 +86,9 @@ SCR_CShift (void) int contents = CONTENTS_EMPTY; if (cls.state == ca_active && cl.worldmodel) { - leaf = Mod_PointInLeaf (r_data->refdef->vieworg, cl.worldmodel); + //FIXME + leaf = Mod_PointInLeaf (&r_data->refdef->viewposition[0], + cl.worldmodel); contents = leaf->contents; } V_SetContentsColor (contents); diff --git a/nq/source/cl_view.c b/nq/source/cl_view.c index 1ccf06d98..f5ba3de8f 100644 --- a/nq/source/cl_view.c +++ b/nq/source/cl_view.c @@ -30,6 +30,7 @@ #include "QF/cmd.h" #include "QF/cvar.h" +#include "QF/entity.h" #include "QF/msg.h" #include "QF/screen.h" @@ -39,8 +40,6 @@ #include "compat.h" -#include "client/view.h" - #include "nq/include/chase.h" #include "nq/include/client.h" #include "nq/include/host.h" @@ -81,6 +80,10 @@ cvar_t *v_idlescale; float v_dmg_time, v_dmg_roll, v_dmg_pitch; +vec4f_t v_idle_yaw; +vec4f_t v_idle_roll; +vec4f_t v_idle_pitch; + cshift_t cshift_empty = { {130, 80, 50}, 0}; cshift_t cshift_water = { {130, 80, 50}, 128}; cshift_t cshift_slime = { {0, 25, 5}, 150}; @@ -113,7 +116,7 @@ V_CalcRoll (const vec3_t angles, vec4f_t velocity) static float V_CalcBob (void) { - vec4f_t velocity = cl.velocity; + vec4f_t velocity = cl.viewstate.velocity; float cycle; static double bobtime; static float bob; @@ -124,7 +127,7 @@ V_CalcBob (void) if (cl.onground == -1) return bob; // just use old value - bobtime += host_frametime; + bobtime += cl.viewstate.frametime; cycle = bobtime - (int) (bobtime / cl_bobcycle->value) * cl_bobcycle->value; cycle /= cl_bobcycle->value; @@ -183,9 +186,9 @@ static void V_DriftPitch (void) { float delta, move; - usercmd_t *cmd = &cl.cmd; + float forwardmove = cl.viewstate.movecmd[0]; - if (noclip_anglehack || cl.onground == -1 || cls.demoplayback) { + if (noclip_anglehack || cl.viewstate.onground == -1 || cls.demoplayback) { cl.driftmove = 0; cl.pitchvel = 0; return; @@ -193,10 +196,10 @@ V_DriftPitch (void) // don't count small mouse motion if (cl.nodrift) { - if (fabs (cmd->forwardmove) < cl_forwardspeed->value) + if (fabs (forwardmove) < cl_forwardspeed->value) cl.driftmove = 0; else - cl.driftmove += host_frametime; + cl.driftmove += cl.viewstate.frametime; if (cl.driftmove > v_centermove->value) { V_StartPitchDrift (); @@ -204,28 +207,28 @@ V_DriftPitch (void) return; } - delta = cl.idealpitch - cl.viewangles[PITCH]; + delta = cl.idealpitch - cl.viewstate.angles[PITCH]; if (!delta) { cl.pitchvel = 0; return; } - move = host_frametime * cl.pitchvel; - cl.pitchvel += host_frametime * v_centerspeed->value; + move = cl.viewstate.frametime * cl.pitchvel; + cl.pitchvel += cl.viewstate.frametime * v_centerspeed->value; if (delta > 0) { if (move > delta) { cl.pitchvel = 0; move = delta; } - cl.viewangles[PITCH] += move; + cl.viewstate.angles[PITCH] += move; } else if (delta < 0) { if (move > -delta) { cl.pitchvel = 0; move = -delta; } - cl.viewangles[PITCH] -= move; + cl.viewstate.angles[PITCH] -= move; } } @@ -234,11 +237,10 @@ V_DriftPitch (void) void V_ParseDamage (void) { - entity_t *ent = &cl_entities[cl.viewentity]; float count, side; int armor, blood; - vec_t *origin = ent->origin; - vec_t *angles = ent->angles; + vec4f_t origin = cl.viewstate.origin; + vec_t *angles = cl.viewstate.angles; vec3_t from, forward, right, up; armor = MSG_ReadByte (net_message); @@ -482,74 +484,41 @@ V_PrepBlend (void) /* VIEW RENDERING */ -static float -angledelta (float a) -{ - a = anglemod (a); - if (a > 180) - a -= 360; - return a; -} - static void CalcGunAngle (void) { - float yaw, pitch, move; - static float oldpitch = 0, oldyaw = 0; - - yaw = r_data->refdef->viewangles[YAW]; - pitch = -r_data->refdef->viewangles[PITCH]; - - yaw = angledelta (yaw - r_data->refdef->viewangles[YAW]) * 0.4; - yaw = bound (-10, yaw, 10); - pitch = angledelta (-pitch - r_data->refdef->viewangles[PITCH]) * 0.4; - pitch = bound (-10, pitch, 10); - - move = host_frametime * 20; - if (yaw > oldyaw) { - if (oldyaw + move < yaw) - yaw = oldyaw + move; - } else { - if (oldyaw - move > yaw) - yaw = oldyaw - move; - } - - if (pitch > oldpitch) { - if (oldpitch + move < pitch) - pitch = oldpitch + move; - } else { - if (oldpitch - move > pitch) - pitch = oldpitch - move; - } - - oldyaw = yaw; - oldpitch = pitch; - - cl.viewent.angles[YAW] = r_data->refdef->viewangles[YAW] + yaw; - cl.viewent.angles[PITCH] = -(r_data->refdef->viewangles[PITCH] + pitch); + vec4f_t rotation = r_data->refdef->viewrotation; + //FIXME make child of camera + Transform_SetWorldRotation (cl.viewent.transform, rotation); } static void V_BoundOffsets (void) { - entity_t *ent = &cl_entities[cl.viewentity]; - vec_t *origin = ent->origin; + vec4f_t offset = r_data->refdef->viewposition + - cl.viewstate.origin; // absolutely bound refresh reletive to entity clipping hull // so the view can never be inside a solid wall - if (r_data->refdef->vieworg[0] < origin[0] - 14) - r_data->refdef->vieworg[0] = origin[0] - 14; - else if (r_data->refdef->vieworg[0] > origin[0] + 14) - r_data->refdef->vieworg[0] = origin[0] + 14; - if (r_data->refdef->vieworg[1] < origin[1] - 14) - r_data->refdef->vieworg[1] = origin[1] - 14; - else if (r_data->refdef->vieworg[1] > origin[1] + 14) - r_data->refdef->vieworg[1] = origin[1] + 14; - if (r_data->refdef->vieworg[2] < origin[2] - 22) - r_data->refdef->vieworg[2] = origin[2] - 22; - else if (r_data->refdef->vieworg[2] > origin[2] + 30) - r_data->refdef->vieworg[2] = origin[2] + 30; + offset[0] = bound (-14, offset[0], 14); + offset[1] = bound (-14, offset[1], 14); + offset[2] = bound (-22, offset[2], 30); + r_data->refdef->viewposition = cl.viewstate.origin + offset; +} + +static vec4f_t +idle_quat (vec4f_t axis, cvar_t *cycle, cvar_t *level) +{ + vec4f_t identity = { 0, 0, 0, 1 }; + if (!level || !cycle) { + return identity; + } + float scale = sin (cl.time * cycle->value); + float ang = scale * level->value * v_idlescale->value; + float c = cos (ang); + float s = sin (ang); + return axis * s + identity * c; } /* @@ -560,19 +529,21 @@ V_BoundOffsets (void) static void V_AddIdle (void) { - r_data->refdef->viewangles[ROLL] += v_idlescale->value * - sin (cl.time * v_iroll_cycle->value) * v_iroll_level->value; - r_data->refdef->viewangles[PITCH] += v_idlescale->value * - sin (cl.time * v_ipitch_cycle->value) * v_ipitch_level->value; - r_data->refdef->viewangles[YAW] += v_idlescale->value * - sin (cl.time * v_iyaw_cycle->value) * v_iyaw_level->value; + vec4f_t roll = idle_quat ((vec4f_t) { 1, 0, 0, 0}, + v_iroll_cycle, v_iroll_level); + vec4f_t pitch = idle_quat ((vec4f_t) { 0, 1, 0, 0}, + v_ipitch_cycle, v_ipitch_level); + vec4f_t yaw = idle_quat ((vec4f_t) { 0, 0, 1, 0}, + v_iyaw_cycle, v_iyaw_level); + vec4f_t rot = normalf (qmulf (yaw, qmulf (pitch, roll))); - cl.viewent.angles[ROLL] -= v_idlescale->value * - sin (cl.time * v_iroll_cycle->value) * v_iroll_level->value; - cl.viewent.angles[PITCH] -= v_idlescale->value * - sin (cl.time * v_ipitch_cycle->value) * v_ipitch_level->value; - cl.viewent.angles[YAW] -= v_idlescale->value * - sin (cl.time * v_iyaw_cycle->value) * v_iyaw_level->value; + // rotate the view + r_data->refdef->viewrotation = qmulf (rot, r_data->refdef->viewrotation); + + // counter-rotate the weapon + rot = qmulf (qconjf (rot), + Transform_GetWorldRotation (cl.viewent.transform)); + Transform_SetWorldRotation (cl.viewent.transform, rot); } /* @@ -583,40 +554,38 @@ V_AddIdle (void) static void V_CalcViewRoll (void) { - float side; - vec_t *angles = cl_entities[cl.viewentity].angles; - vec4f_t velocity = cl.velocity; + vec_t *angles = cl.viewstate.angles; + vec4f_t velocity = cl.viewstate.velocity; + vec3_t ang = { }; - side = V_CalcRoll (angles, velocity); - r_data->refdef->viewangles[ROLL] += side; + ang[ROLL] = V_CalcRoll (angles, velocity); if (v_dmg_time > 0) { - r_data->refdef->viewangles[ROLL] += - v_dmg_time / v_kicktime->value * v_dmg_roll; - r_data->refdef->viewangles[PITCH] += - v_dmg_time / v_kicktime->value * v_dmg_pitch; - v_dmg_time -= host_frametime; + ang[ROLL] += v_dmg_time / v_kicktime->value * v_dmg_roll; + ang[PITCH] += v_dmg_time / v_kicktime->value * v_dmg_pitch; + v_dmg_time -= cl.viewstate.frametime; } - if (cl.stats[STAT_HEALTH] <= 0) - r_data->refdef->viewangles[ROLL] = 80; // dead view angle + if (cl.viewstate.flags & VF_DEAD) { // VF_GIB will also set VF_DEAD + ang[ROLL] = 80; // dead view angle + } + + vec4f_t rot; + AngleQuat (ang, &rot[0]);//FIXME + r_data->refdef->viewrotation = qmulf (r_data->refdef->viewrotation, rot); } static void V_CalcIntermissionRefdef (void) { - // ent is the player model (visible when out of body) - entity_t *ent = &cl_entities[cl.viewentity]; entity_t *view; float old; - vec_t *origin = ent->origin; - vec_t *angles = ent->angles; // view is the weapon model (visible only from inside body) view = &cl.viewent; - VectorCopy (origin, r_data->refdef->vieworg); - VectorCopy (angles, r_data->refdef->viewangles); + r_data->refdef->viewposition = cl.viewstate.origin; + AngleQuat (cl.viewstate.angles, &r_data->refdef->viewrotation[0]);//FIXME view->renderer.model = NULL; // always idle in intermission @@ -629,109 +598,98 @@ V_CalcIntermissionRefdef (void) static void V_CalcRefdef (void) { - // ent is the player model (visible when out of body) - entity_t *ent = &cl_entities[cl.viewentity]; // view is the weapon model (visible only from inside body) entity_t *view = &cl.viewent; float bob; static float oldz = 0; - int i; - vec3_t forward, right, up; - vec_t *origin = ent->origin; - vec_t *viewangles = cl.viewangles; + vec4f_t forward = {}, right = {}, up = {}; + vec4f_t origin = cl.viewstate.origin; + vec_t *viewangles = cl.viewstate.angles; V_DriftPitch (); bob = V_CalcBob (); // refresh position - VectorCopy (origin, r_data->refdef->vieworg); - r_data->refdef->vieworg[2] += cl.viewheight + bob; + r_data->refdef->viewposition = origin; + r_data->refdef->viewposition[2] += cl.viewheight + bob; // never let it sit exactly on a node line, because a water plane can // disappear when viewed with the eye exactly on it. // server protocol specifies to only 1/8 pixel, so add 1/16 in each axis - r_data->refdef->vieworg[0] += 1.0 / 16; - r_data->refdef->vieworg[1] += 1.0 / 16; - r_data->refdef->vieworg[2] += 1.0 / 16; + r_data->refdef->viewposition += (vec4f_t) { 1.0/16, 1.0/16, 1.0/16, 0}; - VectorCopy (viewangles, r_data->refdef->viewangles); + AngleQuat (cl.viewstate.angles, &r_data->refdef->viewrotation[0]);//FIXME V_CalcViewRoll (); V_AddIdle (); // offsets - AngleVectors (viewangles, forward, right, up); + //FIXME semi-duplicates AngleQuat (also, vec3_t vs vec4f_t) + AngleVectors (viewangles, &forward[0], &right[0], &up[0]); // don't allow cheats in multiplayer // FIXME check for dead if (cl.maxclients == 1) { - for (i = 0; i < 3; i++) { - r_data->refdef->vieworg[i] += scr_ofsx->value * forward[i] + - scr_ofsy->value * right[i] + - scr_ofsz->value * up[i]; - } + r_data->refdef->viewposition += scr_ofsx->value * forward + + scr_ofsy->value * right + + scr_ofsz->value * up; } V_BoundOffsets (); // set up gun position - VectorCopy (viewangles, view->angles); - CalcGunAngle (); - VectorCopy (origin, view->origin); - view->origin[2] += cl.viewheight; - - for (i = 0; i < 3; i++) { - view->origin[i] += forward[i] * bob * 0.4; -// view->origin[i] += right[i] * bob * 0.4; -// view->origin[i] += up[i] * bob * 0.8; - } - view->origin[2] += bob; + origin += (vec4f_t) { 0, 0, cl.viewheight, 0 }; + origin += forward * bob * 0.4f + (vec4f_t) { 0, 0, bob, 0 }; // fudge position around to keep amount of weapon visible // roughly equal with different FOV - if (hud_sbar->int_val == 0 && r_data->scr_viewsize->int_val >= 100) + if (hud_sbar->int_val == 0 && r_data->scr_viewsize->int_val >= 100) { ; - else if (r_data->scr_viewsize->int_val == 110) - view->origin[2] += 1; - else if (r_data->scr_viewsize->int_val == 100) - view->origin[2] += 2; - else if (r_data->scr_viewsize->int_val == 90) - view->origin[2] += 1; - else if (r_data->scr_viewsize->int_val == 80) - view->origin[2] += 0.5; + } else if (r_data->scr_viewsize->int_val == 110) { + origin += (vec4f_t) { 0, 0, 1, 0}; + } else if (r_data->scr_viewsize->int_val == 100) { + origin += (vec4f_t) { 0, 0, 2, 0}; + } else if (r_data->scr_viewsize->int_val == 90) { + origin += (vec4f_t) { 0, 0, 1, 0}; + } else if (r_data->scr_viewsize->int_val == 80) { + origin += (vec4f_t) { 0, 0, 0.5, 0}; + } view->renderer.model = cl.model_precache[cl.stats[STAT_WEAPON]]; view->animation.frame = cl.stats[STAT_WEAPONFRAME]; view->renderer.skin = 0; // set up the refresh position - VectorAdd (r_data->refdef->viewangles, cl.punchangle, - r_data->refdef->viewangles); + r_data->refdef->viewrotation = qmulf (cl.viewstate.punchangle, + r_data->refdef->viewrotation); // smooth out stair step ups if ((cl.onground != -1) && (origin[2] - oldz > 0)) { float steptime; - steptime = cl.time - cl.oldtime; - if (steptime < 0) - steptime = 0; + steptime = cl.viewstate.frametime; oldz += steptime * 80; if (oldz > origin[2]) oldz = origin[2]; if (origin[2] - oldz > 12) oldz = origin[2] - 12; - r_data->refdef->vieworg[2] += oldz - origin[2]; - view->origin[2] += oldz - origin[2]; - } else + r_data->refdef->viewposition[2] += oldz - origin[2]; + origin[2] += oldz - origin[2]; + } else { oldz = origin[2]; + } + { + // FIXME sort out the alias model specific negation + vec3_t ang = {-viewangles[0], viewangles[1], viewangles[2]}; + CL_TransformEntity (view, 1, ang, origin); + } - if (cl.chase && chase_active->int_val) + if (cl.chase && chase_active->int_val) { Chase_Update (); - - CL_TransformEntity (view, view->angles); + } } /* @@ -743,8 +701,11 @@ V_CalcRefdef (void) void V_RenderView (void) { - if (cls.state != ca_active) + if (cls.state != ca_active) { + r_data->refdef->viewposition = (vec4f_t) { 0, 0, 0, 1 }; + r_data->refdef->viewrotation = (vec4f_t) { 0, 0, 0, 1 }; return; + } if (cl.intermission) { // intermission / finale rendering V_CalcIntermissionRefdef (); diff --git a/qw/include/client.h b/qw/include/client.h index 5389579c4..8c0369fba 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -37,6 +37,7 @@ #include "QF/plugin/vid_render.h" #include "client/entities.h" +#include "client/view.h" #include "netchan.h" #include "qw/bothdefs.h" @@ -222,12 +223,7 @@ typedef struct { // the client simulates or interpolates movement to get these values double time; // this is the time value that the client // is rendering at. always <= realtime - vec4f_t simorg; - vec4f_t simvel; - vec3_t simangles; - - vec3_t punchangle; // temporary view kick from weapon firing - + viewstate_t viewstate; // pitch drifting vars float idealpitch; float pitchvel; @@ -342,7 +338,9 @@ extern struct cvar_s *cl_fb_players; extern client_state_t cl; -extern entityset_t cl_static_entities; +typedef struct entitystateset_s DARRAY_TYPE (struct entity_state_s) + entitystateset_t; +extern entitystateset_t cl_static_entities; extern entity_t cl_entities[512]; extern byte cl_entity_valid[2][512]; diff --git a/qw/source/cl_chase.c b/qw/source/cl_chase.c index 8a3d6419d..68c9e207a 100644 --- a/qw/source/cl_chase.c +++ b/qw/source/cl_chase.c @@ -41,16 +41,19 @@ #include "QF/mathlib.h" #include "QF/plugin/vid_render.h" +#include "QF/simd/vec4f.h" #include "qw/include/chase.h" #include "qw/include/cl_input.h" #include "qw/include/client.h" #include "world.h" -vec3_t camera_origin = {0,0,0}; -vec3_t camera_angles = {0,0,0}; -vec3_t player_origin = {0,0,0}; -vec3_t player_angles = {0,0,0}; + +vec4f_t camera_origin = {0,0,0,1}; +vec4f_t player_origin = {0,0,0,1}; +vec4f_t player_angles = {0,0,0,1}; + +vec3_t camera_angles = {0,0,0}; vec3_t chase_angles; vec3_t chase_dest; @@ -94,19 +97,17 @@ TraceLine (vec3_t start, vec3_t end, vec3_t impact) void Chase_Update (void) { - float pitch, yaw, fwd; - int i; - usercmd_t cmd; // movement direction - vec3_t forward, up, right, stop, dir; + float pitch, yaw, fwd; + usercmd_t cmd; // movement direction + vec4f_t forward = {}, up = {}, right = {}, stop = {}, dir = {}; // lazy camera, look toward player entity if (chase_active->int_val == 2 || chase_active->int_val == 3) { // control camera angles with key/mouse/joy-look - - camera_angles[PITCH] += cl.viewangles[PITCH] - player_angles[PITCH]; - camera_angles[YAW] += cl.viewangles[YAW] - player_angles[YAW]; - camera_angles[ROLL] += cl.viewangles[ROLL] - player_angles[ROLL]; + vec3_t d; + VectorSubtract (cl.viewstate.angles, player_angles, d); + VectorAdd (camera_angles, d, camera_angles); if (chase_active->int_val == 2) { if (camera_angles[PITCH] < -60) @@ -118,48 +119,48 @@ Chase_Update (void) // move camera, it's not enough to just change the angles because // the angles are automatically changed to look toward the player - if (chase_active->int_val == 3) - VectorCopy (r_data->refdef->vieworg, player_origin); + if (chase_active->int_val == 3) { + player_origin = r_data->refdef->viewposition; + } - AngleVectors (camera_angles, forward, right, up); - VectorScale (forward, chase_back->value, forward); - VectorSubtract (player_origin, forward, camera_origin); + AngleVectors (camera_angles, &forward[0], &right[0], &up[0]); + camera_origin = player_origin - chase_back->value * forward; if (chase_active->int_val == 2) { - VectorCopy (r_data->refdef->vieworg, player_origin); + player_origin = r_data->refdef->viewposition; // don't let camera get too low - if (camera_origin[2] < player_origin[2] + chase_up->value) + if (camera_origin[2] < player_origin[2] + chase_up->value) { camera_origin[2] = player_origin[2] + chase_up->value; + } } // don't let camera get too far from player - VectorSubtract (camera_origin, player_origin, dir); - VectorCopy (dir, forward); - VectorNormalize (forward); + dir = camera_origin - player_origin; + forward = normalf (dir); - if (VectorLength (dir) > chase_back->value) { - VectorScale (forward, chase_back->value, dir); - VectorAdd (player_origin, dir, camera_origin); + if (magnitudef (dir)[0] > chase_back->value) { + camera_origin = player_origin + forward * chase_back->value; } // check for walls between player and camera - VectorScale (forward, 8, forward); - VectorAdd (camera_origin, forward, camera_origin); - TraceLine (player_origin, camera_origin, stop); - if (VectorLength (stop) != 0) - VectorSubtract (stop, forward, camera_origin); + camera_origin += 8 * forward; + //FIXME + TraceLine (&player_origin[0], &camera_origin[0], &stop[0]); + stop[3] = 1; + if (magnitude3f (stop)[0] != 0) { + camera_origin = stop - forward; + } - VectorSubtract (camera_origin, r_data->refdef->vieworg, dir); - VectorCopy (dir, forward); - VectorNormalize (forward); + dir = camera_origin - r_data->refdef->viewposition; + forward = normalf (dir); if (chase_active->int_val == 2) { if (dir[1] == 0 && dir[0] == 0) { // look straight up or down -// camera_angles[YAW] = r_data->refdef->viewangles[YAW]; +// camera_angles[YAW] = r_data->refdef->viewstate.angles[YAW]; if (dir[2] > 0) camera_angles[PITCH] = 90; else @@ -182,13 +183,13 @@ Chase_Update (void) } } - VectorCopy (camera_angles, r_data->refdef->viewangles);// rotate camera - VectorCopy (camera_origin, r_data->refdef->vieworg); // move camera + AngleQuat (camera_angles, &r_data->refdef->viewrotation[0]);//FIXME rotate camera + r_data->refdef->viewposition = camera_origin; // move camera // get basic movement from keyboard memset (&cmd, 0, sizeof (cmd)); -// VectorCopy (cl.viewangles, cmd.angles); +// VectorCopy (cl.viewstate.angles, cmd.angles); if (in_strafe.state & 1) { cmd.sidemove += cl_sidespeed->value * CL_KeyState (&in_right); @@ -208,54 +209,54 @@ Chase_Update (void) } // mouse and joystick controllers add to movement - VectorSet (0, cl.viewangles[1] - camera_angles[1], 0, dir); - AngleVectors (dir, forward, right, up); - VectorScale (forward, viewdelta.position[2] * m_forward->value, - forward); - VectorScale (right, viewdelta.position[0] * m_side->value, right); - VectorAdd (forward, right, dir); + VectorSet (0, cl.viewstate.angles[1] - camera_angles[1], 0, dir); + AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME + forward *= viewdelta.position[2] * m_forward->value; + right *= viewdelta.position[0] * m_side->value; + dir = forward + right; cmd.forwardmove += dir[0]; cmd.sidemove -= dir[1]; VectorSet (0, camera_angles[1], 0, dir); - AngleVectors (dir, forward, right, up); + AngleVectors (&dir[0], &forward[0], &right[0], &up[0]); //FIXME VectorScale (forward, cmd.forwardmove, forward); VectorScale (right, cmd.sidemove, right); VectorAdd (forward, right, dir); if (dir[1] || dir[0]) { - cl.viewangles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI); - if (cl.viewangles[YAW] < 0) cl.viewangles[YAW] += 360; -// if (cl.viewangles[YAW] < 180) -// cl.viewangles[YAW] += 180; -// else -// cl.viewangles[YAW] -= 180; + cl.viewstate.angles[YAW] = (atan2 (dir[1], dir[0]) * 180 / M_PI); + if (cl.viewstate.angles[YAW] < 0) { + cl.viewstate.angles[YAW] += 360; + } } - cl.viewangles[PITCH] = 0; + cl.viewstate.angles[PITCH] = 0; // remember the new angle to calculate the difference next frame - VectorCopy (cl.viewangles, player_angles); + VectorCopy (cl.viewstate.angles, player_angles); return; } // regular camera, faces same direction as player - AngleVectors (cl.viewangles, forward, right, up); + //FIXME + AngleVectors (cl.viewstate.angles, &forward[0], &right[0], &up[0]); // calc exact destination - for (i = 0; i < 3; i++) - camera_origin[i] = r_data->refdef->vieworg[i] - - forward[i] * chase_back->value - right[i] * chase_right->value; + camera_origin = r_data->refdef->viewposition + - forward * chase_back->value - right * chase_right->value; + // chase_up is world up camera_origin[2] += chase_up->value; // check for walls between player and camera - TraceLine (r_data->refdef->vieworg, camera_origin, stop); - if (VectorLength (stop) != 0) - for (i = 0; i < 3; i++) - camera_origin[i] = stop[i] + forward[i] * 8; + //FIXME + TraceLine (&r_data->refdef->viewposition[0], &camera_origin[0], &stop[0]); + stop[3] = 1; + if (magnitude3f (stop)[0] != 0) { + camera_origin = stop + forward * 8; + } - VectorCopy (camera_origin, r_data->refdef->vieworg); + r_data->refdef->viewposition = camera_origin; } diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 0694b5f25..7503f5c2a 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -652,9 +652,8 @@ demo_start_recording (int track) { byte buf_data[MAX_MSGLEN + 10]; // + 10 for header char *s; - int n, i, j; + int n, i; int seq = 1; - entity_t *ent; entity_state_t *es, blankes; player_info_t *player; sizebuf_t buf; @@ -757,23 +756,16 @@ demo_start_recording (int track) // spawnstatic for (size_t staticIndex = 0; staticIndex < cl_static_entities.size; staticIndex++) { - ent = cl_static_entities.a[staticIndex]; + entity_state_t *es = &cl_static_entities.a[staticIndex]; + MSG_WriteByte (&buf, svc_spawnstatic); - for (j = 1; j < cl.nummodels; j++) { - if (ent->renderer.model == cl.model_precache[j]) { - break; - } - } - if (j == cl.nummodels) - MSG_WriteByte (&buf, 0); - else - MSG_WriteByte (&buf, j); + MSG_WriteByte (&buf, es->modelindex); - MSG_WriteByte (&buf, ent->animation.frame); + MSG_WriteByte (&buf, es->frame); MSG_WriteByte (&buf, 0); - MSG_WriteByte (&buf, ent->renderer.skinnum); - MSG_WriteCoordAngleV (&buf, ent->origin, ent->angles); + MSG_WriteByte (&buf, es->skinnum); + MSG_WriteCoordAngleV (&buf, &es->origin[0], &es->angles[0]); if (buf.cursize > MAX_MSGLEN / 2) { CL_WriteRecordDemoMessage (&buf, seq++); diff --git a/qw/source/cl_entparse.c b/qw/source/cl_entparse.c index 60c8cf2c4..7100d2726 100644 --- a/qw/source/cl_entparse.c +++ b/qw/source/cl_entparse.c @@ -130,6 +130,8 @@ CL_ParseDelta (entity_state_t *from, entity_state_t *to, int bits) if (bits & U_ANGLE3) to->angles[2] = MSG_ReadAngle (net_message); + to->origin[3] = 1; + if (bits & U_SOLID) { // FIXME } @@ -428,6 +430,7 @@ CL_ParsePlayerinfo (void) state->messagenum = cl.parsecount; MSG_ReadCoordV (net_message, &state->pls.es.origin[0]);//FIXME + state->pls.es.origin[3] = 1; state->pls.es.frame = MSG_ReadByte (net_message); @@ -486,7 +489,7 @@ CL_ParsePlayerinfo (void) } if (bits & PF_SCALE) { val = MSG_ReadByte (net_message); - ent->scale = val / 16.0; + state->pls.es.scale = val; } if (bits & PF_EFFECTS2) { state->pls.es.effects |= MSG_ReadByte (net_message) << 8; diff --git a/qw/source/cl_ents.c b/qw/source/cl_ents.c index b70b143cc..8ee9440b4 100644 --- a/qw/source/cl_ents.c +++ b/qw/source/cl_ents.c @@ -132,7 +132,6 @@ CL_LinkPacketEntities (void) entity_state_t *new, *old; renderer_t *renderer; animation_t *animation; - vec3_t delta; frac = 1; for (i = 0; i < 512; i++) { @@ -195,7 +194,6 @@ CL_LinkPacketEntities (void) 0); } } - ent->scale = new->scale / 16.0; VectorCopy (ent_colormod[new->colormod], renderer->colormod); renderer->colormod[3] = new->alpha / 255.0; @@ -209,35 +207,31 @@ CL_LinkPacketEntities (void) } } + ent->old_origin = Transform_GetWorldPosition (ent->transform); if (forcelink) { animation->pose1 = animation->pose2 = -1; - VectorCopy (new->origin, ent->origin); - if (!(renderer->model->flags & EF_ROTATE)) - CL_TransformEntity (ent, new->angles); + CL_TransformEntity (ent, new->scale / 16, new->angles, + new->origin); if (i != cl.viewentity || chase_active->int_val) { if (ent->visibility.efrag) { r_funcs->R_RemoveEfrags (ent); } r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } - VectorCopy (ent->origin, ent->old_origin); } else { + vec4f_t delta = new->origin - old->origin; f = frac; - VectorCopy (ent->origin, ent->old_origin); - VectorSubtract (new->origin, old->origin, delta); // If the delta is large, assume a teleport and don't lerp if (fabs (delta[0]) > 100 || fabs (delta[1] > 100) || fabs (delta[2]) > 100) { // assume a teleportation, not a motion - VectorCopy (new->origin, ent->origin); - if (!(renderer->model->flags & EF_ROTATE)) { - CL_TransformEntity (ent, new->angles); - } + CL_TransformEntity (ent, new->scale / 16, new->angles, + new->origin); animation->pose1 = animation->pose2 = -1; } else { vec3_t angles, d; + vec4f_t origin = old->origin + f * delta; // interpolate the origin and angles - VectorMultAdd (old->origin, f, delta, ent->origin); if (!(renderer->model->flags & EF_ROTATE)) { VectorSubtract (new->angles, old->angles, d); for (j = 0; j < 3; j++) { @@ -247,12 +241,14 @@ CL_LinkPacketEntities (void) d[j] += 360; } VectorMultAdd (old->angles, f, d, angles); - CL_TransformEntity (ent, angles); } + CL_TransformEntity (ent, new->scale / 16.0, angles, origin); } if (i != cl.viewentity || chase_active->int_val) { if (ent->visibility.efrag) { - if (!VectorCompare (ent->origin, ent->old_origin)) { + vec4f_t org + = Transform_GetWorldPosition (ent->transform); + if (!VectorCompare (org, ent->old_origin)) {//FIXME r_funcs->R_RemoveEfrags (ent); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } @@ -271,12 +267,13 @@ CL_LinkPacketEntities (void) angles[PITCH] = 0; angles[YAW] = anglemod (100 * cl.time); angles[ROLL] = 0; - CL_TransformEntity (ent, angles); + CL_TransformEntity (ent, new->scale / 16.0, angles, new->origin); } //CL_EntityEffects (i, ent, new); //CL_NewDlight (i, ent->origin, new->effects, 0, 0, cl.time); - if (VectorDistance_fast (old->origin, ent->origin) > (256 * 256)) - VectorCopy (ent->origin, old->origin); + vec4f_t org = Transform_GetWorldPosition (ent->transform); + if (VectorDistance_fast (old->origin, org) > (256 * 256)) + old->origin = org; if (renderer->model->flags & ~EF_ROTATE) { CL_ModelEffects (ent, -new->number, new->glow_color, cl.time); } @@ -378,7 +375,7 @@ CL_LinkPlayers (void) // spawn light flashes, even ones coming from invisible objects if (j == cl.playernum) { - org = cl.simorg; + org = cl.viewstate.origin; r_data->player_entity = &cl_player_ents[j]; clientplayer = true; } else { @@ -413,15 +410,16 @@ CL_LinkPlayers (void) // predict only half the move to minimize overruns msec = 500 * (playertime - state->state_time); if (msec <= 0 || (!cl_predict_players->int_val) || cls.demoplayback2) { - VectorCopy (state->pls.es.origin, ent->origin); + Sys_Printf("a\n"); + exact.pls.es.origin = state->pls.es.origin; } else { // predict players movement state->pls.cmd.msec = msec = min (msec, 255); oldphysent = pmove.numphysent; CL_SetSolidPlayers (j); + exact.pls.es.origin[3] = 1;//FIXME should be done by prediction CL_PredictUsercmd (state, &exact, &state->pls.cmd, clientplayer); pmove.numphysent = oldphysent; - VectorCopy (exact.pls.es.origin, ent->origin); } // angles @@ -439,7 +437,8 @@ CL_LinkPlayers (void) ent->animation.frame = state->pls.es.frame; ent->renderer.skinnum = state->pls.es.skinnum; - CL_TransformEntity (ent, ang); + //FIXME scale + CL_TransformEntity (ent, 1, ang, exact.pls.es.origin); ent->renderer.min_light = 0; ent->renderer.fullbright = 0; @@ -484,14 +483,14 @@ CL_EmitEntities (void) return; TEntContext_t tentCtx = { - {VectorExpand (cl.simorg), 1}, cl.worldmodel, cl.viewentity + cl.viewstate.origin, cl.worldmodel, cl.viewentity }; CL_LinkPlayers (); CL_LinkPacketEntities (); CL_UpdateTEnts (cl.time, &tentCtx); if (cl_draw_locs->int_val) { - locs_draw (cl.simorg); + locs_draw (cl.viewstate.origin); } } diff --git a/qw/source/cl_input.c b/qw/source/cl_input.c index 5a2fe2b6e..9b9763d46 100644 --- a/qw/source/cl_input.c +++ b/qw/source/cl_input.c @@ -530,6 +530,7 @@ CL_BaseMove (usercmd_t *cmd) IN_Move (); // adjust for chase camera angles + /*FIXME:chase figure out just what this does and get it working if (cl.chase && (chase_active->int_val == 2 || chase_active->int_val == 3)) { vec3_t forward, right, up, f, r; @@ -546,6 +547,7 @@ CL_BaseMove (usercmd_t *cmd) viewdelta.position[2] = f[0] + r[0]; viewdelta.position[0] = (f[1] + r[1]) * -1; } + */ cmd->forwardmove += viewdelta.position[2] * m_forward->value; cmd->sidemove += viewdelta.position[0] * m_side->value; diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index be73db0e7..cef24d6bd 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -1605,6 +1605,8 @@ Host_Frame (float time) oldrealtime = realtime; host_frametime = min (host_frametime, 0.2); + cl.viewstate.frametime = host_frametime; + con_frametime = con_realtime - oldcon_realtime; oldcon_realtime = con_realtime; diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index b75355fa1..b53c2beb9 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -170,7 +170,7 @@ int packet_latency[NET_TIMINGS]; extern cvar_t *hud_scoreboard_uid; -entityset_t cl_static_entities = DARRAY_STATIC_INIT (32); +entitystateset_t cl_static_entities = DARRAY_STATIC_INIT (32); static void CL_LoadSky (void) @@ -973,15 +973,14 @@ CL_ParseStatic (void) ent = r_funcs->R_AllocEntity (); CL_Init_Entity (ent); - DARRAY_APPEND (&cl_static_entities, ent); + DARRAY_APPEND (&cl_static_entities, es); // copy it to the current state ent->renderer.model = cl.model_precache[es.modelindex]; ent->animation.frame = es.frame; ent->renderer.skinnum = es.skinnum; - VectorCopy (es.origin, ent->origin); - CL_TransformEntity (ent, es.angles); + CL_TransformEntity (ent, es.scale / 16.0, es.angles, es.origin); r_funcs->R_AddEfrags (&cl.worldmodel->brush, ent); } @@ -1296,7 +1295,7 @@ CL_ParseServerMessage (void) const char *str; static dstring_t *stuffbuf; TEntContext_t tentCtx = { - {VectorExpand (cl.simorg), 1}, cl.worldmodel, cl.viewentity + cl.viewstate.origin, cl.worldmodel, cl.viewentity }; received_framecount = host_framecount; @@ -1542,17 +1541,17 @@ CL_ParseServerMessage (void) cl.completed_time = realtime; r_data->vid->recalc_refdef = true; // go to full screen Sys_MaskPrintf (SYS_DEV, "intermission simorg: "); - MSG_ReadCoordV (net_message, &cl.simorg[0]);//FIXME - cl.simorg[3] = 1; - for (i = 0; i < 3; i++) - Sys_MaskPrintf (SYS_DEV, "%f ", cl.simorg[i]); + MSG_ReadCoordV (net_message, &cl.viewstate.origin[0]);//FIXME + cl.viewstate.origin[3] = 1; + Sys_MaskPrintf (SYS_DEV, VEC4F_FMT, + VEC4_EXP (cl.viewstate.origin)); Sys_MaskPrintf (SYS_DEV, "\nintermission simangles: "); - MSG_ReadAngleV (net_message, cl.simangles); - cl.simangles[ROLL] = 0; // FIXME @@@ - for (i = 0; i < 3; i++) - Sys_MaskPrintf (SYS_DEV, "%f ", cl.simangles[i]); + MSG_ReadAngleV (net_message, cl.viewstate.angles); + cl.viewstate.angles[ROLL] = 0; // FIXME @@@ + Sys_MaskPrintf (SYS_DEV, "%f %f %f", + VectorExpand (cl.viewstate.angles)); Sys_MaskPrintf (SYS_DEV, "\n"); - VectorZero (cl.simvel); + cl.viewstate.velocity = (vec4f_t) { }; // automatic fraglogging (by elmex) // XXX: Should this _really_ called here? @@ -1585,11 +1584,17 @@ CL_ParseServerMessage (void) // svc_cutscene (same value as svc_smallkick) case svc_smallkick: - cl.punchangle[PITCH] = -2; + cl.viewstate.punchangle = (vec4f_t) { + // -2 degrees pitch + 0, -0.0174524064, 0, 0.999847695 + }; break; case svc_bigkick: - cl.punchangle[PITCH] = -4; + cl.viewstate.punchangle = (vec4f_t) { + // -4 degrees pitch + 0, -0.0348994967, 0, 0.999390827 + }; break; case svc_updateping: diff --git a/qw/source/cl_pred.c b/qw/source/cl_pred.c index f48533673..5bf79a163 100644 --- a/qw/source/cl_pred.c +++ b/qw/source/cl_pred.c @@ -47,7 +47,7 @@ cvar_t *cl_pushlatency; void -CL_PredictUsercmd (player_state_t * from, player_state_t * to, usercmd_t *u, +CL_PredictUsercmd (player_state_t *from, player_state_t *to, usercmd_t *u, qboolean clientplayer) { if (!clientplayer) { @@ -105,6 +105,8 @@ CL_PredictMove (void) float f; int oldphysent, i; frame_t *from, *to = NULL; + entity_state_t *fromes; + entity_state_t *toes; if (cl_pushlatency->value > 0) Cvar_Set (cl_pushlatency, "0"); @@ -130,15 +132,16 @@ CL_PredictMove (void) UPDATE_BACKUP - 1) return; - VectorCopy (cl.viewangles, cl.simangles); - cl.simangles[ROLL] = 0; // FIXME @@@ + VectorCopy (cl.viewangles, cl.viewstate.angles); + cl.viewstate.angles[ROLL] = 0; // FIXME @@@ // this is the last frame received from the server from = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK]; + fromes = &from->playerstate[cl.playernum].pls.es; if (!cl_predict->int_val) { - VectorCopy (from->playerstate[cl.playernum].pls.es.velocity, cl.simvel); - VectorCopy (from->playerstate[cl.playernum].pls.es.origin, cl.simorg); + cl.viewstate.velocity = fromes->velocity; + cl.viewstate.origin = fromes->origin; return; } @@ -165,6 +168,7 @@ CL_PredictMove (void) if (i == UPDATE_BACKUP - 1 || !to) return; // net hasn't deliver packets in a // long time... + toes = &to->playerstate[cl.playernum].pls.es; // now interpolate some fraction of the final frame if (to->senttime == from->senttime) @@ -175,18 +179,14 @@ CL_PredictMove (void) } for (i = 0; i < 3; i++) - if (fabs (from->playerstate[cl.playernum].pls.es.origin[i] - - to->playerstate[cl.playernum].pls.es.origin[i]) > 128) { + if (fabs (fromes->origin[i] - toes->origin[i]) > 128) { // teleported, so don't lerp - VectorCopy (to->playerstate[cl.playernum].pls.es.velocity, - cl.simvel); - VectorCopy (to->playerstate[cl.playernum].pls.es.origin, cl.simorg); + cl.viewstate.velocity = toes->velocity; + cl.viewstate.origin = toes->origin; return; } - cl.simorg = from->playerstate[cl.playernum].pls.es.origin - + f * (to->playerstate[cl.playernum].pls.es.origin - - from->playerstate[cl.playernum].pls.es.origin); + cl.viewstate.origin = fromes->origin + f * (toes->origin - fromes->origin); } void diff --git a/qw/source/cl_screen.c b/qw/source/cl_screen.c index 22c8b5b96..12cfb8441 100644 --- a/qw/source/cl_screen.c +++ b/qw/source/cl_screen.c @@ -87,7 +87,9 @@ SCR_CShift (void) int contents = CONTENTS_EMPTY; if (cls.state == ca_active && cl.worldmodel) { - leaf = Mod_PointInLeaf (r_data->refdef->vieworg, cl.worldmodel); + //FIXME + leaf = Mod_PointInLeaf (&r_data->refdef->viewposition[0], + cl.worldmodel); contents = leaf->contents; } V_SetContentsColor (contents); diff --git a/qw/source/cl_view.c b/qw/source/cl_view.c index f20d5747a..0e9162ca8 100644 --- a/qw/source/cl_view.c +++ b/qw/source/cl_view.c @@ -37,8 +37,6 @@ #include "compat.h" -#include "client/view.h" - #include "qw/bothdefs.h" #include "qw/include/chase.h" @@ -84,8 +82,9 @@ cvar_t *v_idlescale; float v_dmg_time, v_dmg_roll, v_dmg_pitch; -frame_t *view_frame; -player_state_t *view_state; +vec4f_t v_idle_yaw; +vec4f_t v_idle_roll; +vec4f_t v_idle_pitch; cshift_t cshift_empty = { {130, 80, 50}, 0}; cshift_t cshift_water = { {130, 80, 50}, 128}; @@ -119,7 +118,7 @@ V_CalcRoll (const vec3_t angles, vec4f_t velocity) static float V_CalcBob (void) { - vec4f_t velocity = cl.simvel; + vec4f_t velocity = cl.viewstate.velocity; float cycle; static double bobtime; static float bob; @@ -130,7 +129,7 @@ V_CalcBob (void) if (cl.onground == -1) return bob; // just use old value - bobtime += host_frametime; + bobtime += cl.viewstate.frametime; cycle = bobtime - (int) (bobtime / cl_bobcycle->value) * cl_bobcycle->value; cycle /= cl_bobcycle->value; @@ -189,10 +188,9 @@ static void V_DriftPitch (void) { float delta, move; - int frameno = (cls.netchan.outgoing_sequence - 1) & UPDATE_MASK; - usercmd_t *cmd = &cl.frames[frameno].cmd; + float forwardmove = cl.viewstate.movecmd[0]; - if (view_state->onground == -1 || cls.demoplayback) { + if (noclip_anglehack || cl.viewstate.onground == -1 || cls.demoplayback) { cl.driftmove = 0; cl.pitchvel = 0; return; @@ -200,10 +198,10 @@ V_DriftPitch (void) // don't count small mouse motion if (cl.nodrift) { - if (fabs (cmd->forwardmove) < cl_forwardspeed->value) + if (fabs (forwardmove) < cl_forwardspeed->value) cl.driftmove = 0; else - cl.driftmove += host_frametime; + cl.driftmove += cl.viewstate.frametime; if (cl.driftmove > v_centermove->value) { V_StartPitchDrift (); @@ -211,28 +209,28 @@ V_DriftPitch (void) return; } - delta = cl.idealpitch - cl.viewangles[PITCH]; + delta = cl.idealpitch - cl.viewstate.angles[PITCH]; if (!delta) { cl.pitchvel = 0; return; } - move = host_frametime * cl.pitchvel; - cl.pitchvel += host_frametime * v_centerspeed->value; + move = cl.viewstate.frametime * cl.pitchvel; + cl.pitchvel += cl.viewstate.frametime * v_centerspeed->value; if (delta > 0) { if (move > delta) { cl.pitchvel = 0; move = delta; } - cl.viewangles[PITCH] += move; + cl.viewstate.angles[PITCH] += move; } else if (delta < 0) { if (move > -delta) { cl.pitchvel = 0; move = -delta; } - cl.viewangles[PITCH] -= move; + cl.viewstate.angles[PITCH] -= move; } } @@ -243,8 +241,8 @@ V_ParseDamage (void) { float count, side; int armor, blood; - vec4f_t origin = cl.simorg; - vec_t *angles = cl.simangles; + vec4f_t origin = cl.viewstate.origin; + vec_t *angles = cl.viewstate.angles; vec3_t from, forward, right, up; armor = MSG_ReadByte (net_message); @@ -488,73 +486,41 @@ V_PrepBlend (void) /* VIEW RENDERING */ -static float -angledelta (float a) -{ - a = anglemod (a); - if (a > 180) - a -= 360; - return a; -} - static void CalcGunAngle (void) { - float yaw, pitch, move; - static float oldpitch = 0, oldyaw = 0; - - yaw = r_data->refdef->viewangles[YAW]; - pitch = -r_data->refdef->viewangles[PITCH]; - - yaw = angledelta (yaw - r_data->refdef->viewangles[YAW]) * 0.4; - yaw = bound (-10, yaw, 10); - pitch = angledelta (-pitch - r_data->refdef->viewangles[PITCH]) * 0.4; - pitch = bound (-10, pitch, 10); - - move = host_frametime * 20; - if (yaw > oldyaw) { - if (oldyaw + move < yaw) - yaw = oldyaw + move; - } else { - if (oldyaw - move > yaw) - yaw = oldyaw - move; - } - - if (pitch > oldpitch) { - if (oldpitch + move < pitch) - pitch = oldpitch + move; - } else { - if (oldpitch - move > pitch) - pitch = oldpitch - move; - } - - oldyaw = yaw; - oldpitch = pitch; - - cl.viewent.angles[YAW] = r_data->refdef->viewangles[YAW] + yaw; - cl.viewent.angles[PITCH] = -(r_data->refdef->viewangles[PITCH] + pitch); + vec4f_t rotation = r_data->refdef->viewrotation; + //FIXME make child of camera + Transform_SetWorldRotation (cl.viewent.transform, rotation); } static void V_BoundOffsets (void) { - vec4f_t origin = cl.simorg; + vec4f_t offset = r_data->refdef->viewposition + - cl.viewstate.origin; // absolutely bound refresh reletive to entity clipping hull // so the view can never be inside a solid wall - if (r_data->refdef->vieworg[0] < origin[0] - 14) - r_data->refdef->vieworg[0] = origin[0] - 14; - else if (r_data->refdef->vieworg[0] > origin[0] + 14) - r_data->refdef->vieworg[0] = origin[0] + 14; - if (r_data->refdef->vieworg[1] < origin[1] - 14) - r_data->refdef->vieworg[1] = origin[1] - 14; - else if (r_data->refdef->vieworg[1] > origin[1] + 14) - r_data->refdef->vieworg[1] = origin[1] + 14; - if (r_data->refdef->vieworg[2] < origin[2] - 22) - r_data->refdef->vieworg[2] = origin[2] - 22; - else if (r_data->refdef->vieworg[2] > origin[2] + 30) - r_data->refdef->vieworg[2] = origin[2] + 30; + offset[0] = bound (-14, offset[0], 14); + offset[1] = bound (-14, offset[1], 14); + offset[2] = bound (-22, offset[2], 30); + r_data->refdef->viewposition = cl.viewstate.origin + offset; +} + +static vec4f_t +idle_quat (vec4f_t axis, cvar_t *cycle, cvar_t *level) +{ + vec4f_t identity = { 0, 0, 0, 1 }; + if (!level || !cycle) { + return identity; + } + float scale = sin (cl.time * cycle->value); + float ang = scale * level->value * v_idlescale->value; + float c = cos (ang); + float s = sin (ang); + return axis * s + identity * c; } /* @@ -565,19 +531,21 @@ V_BoundOffsets (void) static void V_AddIdle (void) { - r_data->refdef->viewangles[ROLL] += v_idlescale->value * - sin (cl.time * v_iroll_cycle->value) * v_iroll_level->value; - r_data->refdef->viewangles[PITCH] += v_idlescale->value * - sin (cl.time * v_ipitch_cycle->value) * v_ipitch_level->value; - r_data->refdef->viewangles[YAW] += v_idlescale->value * - sin (cl.time * v_iyaw_cycle->value) * v_iyaw_level->value; + vec4f_t roll = idle_quat ((vec4f_t) { 1, 0, 0, 0}, + v_iroll_cycle, v_iroll_level); + vec4f_t pitch = idle_quat ((vec4f_t) { 0, 1, 0, 0}, + v_ipitch_cycle, v_ipitch_level); + vec4f_t yaw = idle_quat ((vec4f_t) { 0, 0, 1, 0}, + v_iyaw_cycle, v_iyaw_level); + vec4f_t rot = normalf (qmulf (yaw, qmulf (pitch, roll))); - cl.viewent.angles[ROLL] -= v_idlescale->value * - sin (cl.time * v_iroll_cycle->value) * v_iroll_level->value; - cl.viewent.angles[PITCH] -= v_idlescale->value * - sin (cl.time * v_ipitch_cycle->value) * v_ipitch_level->value; - cl.viewent.angles[YAW] -= v_idlescale->value * - sin (cl.time * v_iyaw_cycle->value) * v_iyaw_level->value; + // rotate the view + r_data->refdef->viewrotation = qmulf (rot, r_data->refdef->viewrotation); + + // counter-rotate the weapon + rot = qmulf (qconjf (rot), + Transform_GetWorldRotation (cl.viewent.transform)); + Transform_SetWorldRotation (cl.viewent.transform, rot); } /* @@ -588,23 +556,25 @@ V_AddIdle (void) static void V_CalcViewRoll (void) { - float side; - vec_t *angles = cl.simangles; - vec4f_t velocity = cl.simvel; + vec_t *angles = cl.viewstate.angles; + vec4f_t velocity = cl.viewstate.velocity; + vec3_t ang = { }; - side = V_CalcRoll (angles, velocity); - r_data->refdef->viewangles[ROLL] += side; + ang[ROLL] = V_CalcRoll (angles, velocity); if (v_dmg_time > 0) { - r_data->refdef->viewangles[ROLL] += - v_dmg_time / v_kicktime->value * v_dmg_roll; - r_data->refdef->viewangles[PITCH] += - v_dmg_time / v_kicktime->value * v_dmg_pitch; - v_dmg_time -= host_frametime; + ang[ROLL] += v_dmg_time / v_kicktime->value * v_dmg_roll; + ang[PITCH] += v_dmg_time / v_kicktime->value * v_dmg_pitch; + v_dmg_time -= cl.viewstate.frametime; } - if (view_state->pls.es.flags & PF_DEAD) // PF_GIB will also set PF_DEAD - r_data->refdef->viewangles[ROLL] = 80; // dead view angle + if (cl.viewstate.flags & VF_DEAD) { // VF_GIB will also set VF_DEAD + ang[ROLL] = 80; // dead view angle + } + + vec4f_t rot; + AngleQuat (ang, &rot[0]);//FIXME + r_data->refdef->viewrotation = qmulf (r_data->refdef->viewrotation, rot); } static void @@ -612,14 +582,12 @@ V_CalcIntermissionRefdef (void) { entity_t *view; float old; - vec4f_t origin = cl.simorg; - vec_t *angles = cl.simangles; // view is the weapon model (visible only from inside body) view = &cl.viewent; - VectorCopy (origin, r_data->refdef->vieworg); - VectorCopy (angles, r_data->refdef->viewangles); + r_data->refdef->viewposition = cl.viewstate.origin; + AngleQuat (cl.viewstate.angles, &r_data->refdef->viewrotation[0]);//FIXME view->renderer.model = NULL; // always idle in intermission @@ -636,113 +604,122 @@ V_CalcRefdef (void) entity_t *view = &cl.viewent; float bob; static float oldz = 0; - int i; - vec3_t forward, right, up; - vec4f_t origin = cl.simorg; - vec_t *viewangles = cl.simangles; + vec4f_t forward = {}, right = {}, up = {}; + vec4f_t origin = cl.viewstate.origin; + vec_t *viewangles = cl.viewstate.angles; V_DriftPitch (); bob = V_CalcBob (); // refresh position - VectorCopy (origin, r_data->refdef->vieworg); - r_data->refdef->vieworg[2] += cl.viewheight + bob; + r_data->refdef->viewposition = origin; + r_data->refdef->viewposition[2] += cl.viewheight + bob; // never let it sit exactly on a node line, because a water plane can // disappear when viewed with the eye exactly on it. // server protocol specifies to only 1/8 pixel, so add 1/16 in each axis - r_data->refdef->vieworg[0] += 1.0 / 16; - r_data->refdef->vieworg[1] += 1.0 / 16; - r_data->refdef->vieworg[2] += 1.0 / 16; + r_data->refdef->viewposition += (vec4f_t) { 1.0/16, 1.0/16, 1.0/16, 0}; - VectorCopy (viewangles, r_data->refdef->viewangles); + AngleQuat (cl.viewstate.angles, &r_data->refdef->viewrotation[0]);//FIXME V_CalcViewRoll (); V_AddIdle (); // offsets - AngleVectors (viewangles, forward, right, up); + //FIXME semi-duplicates AngleQuat (also, vec3_t vs vec4f_t) + AngleVectors (viewangles, &forward[0], &right[0], &up[0]); // don't allow cheats in multiplayer // FIXME check for dead if (cl.maxclients == 1) { - for (i = 0; i < 3; i++) { - r_data->refdef->vieworg[i] += scr_ofsx->value * forward[i] + - scr_ofsy->value * right[i] + - scr_ofsz->value * up[i]; - } + r_data->refdef->viewposition += scr_ofsx->value * forward + + scr_ofsy->value * right + + scr_ofsz->value * up; } V_BoundOffsets (); // set up gun position - VectorCopy (viewangles, view->angles); - CalcGunAngle (); - VectorCopy (origin, view->origin); - view->origin[2] += cl.viewheight; - - for (i = 0; i < 3; i++) { - view->origin[i] += forward[i] * bob * 0.4; -// view->origin[i] += right[i] * bob * 0.4; -// view->origin[i] += up[i] * bob * 0.8; - } - view->origin[2] += bob; + origin += (vec4f_t) { 0, 0, cl.viewheight, 0 }; + origin += forward * bob * 0.4f + (vec4f_t) { 0, 0, bob, 0 }; // fudge position around to keep amount of weapon visible // roughly equal with different FOV - if (hud_sbar->int_val == 0 && r_data->scr_viewsize->int_val >= 100) + if (hud_sbar->int_val == 0 && r_data->scr_viewsize->int_val >= 100) { ; - else if (r_data->scr_viewsize->int_val == 110) - view->origin[2] += 1; - else if (r_data->scr_viewsize->int_val == 100) - view->origin[2] += 2; - else if (r_data->scr_viewsize->int_val == 90) - view->origin[2] += 1; - else if (r_data->scr_viewsize->int_val == 80) - view->origin[2] += 0.5; + } else if (r_data->scr_viewsize->int_val == 110) { + origin += (vec4f_t) { 0, 0, 1, 0}; + } else if (r_data->scr_viewsize->int_val == 100) { + origin += (vec4f_t) { 0, 0, 2, 0}; + } else if (r_data->scr_viewsize->int_val == 90) { + origin += (vec4f_t) { 0, 0, 1, 0}; + } else if (r_data->scr_viewsize->int_val == 80) { + origin += (vec4f_t) { 0, 0, 0.5, 0}; + } - if (view_state->pls.es.flags & (PF_GIB | PF_DEAD)) { + if (cl.viewstate.flags & (VF_GIB | VF_DEAD)) { view->renderer.model = NULL; } else { view->renderer.model = cl.model_precache[cl.stats[STAT_WEAPON]]; } - view->animation.frame = view_state->pls.es.weaponframe; + view->animation.frame = cl.viewstate.weaponframe; view->renderer.skin = 0; // set up the refresh position - VectorAdd (r_data->refdef->viewangles, cl.punchangle, - r_data->refdef->viewangles); + r_data->refdef->viewrotation = qmulf (cl.viewstate.punchangle, + r_data->refdef->viewrotation); // smooth out stair step ups if ((cl.onground != -1) && (origin[2] - oldz > 0)) { float steptime; - steptime = host_frametime; + steptime = cl.viewstate.frametime; oldz += steptime * 80; if (oldz > origin[2]) oldz = origin[2]; if (origin[2] - oldz > 12) oldz = origin[2] - 12; - r_data->refdef->vieworg[2] += oldz - origin[2]; - view->origin[2] += oldz - origin[2]; - } else + r_data->refdef->viewposition[2] += oldz - origin[2]; + origin[2] += oldz - origin[2]; + } else { oldz = origin[2]; + } + { + // FIXME sort out the alias model specific negation + vec3_t ang = {-viewangles[0], viewangles[1], viewangles[2]}; + CL_TransformEntity (view, 1, ang, origin); + } - if (cl.chase && chase_active->int_val) + if (cl.chase && chase_active->int_val) { Chase_Update (); - - CL_TransformEntity (view, view->angles); + } } static void DropPunchAngle (void) { - cl.punchangle[PITCH] -= 10 * host_frametime; - if (cl.punchangle[PITCH] < 0) - cl.punchangle[PITCH] = 0; + vec4f_t punch = cl.viewstate.punchangle; + float ps = magnitude3f (punch)[0]; + if (ps < 1e-3) { + // < 0.2 degree rotation, not worth worrying about + //ensure the quaternion is normalized + cl.viewstate.punchangle = (vec4f_t) { 0, 0, 0, 1 }; + return; + } + float pc = punch[3]; + float ds = 0.0871557427 * cl.viewstate.frametime; + float dc = sqrt (1 - ds * ds); + float s = ps * dc - pc * ds; + float c = pc * dc + ps * ds; + if (s <= 0 || c >= 1) { + cl.viewstate.punchangle = (vec4f_t) { 0, 0, 0, 1 }; + } else { + punch *= s / ps; + punch[3] = c; + } } /* @@ -754,17 +731,17 @@ DropPunchAngle (void) void V_RenderView (void) { - if (cls.state != ca_active) + if (cls.state != ca_active) { + r_data->refdef->viewposition = (vec4f_t) { 0, 0, 0, 1 }; + r_data->refdef->viewrotation = (vec4f_t) { 0, 0, 0, 1 }; return; + } - view_frame = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK]; - view_state = &view_frame->playerstate[cl.playernum]; - - if (view_state->pls.es.flags & PF_GIB) + if (cl.viewstate.flags & VF_GIB) { cl.viewheight = 8; // gib view height - else if (view_state->pls.es.flags & PF_DEAD) + } else if (cl.viewstate.flags & VF_DEAD) { cl.viewheight = -16; // corpse view height - else { + } else { cl.viewheight = DEFAULT_VIEWHEIGHT; // view height if (cl.stdver) cl.viewheight = cl.stats[STAT_VIEWHEIGHT]; diff --git a/qw/source/teamplay.c b/qw/source/teamplay.c index 159da95f0..c3e2a0424 100644 --- a/qw/source/teamplay.c +++ b/qw/source/teamplay.c @@ -184,10 +184,10 @@ Team_ParseSay (dstring_t *buf, const char *s) case 'l': location: bracket = 0; - location = locs_find (cl.simorg); + location = locs_find (cl.viewstate.origin); if (location) { recorded_location = true; - last_recorded_location = cl.simorg; + last_recorded_location = cl.viewstate.origin; t1 = location->name; } else snprintf (t2, sizeof (t2), "Unknown!"); @@ -279,7 +279,7 @@ void Team_Dead (void) { died = true; - death_location = cl.simorg; + death_location = cl.viewstate.origin; } void @@ -370,7 +370,7 @@ locs_loc (void) if (strcasecmp (Cmd_Argv (1), "add") == 0) { if (Cmd_Argc () >= 3) - locs_mark (cl.simorg, desc); + locs_mark (cl.viewstate.origin, desc); else Sys_Printf ("loc add :marks the current location " "with the description and records the information " @@ -379,7 +379,7 @@ locs_loc (void) if (strcasecmp (Cmd_Argv (1), "rename") == 0) { if (Cmd_Argc () >= 3) - locs_edit (cl.simorg, desc); + locs_edit (cl.viewstate.origin, desc); else Sys_Printf ("loc rename :changes the description of " "the nearest location marker\n"); @@ -387,14 +387,14 @@ locs_loc (void) if (strcasecmp (Cmd_Argv (1),"delete") == 0) { if (Cmd_Argc () == 2) - locs_del (cl.simorg); + locs_del (cl.viewstate.origin); else Sys_Printf ("loc delete :removes nearest location marker\n"); } if (strcasecmp (Cmd_Argv (1),"move") == 0) { if (Cmd_Argc () == 2) - locs_edit (cl.simorg, NULL); + locs_edit (cl.viewstate.origin, NULL); else Sys_Printf ("loc move :moves the nearest location marker to your " "current location\n"); @@ -409,7 +409,7 @@ Locs_Loc_Get (void) if (GIB_Argc () != 1) GIB_USAGE (""); else { - location = locs_find (cl.simorg); + location = locs_find (cl.viewstate.origin); GIB_Return (location ? location->name : "unknown"); } }