Debian Codegraph @

code/cgame/cg_ents.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 //
23 // cg_ents.c -- present snapshot entities, happens every single frame
24
25 #include "cg_local.h"
26
27
28 /*
29 ======================
30 CG_PositionEntityOnTag
31
32 Modifies the entities position and axis by the given
33 tag location
34 ======================
35 */
36 void CG_PositionEntityOnTag( refEntity_t *entity, const refEntity_t *parent,
37 qhandle_t parentModel, char *tagName ) {
38 int i;
39 orientation_t lerped;
40
41 // lerp the tag
42 trap_R_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame,
43 1.0 - parent->backlerp, tagName );
44
45 // FIXME: allow origin offsets along tag?
46 VectorCopy( parent->origin, entity->origin );
47 for ( i = 0 ; i < 3 ; i++ ) {
48 VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin );
49 }
50
51 // had to cast away the const to avoid compiler problems...
52 MatrixMultiply( lerped.axis, ((refEntity_t *)parent)->axis, entity->axis );
53 entity->backlerp = parent->backlerp;
54 }
55
56
57 /*
58 ======================
59 CG_PositionRotatedEntityOnTag
60
61 Modifies the entities position and axis by the given
62 tag location
63 ======================
64 */
65 void CG_PositionRotatedEntityOnTag( refEntity_t *entity, const refEntity_t *parent,
66 qhandle_t parentModel, char *tagName ) {
67 int i;
68 orientation_t lerped;
69 vec3_t tempAxis[3];
70
71 //AxisClear( entity->axis );
72 // lerp the tag
73 trap_R_LerpTag( &lerped, parentModel, parent->oldframe, parent->frame,
74 1.0 - parent->backlerp, tagName );
75
76 // FIXME: allow origin offsets along tag?
77 VectorCopy( parent->origin, entity->origin );
78 for ( i = 0 ; i < 3 ; i++ ) {
79 VectorMA( entity->origin, lerped.origin[i], parent->axis[i], entity->origin );
80 }
81
82 // had to cast away the const to avoid compiler problems...
83 MatrixMultiply( entity->axis, lerped.axis, tempAxis );
84 MatrixMultiply( tempAxis, ((refEntity_t *)parent)->axis, entity->axis );
85 }
86
87
88
89 /*
90 ==========================================================================
91
92 FUNCTIONS CALLED EACH FRAME
93
94 ==========================================================================
95 */
96
97 /*
98 ======================
99 CG_SetEntitySoundPosition
100
101 Also called by event processing code
102 ======================
103 */
104 void CG_SetEntitySoundPosition( centity_t *cent ) {
105 if ( cent->currentState.solid == SOLID_BMODEL ) {
106 vec3_t origin;
107 float *v;
108
109 v = cgs.inlineModelMidpoints[ cent->currentState.modelindex ];
110 VectorAdd( cent->lerpOrigin, v, origin );
111 trap_S_UpdateEntityPosition( cent->currentState.number, origin );
112 } else {
113 trap_S_UpdateEntityPosition( cent->currentState.number, cent->lerpOrigin );
114 }
115 }
116
117 /*
118 ==================
119 CG_EntityEffects
120
121 Add continuous entity effects, like local entity emission and lighting
122 ==================
123 */
124 static void CG_EntityEffects( centity_t *cent ) {
125
126 // update sound origins
127 CG_SetEntitySoundPosition( cent );
128
129 // add loop sound
130 if ( cent->currentState.loopSound ) {
131 if (cent->currentState.eType != ET_SPEAKER) {
132 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin,
133 cgs.gameSounds[ cent->currentState.loopSound ] );
134 } else {
135 trap_S_AddRealLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin,
136 cgs.gameSounds[ cent->currentState.loopSound ] );
137 }
138 }
139
140
141 // constant light glow
142 if(cent->currentState.constantLight)
143 {
144 int cl;
145 float i, r, g, b;
146
147 cl = cent->currentState.constantLight;
148 r = (float) (cl & 0xFF) / 255.0;
149 g = (float) ((cl >> 8) & 0xFF) / 255.0;
150 b = (float) ((cl >> 16) & 0xFF) / 255.0;
151 i = (float) ((cl >> 24) & 0xFF) * 4.0;
152 trap_R_AddLightToScene(cent->lerpOrigin, i, r, g, b);
153 }
154
155 }
156
157
158 /*
159 ==================
160 CG_General
161 ==================
162 */
163 static void CG_General( centity_t *cent ) {
164 refEntity_t ent;
165 entityState_t *s1;
166
167 s1 = &cent->currentState;
168
169 // if set to invisible, skip
170 if (!s1->modelindex) {
171 return;
172 }
173
174 memset (&ent, 0, sizeof(ent));
175
176 // set frame
177
178 ent.frame = s1->frame;
179 ent.oldframe = ent.frame;
180 ent.backlerp = 0;
181
182 VectorCopy( cent->lerpOrigin, ent.origin);
183 VectorCopy( cent->lerpOrigin, ent.oldorigin);
184
185 ent.hModel = cgs.gameModels[s1->modelindex];
186
187 // player model
188 if (s1->number == cg.snap->ps.clientNum) {
189 ent.renderfx |= RF_THIRD_PERSON; // only draw from mirrors
190 }
191
192 // convert angles to axis
193 AnglesToAxis( cent->lerpAngles, ent.axis );
194
195 // add to refresh list
196 trap_R_AddRefEntityToScene (&ent);
197 }
198
199 /*
200 ==================
201 CG_Speaker
202
203 Speaker entities can automatically play sounds
204 ==================
205 */
206 static void CG_Speaker( centity_t *cent ) {
207 if ( ! cent->currentState.clientNum ) { // FIXME: use something other than clientNum...
208 return; // not auto triggering
209 }
210
211 if ( cg.time < cent->miscTime ) {
212 return;
213 }
214
215 trap_S_StartSound (NULL, cent->currentState.number, CHAN_ITEM, cgs.gameSounds[cent->currentState.eventParm] );
216
217 // ent->s.frame = ent->wait * 10;
218 // ent->s.clientNum = ent->random * 10;
219 cent->miscTime = cg.time + cent->currentState.frame * 100 + cent->currentState.clientNum * 100 * crandom();
220 }
221
222 /*
223 ==================
224 CG_Item
225 ==================
226 */
227 static void CG_Item( centity_t *cent ) {
228 refEntity_t ent;
229 entityState_t *es;
230 gitem_t *item;
231 int msec;
232 float frac;
233 float scale;
234 weaponInfo_t *wi;
235
236 es = &cent->currentState;
237 if ( es->modelindex >= bg_numItems ) {
238 CG_Error( "Bad item index %i on entity", es->modelindex );
239 }
240
241 // if set to invisible, skip
242 if ( !es->modelindex || ( es->eFlags & EF_NODRAW ) ) {
243 return;
244 }
245
246 item = &bg_itemlist[ es->modelindex ];
247 if ( cg_simpleItems.integer && item->giType != IT_TEAM ) {
248 memset( &ent, 0, sizeof( ent ) );
249 ent.reType = RT_SPRITE;
250 VectorCopy( cent->lerpOrigin, ent.origin );
251 ent.radius = 14;
252 ent.customShader = cg_items[es->modelindex].icon;
253 ent.shaderRGBA[0] = 255;
254 ent.shaderRGBA[1] = 255;
255 ent.shaderRGBA[2] = 255;
256 ent.shaderRGBA[3] = 255;
257 trap_R_AddRefEntityToScene(&ent);
258 return;
259 }
260
261 // items bob up and down continuously
262 scale = 0.005 + cent->currentState.number * 0.00001;
263 cent->lerpOrigin[2] += 4 + cos( ( cg.time + 1000 ) * scale ) * 4;
264
265 memset (&ent, 0, sizeof(ent));
266
267 // autorotate at one of two speeds
268 if ( item->giType == IT_HEALTH ) {
269 VectorCopy( cg.autoAnglesFast, cent->lerpAngles );
270 AxisCopy( cg.autoAxisFast, ent.axis );
271 } else {
272 VectorCopy( cg.autoAngles, cent->lerpAngles );
273 AxisCopy( cg.autoAxis, ent.axis );
274 }
275
276 wi = NULL;
277 // the weapons have their origin where they attatch to player
278 // models, so we need to offset them or they will rotate
279 // eccentricly
280 if ( item->giType == IT_WEAPON ) {
281 wi = &cg_weapons[item->giTag];
282 cent->lerpOrigin[0] -=
283 wi->weaponMidpoint[0] * ent.axis[0][0] +
284 wi->weaponMidpoint[1] * ent.axis[1][0] +
285 wi->weaponMidpoint[2] * ent.axis[2][0];
286 cent->lerpOrigin[1] -=
287 wi->weaponMidpoint[0] * ent.axis[0][1] +
288 wi->weaponMidpoint[1] * ent.axis[1][1] +
289 wi->weaponMidpoint[2] * ent.axis[2][1];
290 cent->lerpOrigin[2] -=
291 wi->weaponMidpoint[0] * ent.axis[0][2] +
292 wi->weaponMidpoint[1] * ent.axis[1][2] +
293 wi->weaponMidpoint[2] * ent.axis[2][2];
294
295 cent->lerpOrigin[2] += 8; // an extra height boost
296 }
297
298 if( item->giType == IT_WEAPON && item->giTag == WP_RAILGUN ) {
299 clientInfo_t *ci = &cgs.clientinfo[cg.snap->ps.clientNum];
300 Byte4Copy( ci->c1RGBA, ent.shaderRGBA );
301 }
302
303 ent.hModel = cg_items[es->modelindex].models[0];
304
305 VectorCopy( cent->lerpOrigin, ent.origin);
306 VectorCopy( cent->lerpOrigin, ent.oldorigin);
307
308 ent.nonNormalizedAxes = qfalse;
309
310 // if just respawned, slowly scale up
311 msec = cg.time - cent->miscTime;
312 if ( msec >= 0 && msec < ITEM_SCALEUP_TIME ) {
313 frac = (float)msec / ITEM_SCALEUP_TIME;
314 VectorScale( ent.axis[0], frac, ent.axis[0] );
315 VectorScale( ent.axis[1], frac, ent.axis[1] );
316 VectorScale( ent.axis[2], frac, ent.axis[2] );
317 ent.nonNormalizedAxes = qtrue;
318 } else {
319 frac = 1.0;
320 }
321
322 // items without glow textures need to keep a minimum light value
323 // so they are always visible
324 if ( ( item->giType == IT_WEAPON ) ||
325 ( item->giType == IT_ARMOR ) ) {
326 ent.renderfx |= RF_MINLIGHT;
327 }
328
329 // increase the size of the weapons when they are presented as items
330 if ( item->giType == IT_WEAPON ) {
331 VectorScale( ent.axis[0], 1.5, ent.axis[0] );
332 VectorScale( ent.axis[1], 1.5, ent.axis[1] );
333 VectorScale( ent.axis[2], 1.5, ent.axis[2] );
334 ent.nonNormalizedAxes = qtrue;
335 #ifdef MISSIONPACK
336 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, cgs.media.weaponHoverSound );
337 #endif
338 }
339
340 #ifdef MISSIONPACK
341 if ( item->giType == IT_HOLDABLE && item->giTag == HI_KAMIKAZE ) {
342 VectorScale( ent.axis[0], 2, ent.axis[0] );
343 VectorScale( ent.axis[1], 2, ent.axis[1] );
344 VectorScale( ent.axis[2], 2, ent.axis[2] );
345 ent.nonNormalizedAxes = qtrue;
346 }
347 #endif
348
349 // add to refresh list
350 trap_R_AddRefEntityToScene(&ent);
351
352 if ( item->giType == IT_WEAPON && wi && wi->barrelModel ) {
353 refEntity_t barrel;
354 vec3_t angles;
355
356 memset( &barrel, 0, sizeof( barrel ) );
357
358 barrel.hModel = wi->barrelModel;
359
360 VectorCopy( ent.lightingOrigin, barrel.lightingOrigin );
361 barrel.shadowPlane = ent.shadowPlane;
362 barrel.renderfx = ent.renderfx;
363
364 angles[YAW] = 0;
365 angles[PITCH] = 0;
366 angles[ROLL] = 0;
367 AnglesToAxis( angles, barrel.axis );
368
369 CG_PositionRotatedEntityOnTag( &barrel, &ent, wi->weaponModel, "tag_barrel" );
370
371 barrel.nonNormalizedAxes = ent.nonNormalizedAxes;
372
373 trap_R_AddRefEntityToScene( &barrel );
374 }
375
376 // accompanying rings / spheres for powerups
377 if ( !cg_simpleItems.integer )
378 {
379 vec3_t spinAngles;
380
381 VectorClear( spinAngles );
382
383 if ( item->giType == IT_HEALTH || item->giType == IT_POWERUP )
384 {
385 if ( ( ent.hModel = cg_items[es->modelindex].models[1] ) != 0 )
386 {
387 if ( item->giType == IT_POWERUP )
388 {
389 ent.origin[2] += 12;
390 spinAngles[1] = ( cg.time & 1023 ) * 360 / -1024.0f;
391 }
392 AnglesToAxis( spinAngles, ent.axis );
393
394 // scale up if respawning
395 if ( frac != 1.0 ) {
396 VectorScale( ent.axis[0], frac, ent.axis[0] );
397 VectorScale( ent.axis[1], frac, ent.axis[1] );
398 VectorScale( ent.axis[2], frac, ent.axis[2] );
399 ent.nonNormalizedAxes = qtrue;
400 }
401 trap_R_AddRefEntityToScene( &ent );
402 }
403 }
404 }
405 }
406
407 //============================================================================
408
409 /*
410 ===============
411 CG_Missile
412 ===============
413 */
414 static void CG_Missile( centity_t *cent ) {
415 refEntity_t ent;
416 entityState_t *s1;
417 const weaponInfo_t *weapon;
418 // int col;
419
420 s1 = &cent->currentState;
421 if ( s1->weapon >= WP_NUM_WEAPONS ) {
422 s1->weapon = 0;
423 }
424 weapon = &cg_weapons[s1->weapon];
425
426 // calculate the axis
427 VectorCopy( s1->angles, cent->lerpAngles);
428
429 // add trails
430 if ( weapon->missileTrailFunc )
431 {
432 weapon->missileTrailFunc( cent, weapon );
433 }
434 /*
435 if ( cent->currentState.modelindex == TEAM_RED ) {
436 col = 1;
437 }
438 else if ( cent->currentState.modelindex == TEAM_BLUE ) {
439 col = 2;
440 }
441 else {
442 col = 0;
443 }
444
445 // add dynamic light
446 if ( weapon->missileDlight ) {
447 trap_R_AddLightToScene(cent->lerpOrigin, weapon->missileDlight,
448 weapon->missileDlightColor[col][0], weapon->missileDlightColor[col][1], weapon->missileDlightColor[col][2] );
449 }
450 */
451 // add dynamic light
452 if ( weapon->missileDlight ) {
453 trap_R_AddLightToScene(cent->lerpOrigin, weapon->missileDlight,
454 weapon->missileDlightColor[0], weapon->missileDlightColor[1], weapon->missileDlightColor[2] );
455 }
456
457 // add missile sound
458 if ( weapon->missileSound ) {
459 vec3_t velocity;
460
461 BG_EvaluateTrajectoryDelta( &cent->currentState.pos, cg.time, velocity );
462
463 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, velocity, weapon->missileSound );
464 }
465
466 // create the render entity
467 memset (&ent, 0, sizeof(ent));
468 VectorCopy( cent->lerpOrigin, ent.origin);
469 VectorCopy( cent->lerpOrigin, ent.oldorigin);
470
471 if ( cent->currentState.weapon == WP_PLASMAGUN ) {
472 ent.reType = RT_SPRITE;
473 ent.radius = 16;
474 ent.rotation = 0;
475 ent.customShader = cgs.media.plasmaBallShader;
476 trap_R_AddRefEntityToScene( &ent );
477 return;
478 }
479
480 // flicker between two skins
481 ent.skinNum = cg.clientFrame & 1;
482 ent.hModel = weapon->missileModel;
483 ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW;
484
485 #ifdef MISSIONPACK
486 if ( cent->currentState.weapon == WP_PROX_LAUNCHER ) {
487 if (s1->generic1 == TEAM_BLUE) {
488 ent.hModel = cgs.media.blueProxMine;
489 }
490 }
491 #endif
492
493 // convert direction of travel into axis
494 if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) {
495 ent.axis[0][2] = 1;
496 }
497
498 // spin as it moves
499 if ( s1->pos.trType != TR_STATIONARY ) {
500 RotateAroundDirection( ent.axis, cg.time / 4 );
501 } else {
502 #ifdef MISSIONPACK
503 if ( s1->weapon == WP_PROX_LAUNCHER ) {
504 AnglesToAxis( cent->lerpAngles, ent.axis );
505 }
506 else
507 #endif
508 {
509 RotateAroundDirection( ent.axis, s1->time );
510 }
511 }
512
513 // add to refresh list, possibly with quad glow
514 CG_AddRefEntityWithPowerups( &ent, s1, TEAM_FREE );
515 }
516
517 /*
518 ===============
519 CG_Grapple
520
521 This is called when the grapple is sitting up against the wall
522 ===============
523 */
524 static void CG_Grapple( centity_t *cent ) {
525 refEntity_t ent;
526 entityState_t *s1;
527 const weaponInfo_t *weapon;
528
529 s1 = &cent->currentState;
530 if ( s1->weapon >= WP_NUM_WEAPONS ) {
531 s1->weapon = 0;
532 }
533 weapon = &cg_weapons[s1->weapon];
534
535 // calculate the axis
536 VectorCopy( s1->angles, cent->lerpAngles);
537
538 #if 0 // FIXME add grapple pull sound here..?
539 // add missile sound
540 if ( weapon->missileSound ) {
541 trap_S_AddLoopingSound( cent->currentState.number, cent->lerpOrigin, vec3_origin, weapon->missileSound );
542 }
543 #endif
544
545 // Will draw cable if needed
546 CG_GrappleTrail ( cent, weapon );
547
548 // create the render entity
549 memset (&ent, 0, sizeof(ent));
550 VectorCopy( cent->lerpOrigin, ent.origin);
551 VectorCopy( cent->lerpOrigin, ent.oldorigin);
552
553 // flicker between two skins
554 ent.skinNum = cg.clientFrame & 1;
555 ent.hModel = weapon->missileModel;
556 ent.renderfx = weapon->missileRenderfx | RF_NOSHADOW;
557
558 // convert direction of travel into axis
559 if ( VectorNormalize2( s1->pos.trDelta, ent.axis[0] ) == 0 ) {
560 ent.axis[0][2] = 1;
561 }
562
563 trap_R_AddRefEntityToScene( &ent );
564 }
565
566 /*
567 ===============
568 CG_Mover
569 ===============
570 */
571 static void CG_Mover( centity_t *cent ) {
572 refEntity_t ent;
573 entityState_t *s1;
574
575 s1 = &cent->currentState;
576
577 // create the render entity
578 memset (&ent, 0, sizeof(ent));
579 VectorCopy( cent->lerpOrigin, ent.origin);
580 VectorCopy( cent->lerpOrigin, ent.oldorigin);
581 AnglesToAxis( cent->lerpAngles, ent.axis );
582
583 ent.renderfx = RF_NOSHADOW;
584
585 // flicker between two skins (FIXME?)
586 ent.skinNum = ( cg.time >> 6 ) & 1;
587
588 // get the model, either as a bmodel or a modelindex
589 if ( s1->solid == SOLID_BMODEL ) {
590 ent.hModel = cgs.inlineDrawModel[s1->modelindex];
591 } else {
592 ent.hModel = cgs.gameModels[s1->modelindex];
593 }
594
595 // add to refresh list
596 trap_R_AddRefEntityToScene(&ent);
597
598 // add the secondary model
599 if ( s1->modelindex2 ) {
600 ent.skinNum = 0;
601 ent.hModel = cgs.gameModels[s1->modelindex2];
602 trap_R_AddRefEntityToScene(&ent);
603 }
604
605 }
606
607 /*
608 ===============
609 CG_Beam
610
611 Also called as an event
612 ===============
613 */
614 void CG_Beam( centity_t *cent ) {
615 refEntity_t ent;
616 entityState_t *s1;
617
618 s1 = &cent->currentState;
619
620 // create the render entity
621 memset (&ent, 0, sizeof(ent));
622 VectorCopy( s1->pos.trBase, ent.origin );
623 VectorCopy( s1->origin2, ent.oldorigin );
624 AxisClear( ent.axis );
625 ent.reType = RT_BEAM;
626
627 ent.renderfx = RF_NOSHADOW;
628
629 // add to refresh list
630 trap_R_AddRefEntityToScene(&ent);
631 }
632
633
634 /*
635 ===============
636 CG_Portal
637 ===============
638 */
639 static void CG_Portal( centity_t *cent ) {
640 refEntity_t ent;
641 entityState_t *s1;
642
643 s1 = &cent->currentState;
644
645 // create the render entity
646 memset (&ent, 0, sizeof(ent));
647 VectorCopy( cent->lerpOrigin, ent.origin );
648 VectorCopy( s1->origin2, ent.oldorigin );
649 ByteToDir( s1->eventParm, ent.axis[0] );
650 PerpendicularVector( ent.axis[1], ent.axis[0] );
651
652 // negating this tends to get the directions like they want
653 // we really should have a camera roll value
654 VectorSubtract( vec3_origin, ent.axis[1], ent.axis[1] );
655
656 CrossProduct( ent.axis[0], ent.axis[1], ent.axis[2] );
657 ent.reType = RT_PORTALSURFACE;
658 ent.oldframe = s1->powerups;
659 ent.frame = s1->frame; // rotation speed
660 ent.skinNum = s1->clientNum/256.0 * 360; // roll offset
661
662 // add to refresh list
663 trap_R_AddRefEntityToScene(&ent);
664 }
665
666
667 /*
668 ================
669 CG_CreateRotationMatrix
670 ================
671 */
672 void CG_CreateRotationMatrix(vec3_t angles, vec3_t matrix[3]) {
673 AngleVectors(angles, matrix[0], matrix[1], matrix[2]);
674 VectorInverse(matrix[1]);
675 }
676
677 /*
678 ================
679 CG_TransposeMatrix
680 ================
681 */
682 void CG_TransposeMatrix(vec3_t matrix[3], vec3_t transpose[3]) {
683 int i, j;
684 for (i = 0; i < 3; i++) {
685 for (j = 0; j < 3; j++) {
686 transpose[i][j] = matrix[j][i];
687 }
688 }
689 }
690
691 /*
692 ================
693 CG_RotatePoint
694 ================
695 */
696 void CG_RotatePoint(vec3_t point, vec3_t matrix[3]) {
697 vec3_t tvec;
698
699 VectorCopy(point, tvec);
700 point[0] = DotProduct(matrix[0], tvec);
701 point[1] = DotProduct(matrix[1], tvec);
702 point[2] = DotProduct(matrix[2], tvec);
703 }
704
705 /*
706 =========================
707 CG_AdjustPositionForMover
708
709 Also called by client movement prediction code
710 =========================
711 */
712 void CG_AdjustPositionForMover(const vec3_t in, int moverNum, int fromTime, int toTime, vec3_t out, vec3_t angles_in, vec3_t angles_out) {
713 centity_t *cent;
714 vec3_t oldOrigin, origin, deltaOrigin;
715 vec3_t oldAngles, angles, deltaAngles;
716 vec3_t matrix[3], transpose[3];
717 vec3_t org, org2, move2;
718
719 if ( moverNum <= 0 || moverNum >= ENTITYNUM_MAX_NORMAL ) {
720 VectorCopy( in, out );
721 VectorCopy(angles_in, angles_out);
722 return;
723 }
724
725 cent = &cg_entities[ moverNum ];
726 if ( cent->currentState.eType != ET_MOVER ) {
727 VectorCopy( in, out );
728 VectorCopy(angles_in, angles_out);
729 return;
730 }
731
732 BG_EvaluateTrajectory( &cent->currentState.pos, fromTime, oldOrigin );
733 BG_EvaluateTrajectory( &cent->currentState.apos, fromTime, oldAngles );
734
735 BG_EvaluateTrajectory( &cent->currentState.pos, toTime, origin );
736 BG_EvaluateTrajectory( &cent->currentState.apos, toTime, angles );
737
738 VectorSubtract( origin, oldOrigin, deltaOrigin );
739 VectorSubtract( angles, oldAngles, deltaAngles );
740
741 // origin change when on a rotating object
742 CG_CreateRotationMatrix( deltaAngles, transpose );
743 CG_TransposeMatrix( transpose, matrix );
744 VectorSubtract( in, oldOrigin, org );
745 VectorCopy( org, org2 );
746 CG_RotatePoint( org2, matrix );
747 VectorSubtract( org2, org, move2 );
748 VectorAdd( deltaOrigin, move2, deltaOrigin );
749
750 VectorAdd( in, deltaOrigin, out );
751 VectorAdd( angles_in, deltaAngles, angles_out );
752 }
753
754
755 /*
756 =============================
757 CG_InterpolateEntityPosition
758 =============================
759 */
760 static void CG_InterpolateEntityPosition( centity_t *cent ) {
761 vec3_t current, next;
762 float f;
763
764 // it would be an internal error to find an entity that interpolates without
765 // a snapshot ahead of the current one
766 if ( cg.nextSnap == NULL ) {
767 CG_Error( "CG_InterpoateEntityPosition: cg.nextSnap == NULL" );
768 }
769
770 f = cg.frameInterpolation;
771
772 // this will linearize a sine or parabolic curve, but it is important
773 // to not extrapolate player positions if more recent data is available
774 BG_EvaluateTrajectory( &cent->currentState.pos, cg.snap->serverTime, current );
775 BG_EvaluateTrajectory( &cent->nextState.pos, cg.nextSnap->serverTime, next );
776
777 cent->lerpOrigin[0] = current[0] + f * ( next[0] - current[0] );
778 cent->lerpOrigin[1] = current[1] + f * ( next[1] - current[1] );
779 cent->lerpOrigin[2] = current[2] + f * ( next[2] - current[2] );
780
781 BG_EvaluateTrajectory( &cent->currentState.apos, cg.snap->serverTime, current );
782 BG_EvaluateTrajectory( &cent->nextState.apos, cg.nextSnap->serverTime, next );
783
784 cent->lerpAngles[0] = LerpAngle( current[0], next[0], f );
785 cent->lerpAngles[1] = LerpAngle( current[1], next[1], f );
786 cent->lerpAngles[2] = LerpAngle( current[2], next[2], f );
787
788 }
789
790 /*
791 ===============
792 CG_CalcEntityLerpPositions
793
794 ===============
795 */
796 static void CG_CalcEntityLerpPositions( centity_t *cent ) {
797
798 // if this player does not want to see extrapolated players
799 if ( !cg_smoothClients.integer ) {
800 // make sure the clients use TR_INTERPOLATE
801 if ( cent->currentState.number < MAX_CLIENTS ) {
802 cent->currentState.pos.trType = TR_INTERPOLATE;
803 cent->nextState.pos.trType = TR_INTERPOLATE;
804 }
805 }
806
807 if ( cent->interpolate && cent->currentState.pos.trType == TR_INTERPOLATE ) {
808 CG_InterpolateEntityPosition( cent );
809 return;
810 }
811
812 // first see if we can interpolate between two snaps for
813 // linear extrapolated clients
814 if ( cent->interpolate && cent->currentState.pos.trType == TR_LINEAR_STOP &&
815 cent->currentState.number < MAX_CLIENTS) {
816 CG_InterpolateEntityPosition( cent );
817 return;
818 }
819
820 // just use the current frame and evaluate as best we can
821 BG_EvaluateTrajectory( &cent->currentState.pos, cg.time, cent->lerpOrigin );
822 BG_EvaluateTrajectory( &cent->currentState.apos, cg.time, cent->lerpAngles );
823
824 // adjust for riding a mover if it wasn't rolled into the predicted
825 // player state
826 if ( cent != &cg.predictedPlayerEntity ) {
827 CG_AdjustPositionForMover( cent->lerpOrigin, cent->currentState.groundEntityNum,
828 cg.snap->serverTime, cg.time, cent->lerpOrigin, cent->lerpAngles, cent->lerpAngles);
829 }
830 }
831
832 /*
833 ===============
834 CG_TeamBase
835 ===============
836 */
837 static void CG_TeamBase( centity_t *cent ) {
838 refEntity_t model;
839 #ifdef MISSIONPACK
840 vec3_t angles;
841 int t, h;
842 float c;
843
844 if ( cgs.gametype == GT_CTF || cgs.gametype == GT_1FCTF ) {
845 #else
846 if ( cgs.gametype == GT_CTF) {
847 #endif
848 // show the flag base
849 memset(&model, 0, sizeof(model));
850 model.reType = RT_MODEL;
851 VectorCopy( cent->lerpOrigin, model.lightingOrigin );
852 VectorCopy( cent->lerpOrigin, model.origin );
853 AnglesToAxis( cent->currentState.angles, model.axis );
854 if ( cent->currentState.modelindex == TEAM_RED ) {
855 model.hModel = cgs.media.redFlagBaseModel;
856 }
857 else if ( cent->currentState.modelindex == TEAM_BLUE ) {
858 model.hModel = cgs.media.blueFlagBaseModel;
859 }
860 else {
861 model.hModel = cgs.media.neutralFlagBaseModel;
862 }
863 trap_R_AddRefEntityToScene( &model );
864 }
865 #ifdef MISSIONPACK
866 else if ( cgs.gametype == GT_OBELISK ) {
867 // show the obelisk
868 memset(&model, 0, sizeof(model));
869 model.reType = RT_MODEL;
870 VectorCopy( cent->lerpOrigin, model.lightingOrigin );
871 VectorCopy( cent->lerpOrigin, model.origin );
872 AnglesToAxis( cent->currentState.angles, model.axis );
873
874 model.hModel = cgs.media.overloadBaseModel;
875 trap_R_AddRefEntityToScene( &model );
876 // if hit
877 if ( cent->currentState.frame == 1) {
878 // show hit model
879 // modelindex2 is the health value of the obelisk
880 c = cent->currentState.modelindex2;
881 model.shaderRGBA[0] = 0xff;
882 model.shaderRGBA[1] = c;
883 model.shaderRGBA[2] = c;
884 model.shaderRGBA[3] = 0xff;
885 //
886 model.hModel = cgs.media.overloadEnergyModel;
887 trap_R_AddRefEntityToScene( &model );
888 }
889 // if respawning
890 if ( cent->currentState.frame == 2) {
891 if ( !cent->miscTime ) {
892 cent->miscTime = cg.time;
893 }
894 t = cg.time - cent->miscTime;
895 h = (cg_obeliskRespawnDelay.integer - 5) * 1000;
896 //
897 if (t > h) {
898 c = (float) (t - h) / h;
899 if (c > 1)
900 c = 1;
901 }
902 else {
903 c = 0;
904 }
905 // show the lights
906 AnglesToAxis( cent->currentState.angles, model.axis );
907 //
908 model.shaderRGBA[0] = c * 0xff;
909 model.shaderRGBA[1] = c * 0xff;
910 model.shaderRGBA[2] = c * 0xff;
911 model.shaderRGBA[3] = c * 0xff;
912
913 model.hModel = cgs.media.overloadLightsModel;
914 trap_R_AddRefEntityToScene( &model );
915 // show the target
916 if (t > h) {
917 if ( !cent->muzzleFlashTime ) {
918 trap_S_StartSound (cent->lerpOrigin, ENTITYNUM_NONE, CHAN_BODY, cgs.media.obeliskRespawnSound);
919 cent->muzzleFlashTime = 1;
920 }
921 VectorCopy(cent->currentState.angles, angles);
922 angles[YAW] += (float) 16 * acos(1-c) * 180 / M_PI;
923 AnglesToAxis( angles, model.axis );
924
925 VectorScale( model.axis[0], c, model.axis[0]);
926 VectorScale( model.axis[1], c, model.axis[1]);
927 VectorScale( model.axis[2], c, model.axis[2]);
928
929 model.shaderRGBA[0] = 0xff;
930 model.shaderRGBA[1] = 0xff;
931 model.shaderRGBA[2] = 0xff;
932 model.shaderRGBA[3] = 0xff;
933 //
934 model.origin[2] += 56;
935 model.hModel = cgs.media.overloadTargetModel;
936 trap_R_AddRefEntityToScene( &model );
937 }
938 else {
939 //FIXME: show animated smoke
940 }
941 }
942 else {
943 cent->miscTime = 0;
944 cent->muzzleFlashTime = 0;
945 // modelindex2 is the health value of the obelisk
946 c = cent->currentState.modelindex2;
947 model.shaderRGBA[0] = 0xff;
948 model.shaderRGBA[1] = c;
949 model.shaderRGBA[2] = c;
950 model.shaderRGBA[3] = 0xff;
951 // show the lights
952 model.hModel = cgs.media.overloadLightsModel;
953 trap_R_AddRefEntityToScene( &model );
954 // show the target
955 model.origin[2] += 56;
956 model.hModel = cgs.media.overloadTargetModel;
957 trap_R_AddRefEntityToScene( &model );
958 }
959 }
960 else if ( cgs.gametype == GT_HARVESTER ) {
961 // show harvester model
962 memset(&model, 0, sizeof(model));
963 model.reType = RT_MODEL;
964 VectorCopy( cent->lerpOrigin, model.lightingOrigin );
965 VectorCopy( cent->lerpOrigin, model.origin );
966 AnglesToAxis( cent->currentState.angles, model.axis );
967
968 if ( cent->currentState.modelindex == TEAM_RED ) {
969 model.hModel = cgs.media.harvesterModel;
970 model.customSkin = cgs.media.harvesterRedSkin;
971 }
972 else if ( cent->currentState.modelindex == TEAM_BLUE ) {
973 model.hModel = cgs.media.harvesterModel;
974 model.customSkin = cgs.media.harvesterBlueSkin;
975 }
976 else {
977 model.hModel = cgs.media.harvesterNeutralModel;
978 model.customSkin = 0;
979 }
980 trap_R_AddRefEntityToScene( &model );
981 }
982 #endif
983 }
984
985 /*
986 ===============
987 CG_AddCEntity
988
989 ===============
990 */
991 static void CG_AddCEntity( centity_t *cent ) {
992 // event-only entities will have been dealt with already
993 if ( cent->currentState.eType >= ET_EVENTS ) {
994 return;
995 }
996
997 // calculate the current origin
998 CG_CalcEntityLerpPositions( cent );
999
1000 // add automatic effects
1001 CG_EntityEffects( cent );
1002
1003 switch ( cent->currentState.eType ) {
1004 default:
1005 CG_Error( "Bad entity type: %i", cent->currentState.eType );
1006 break;
1007 case ET_INVISIBLE:
1008 case ET_PUSH_TRIGGER:
1009 case ET_TELEPORT_TRIGGER:
1010 break;
1011 case ET_GENERAL:
1012 CG_General( cent );
1013 break;
1014 case ET_PLAYER:
1015 CG_Player( cent );
1016 break;
1017 case ET_ITEM:
1018 CG_Item( cent );
1019 break;
1020 case ET_MISSILE:
1021 CG_Missile( cent );
1022 break;
1023 case ET_MOVER:
1024 CG_Mover( cent );
1025 break;
1026 case ET_BEAM:
1027 CG_Beam( cent );
1028 break;
1029 case ET_PORTAL:
1030 CG_Portal( cent );
1031 break;
1032 case ET_SPEAKER:
1033 CG_Speaker( cent );
1034 break;
1035 case ET_GRAPPLE:
1036 CG_Grapple( cent );
1037 break;
1038 case ET_TEAM:
1039 CG_TeamBase( cent );
1040 break;
1041 }
1042 }
1043
1044 /*
1045 ===============
1046 CG_AddPacketEntities
1047
1048 ===============
1049 */
1050 void CG_AddPacketEntities( void ) {
1051 int num;
1052 centity_t *cent;
1053 playerState_t *ps;
1054
1055 // set cg.frameInterpolation
1056 if ( cg.nextSnap ) {
1057 int delta;
1058
1059 delta = (cg.nextSnap->serverTime - cg.snap->serverTime);
1060 if ( delta == 0 ) {
1061 cg.frameInterpolation = 0;
1062 } else {
1063 cg.frameInterpolation = (float)( cg.time - cg.snap->serverTime ) / delta;
1064 }
1065 } else {
1066 cg.frameInterpolation = 0; // actually, it should never be used, because
1067 // no entities should be marked as interpolating
1068 }
1069
1070 // the auto-rotating items will all have the same axis
1071 cg.autoAngles[0] = 0;
1072 cg.autoAngles[1] = ( cg.time & 2047 ) * 360 / 2048.0;
1073 cg.autoAngles[2] = 0;
1074
1075 cg.autoAnglesFast[0] = 0;
1076 cg.autoAnglesFast[1] = ( cg.time & 1023 ) * 360 / 1024.0f;
1077 cg.autoAnglesFast[2] = 0;
1078
1079 AnglesToAxis( cg.autoAngles, cg.autoAxis );
1080 AnglesToAxis( cg.autoAnglesFast, cg.autoAxisFast );
1081
1082 // generate and add the entity from the playerstate
1083 ps = &cg.predictedPlayerState;
1084 BG_PlayerStateToEntityState( ps, &cg.predictedPlayerEntity.currentState, qfalse );
1085 CG_AddCEntity( &cg.predictedPlayerEntity );
1086
1087 // lerp the non-predicted value for lightning gun origins
1088 CG_CalcEntityLerpPositions( &cg_entities[ cg.snap->ps.clientNum ] );
1089
1090 // add each entity sent over by the server
1091 for ( num = 0 ; num < cg.snap->numEntities ; num++ ) {
1092 cent = &cg_entities[ cg.snap->entities[ num ].number ];
1093 CG_AddCEntity( cent );
1094 }
1095 }
1096