00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "revolt.h"
00018 #ifndef _PSX
00019 #include "main.h"
00020 #endif
00021 #include "geom.h"
00022 #include "particle.h"
00023 #include "model.h"
00024 #include "aerial.h"
00025 #include "newcoll.h"
00026 #include "body.h"
00027 #include "car.h"
00028 #include "ctrlread.h"
00029 #include "object.h"
00030 #include "control.h"
00031 #include "level.h"
00032 #include "player.h"
00033 #include "Field.h"
00034 #ifdef _PC
00035 #include "ghost.h"
00036 #endif
00037
00038
00039
00040
00041
00042 void MOV_MoveObjects(void);
00043 void MOV_MoveBody(OBJECT *bodyObj);
00044 void MOV_MoveCarNew(OBJECT *CarObj);
00045 void MOV_MoveGhost(OBJECT *CarObj);
00046 void MOV_MoveTrain(OBJECT *obj);
00047
00048
00049
00051
00053
00054 void MOV_MoveObjects(void)
00055 {
00056 OBJECT *obj;
00057
00058 for (obj = OBJ_ObjectHead; obj; obj = obj->next)
00059 {
00060 if (obj->movehandler && obj->flag.Move)
00061 {
00062 obj->movehandler(obj);
00063 }
00064 obj->renderflag.visible = FALSE;
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 void MOV_MoveBody(OBJECT *bodyObj)
00136 {
00137 UpdateBody(&bodyObj->body, TimeStep);
00138 }
00139
00140 void MOV_MoveCarNew(OBJECT *carObj)
00141 {
00142 int iWheel, nPowered;
00143 CAR *car = &carObj->player->car;
00144
00145 Assert(carObj->Type == OBJECT_TYPE_CAR || carObj->Type == OBJECT_TYPE_TROLLEY);
00146
00147
00148 UpdateBody(car->Body, TimeStep);
00149 CopyBBox(&car->Body->CollSkin.BBox, &car->BBox);
00150
00151
00152 car->Revs = ZERO;
00153 nPowered = 0;
00154 for (iWheel = 0; iWheel < CAR_NWHEELS; iWheel++) {
00155 if (IsWheelPresent(&car->Wheel[iWheel])) {
00156 UpdateCarWheel(car, iWheel, TimeStep);
00157 AddPosRadToBBox(&car->BBox, &car->Wheel[iWheel].CentrePos, car->Wheel[iWheel].Radius);
00158 }
00159
00160 if (IsWheelPowered(&car->Wheel[iWheel])) {
00161 car->Revs += car->Wheel[iWheel].AngVel;
00162 nPowered++;
00163 }
00164 }
00165 if (nPowered > 0) {
00166 car->Revs /= nPowered;
00167 }
00168 #ifdef _PC
00169 if (carObj->player->type == PLAYER_REMOTE) {
00170 UpdateRemotePlayer(carObj->player);
00171 }
00172 #endif
00173
00174
00175 UpdateCarAerial2(car, TimeStep);
00176 }
00177
00178 void MOV_RightCar(OBJECT *obj)
00179 {
00180 int iWheel;
00181 REAL lookLen;
00182 VEC dR;
00183 MAT mat;
00184 CAR *car = &obj->player->car;
00185
00186 Assert(obj->Type == OBJECT_TYPE_CAR);
00187
00188
00189 if (!car->Righting) {
00190
00191
00192 VecPlusScalarVec(&car->Body->Centre.Pos, TO_LENGTH(Real(50)), &UpVec, &car->DestPos);
00193
00194
00195 SetVec(&mat.mv[L], car->Body->Centre.WMatrix.m[LX], ZERO, car->Body->Centre.WMatrix.m[LZ]);
00196 lookLen = VecLen(&mat.mv[L]);
00197 if (lookLen > SMALL_REAL) {
00198 VecDivScalar(&mat.mv[L], lookLen);
00199 } else {
00200 SetVec(&mat.mv[L], ONE, ZERO, ZERO);
00201 }
00202
00203
00204 CopyVec(&DownVec, &mat.mv[U]);
00205 VecCrossVec(&mat.mv[U], &mat.mv[L], &mat.mv[R]);
00206
00207
00208 MatToQuat(&mat, &car->DestQuat);
00209
00210
00211 car->Righting = TRUE;
00212 }
00213
00214
00215 SetVecZero(&car->Body->Centre.Vel);
00216 SetVecZero(&car->Body->Centre.Impulse);
00217 SetVecZero(&car->Body->AngVel);
00218 SetVecZero(&car->Body->AngImpulse);
00219 if (!car->RightingCollide) {
00220 SetVecZero(&car->Body->Centre.Shift);
00221 }
00222
00223
00224 VecMinusVec(&car->DestPos, &car->Body->Centre.Pos, &dR);
00225 #ifndef _PSX
00226 VecPlusEqScalarVec(&car->Body->Centre.Pos, TimeStep * 10, &dR);
00227 SLerpQuat(&car->Body->Centre.Quat, &car->DestQuat, TimeStep * 3, &car->Body->Centre.Quat);
00228 #else
00229 VecPlusEqScalarVec(&car->Body->Centre.Pos, Real(0.12), &dR);
00230 LerpQuat(&car->Body->Centre.Quat, &car->DestQuat, Real(0.12), &car->Body->Centre.Quat);
00231 #endif
00232 UpdateBody(car->Body, TimeStep);
00233
00234 for (iWheel = 0; iWheel < CAR_NWHEELS; iWheel++) {
00235 if (IsWheelPresent(&car->Wheel[iWheel])) {
00236 UpdateCarWheel(car, iWheel, TimeStep);
00237 }
00238 }
00239 car->Revs = ZERO;
00240
00241
00242 UpdateCarAerial2(car, TimeStep);
00243
00244
00245 if (car->RightingReachDest) {
00246 VecMinusVec(&car->Body->Centre.OldPos, &car->Body->Centre.Pos, &dR);
00247 } else {
00248 SetVecZero(&dR);
00249 }
00250 if ((VecDotVec(&dR, &dR) < SMALL_REAL) &&
00251 (QuatDotQuat(&car->Body->Centre.Quat, &car->DestQuat) > Real(0.9999)))
00252 {
00253 car->Righting = FALSE;
00254 obj->movehandler = (MOVE_HANDLER)MOV_MoveCarNew;
00255 }
00256 }
00257
00258 #ifdef _PC
00259 void MOV_MoveGhost(OBJECT *CarObj)
00260 {
00261
00262 InterpGhostData(&CarObj->player->car);
00263
00264
00265 UpdateCarAerial2(&CarObj->player->car, TimeStep);
00266 }
00267 #endif
00268
00269 void MOV_MoveTrain(OBJECT *obj)
00270 {
00271 VEC vec;
00272
00273
00274 CopyVec(&obj->body.Centre.Pos, &obj->body.Centre.OldPos);
00275 obj->body.Centre.Pos.v[Z] -= TimeStep * 200.0f;
00276 if (obj->body.Centre.Pos.v[Z] < -11500)
00277 obj->body.Centre.Pos.v[Z] = -400;
00278 VecMinusVec(&obj->body.Centre.Pos, &obj->body.Centre.OldPos, &vec);
00279 TransCollPolys(obj->body.CollSkin.CollPoly, obj->body.CollSkin.NCollPolys, &vec);
00280
00281
00282 BuildWorldSkin(&obj->body.CollSkin, &obj->body.Centre.Pos, &obj->body.Centre.WMatrix);
00283
00284 }
00285
00286