1 #include "client.h"
2 #include "localent.h"
3
4 /*
5 ==================
6 ClipVelocity
7
8 Slide off of the impacting object
9 returns the blocked flags (1 = floor, 2 = step / wall)
10 ==================
11 */
12 #define STOP_EPSILON 0.1
13
ClipVelocity(vec3_t in,vec3_t normal,vec3_t out,float overbounce)14 int ClipVelocity (vec3_t in, vec3_t normal, vec3_t out, float overbounce)
15 {
16 float backoff;
17 float change;
18 int i, blocked;
19
20 blocked = 0;
21
22 if (FLOAT_GT_ZERO(normal[2]))
23 blocked |= 1; // floor
24
25 if (!normal[2])
26 blocked |= 2; // step
27
28 backoff = DotProduct (in, normal) * overbounce;
29
30 for (i=0 ; i<3 ; i++)
31 {
32 change = normal[i]*backoff;
33 out[i] = in[i] - change;
34 if (out[i] > -STOP_EPSILON && out[i] < STOP_EPSILON)
35 out[i] = 0;
36 }
37
38 return blocked;
39 }
40
41 void CL_ClipMoveToEntities ( vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr );
LE_Physics_Toss(localent_t * ent)42 void LE_Physics_Toss (localent_t *ent)
43 {
44 trace_t tr;
45 vec3_t vel;
46
47 //copy old origin
48 FastVectorCopy (ent->ent.origin, ent->ent.oldorigin);
49
50 //FIXME: properly scale this to client FPS.
51 ent->velocity[2] -= 1;
52
53 //scale velocity based on something stupid
54 FastVectorCopy (ent->velocity, vel);
55 VectorScale (vel, cl.lerpfrac, vel);
56
57 //add velocity to origin
58 VectorAdd (ent->ent.origin, vel, ent->ent.origin);
59
60 //check we didn't hit the world
61 tr = CM_BoxTrace (ent->ent.oldorigin, ent->ent.origin, ent->mins, ent->maxs, 0, MASK_SOLID);
62 if (tr.fraction != 1.0f)
63 {
64 //vec3_t down;
65 //if we did, back off.
66 FastVectorCopy (tr.endpos, ent->ent.origin);
67 if (ent->touch)
68 ent->touch (ent, &tr.plane, tr.surface);
69
70 //check for stop
71 ClipVelocity (ent->velocity, tr.plane.normal, ent->velocity, ent->movetype == MOVETYPE_BOUNCE ? 1.7f : 1.0f);
72
73 if ((tr.plane.normal[2] > 0.7f && ent->movetype == MOVETYPE_TOSS) || ((ent->velocity[2] < 0.01f && ent->velocity[2] > -0.01f) && ent->movetype == MOVETYPE_BOUNCE))
74 ent->movetype = MOVETYPE_NONE;
75 }
76
77 //note!! this only clips to entities that we currently know about (as the client).
78 //this means if a localent is outside the PVS of a client, it will only clip to
79 //the world.
80
81 //fixme: do we want this?
82 /*CL_ClipMoveToEntities (ent->ent.oldorigin, ent->mins, ent->maxs, ent->ent.origin, &tr);
83 if (tr.ent) {
84 if (ent->touch)
85 ent->touch (ent, &tr.plane, tr.surface);
86
87 VectorCopy (tr.endpos, ent->ent.origin);
88
89 //check for stop
90 ClipVelocity (ent->velocity, tr.plane.normal, ent->velocity, ent->movetype == MOVETYPE_BOUNCE ? 1.7 : 1);
91
92 if (tr.plane.normal[2] > 0.7f && ent->movetype == MOVETYPE_TOSS || ((ent->velocity[2] < 0.01f && ent->velocity[2] > -0.01f) && ent->movetype == MOVETYPE_BOUNCE))
93 ent->movetype = MOVETYPE_NONE;
94
95 }*/
96 }
97
98 /*void LE_Physics_Fly (localent_t *ent)
99 {
100
101 }*/
102
LE_RunEntity(localent_t * ent)103 void LE_RunEntity (localent_t *ent)
104 {
105 switch (ent->movetype)
106 {
107 case MOVETYPE_NONE:
108 break;
109 case MOVETYPE_TOSS:
110 case MOVETYPE_BOUNCE:
111 LE_Physics_Toss (ent);
112 break;
113 case MOVETYPE_FLYMISSILE:
114 //LE_Physics_Fly (ent);
115 break;
116 default:
117 Com_Printf ("LE_RunEntity: bad movetype %i", LOG_CLIENT, ent->movetype);
118 }
119
120 if (ent->think && cl.time >= ent->nextthink )
121 ent->think (ent);
122
123 //if (ent->ent.flags & EF_GIB)
124 // CL_DiminishingTrail (ent->ent.oldorigin, ent->ent.origin, ent->ent, ent->ent.flags);
125 }
126