mirror of
https://github.com/OpenDriver2/REDRIVER2.git
synced 2024-11-25 11:52:32 +01:00
- little refactor
This commit is contained in:
parent
1d182b0cc6
commit
cee65e7324
@ -2,11 +2,10 @@
|
||||
#include "bcoll3d.h"
|
||||
|
||||
// [D] [T]
|
||||
void PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int nSign)
|
||||
int PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int nSign)
|
||||
{
|
||||
int partialDepth;
|
||||
int depth;
|
||||
SVECTOR_NOPAD *radii;
|
||||
int partialDepth, depth;
|
||||
SVECTOR_NOPAD* radii;
|
||||
int k;
|
||||
|
||||
VECTOR normal;
|
||||
@ -27,13 +26,13 @@ void PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int
|
||||
|
||||
depth = FIXEDH(diff.vx * normal.vx + diff.vy * normal.vy + diff.vz * normal.vz);
|
||||
|
||||
if (depth < 0)
|
||||
if (depth < 0)
|
||||
{
|
||||
normal.vx = -normal.vx;
|
||||
normal.vy = -normal.vy;
|
||||
normal.vz = -normal.vz;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
depth = -depth;
|
||||
}
|
||||
@ -41,20 +40,19 @@ void PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int
|
||||
radii = cp1->hd.oBox.radii;
|
||||
depth += cp0->hd.oBox.length[i];
|
||||
|
||||
k = 2;
|
||||
|
||||
do {
|
||||
diff.vx = radii->vx;
|
||||
diff.vy = radii->vy;
|
||||
diff.vz = radii->vz;
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
diff.vx = radii[k].vx;
|
||||
diff.vy = radii[k].vy;
|
||||
diff.vz = radii[k].vz;
|
||||
|
||||
partialDepth = FIXEDH(diff.vx * normal.vx + diff.vy * normal.vy + diff.vz * normal.vz);
|
||||
|
||||
if (partialDepth < 0)
|
||||
if (partialDepth < 0)
|
||||
{
|
||||
partialDepth = -partialDepth;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
diff.vx = -diff.vx;
|
||||
diff.vy = -diff.vy;
|
||||
@ -66,55 +64,63 @@ void PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int
|
||||
point.vz += diff.vz;
|
||||
|
||||
depth += partialDepth;
|
||||
}
|
||||
|
||||
radii++;
|
||||
k--;
|
||||
} while (k >= 0);
|
||||
|
||||
if (depth < least->depth && (least->depth = depth, -1 < depth))
|
||||
if (depth < least->depth)
|
||||
{
|
||||
least->location.vx = point.vx;
|
||||
least->location.vy = point.vy;
|
||||
least->location.vz = point.vz;
|
||||
least->depth = depth;
|
||||
|
||||
if (nSign < 0)
|
||||
if (depth >= 0)
|
||||
{
|
||||
normal.vx = -normal.vx;
|
||||
normal.vy = -normal.vy;
|
||||
normal.vz = -normal.vz;
|
||||
least->location.vx = point.vx;
|
||||
least->location.vy = point.vy;
|
||||
least->location.vz = point.vz;
|
||||
|
||||
if (nSign < 0)
|
||||
{
|
||||
normal.vx = -normal.vx;
|
||||
normal.vy = -normal.vy;
|
||||
normal.vz = -normal.vz;
|
||||
}
|
||||
|
||||
least->normal.vx = normal.vx;
|
||||
least->normal.vy = normal.vy;
|
||||
least->normal.vz = normal.vz;
|
||||
}
|
||||
|
||||
least->normal.vx = normal.vx;
|
||||
least->normal.vy = normal.vy;
|
||||
least->normal.vz = normal.vz;
|
||||
return depth;
|
||||
}
|
||||
|
||||
return least->depth;
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
int collided3d(CAR_DATA *cp0, CAR_DATA *cp1, TestResult *least)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
least->depth = 0x40000000;
|
||||
PointFaceCheck(cp0, cp1, 1, least, 1);
|
||||
|
||||
if (least->depth > -1 && (PointFaceCheck(cp1, cp0, 1, least, -1), least->depth > -1))
|
||||
// check up-down first
|
||||
if (PointFaceCheck(cp0, cp1, 1, least, 1) >= 0 &&
|
||||
PointFaceCheck(cp1, cp0, 1, least, -1) >= 0)
|
||||
{
|
||||
least->depth = 0x40000000;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (PointFaceCheck(cp0, cp1, i, least, 1), least->depth > -1)
|
||||
// check sides
|
||||
while (PointFaceCheck(cp0, cp1, i, least, 1) >= 0)
|
||||
{
|
||||
PointFaceCheck(cp1, cp0, i, least, -1);
|
||||
if (PointFaceCheck(cp1, cp0, i, least, -1) >= 0)
|
||||
{
|
||||
i += 2;
|
||||
|
||||
i += 2;
|
||||
|
||||
if (least->depth < 0)
|
||||
return 0;
|
||||
|
||||
if (i > 2)
|
||||
if (i <= 2)
|
||||
continue;
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,12 +135,14 @@ int CarCarCollision3(CAR_DATA *c0, CAR_DATA *c1, int *depth, VECTOR *where, VECT
|
||||
|
||||
res = collided3d(c0, c1, &tr);
|
||||
|
||||
if (res != 0)
|
||||
if (res)
|
||||
{
|
||||
*depth = tr.depth;
|
||||
|
||||
where->vx = tr.location.vx;
|
||||
where->vy = tr.location.vy;
|
||||
where->vz = tr.location.vz;
|
||||
|
||||
normal->vx = tr.normal.vx;
|
||||
normal->vy = tr.normal.vy;
|
||||
normal->vz = tr.normal.vz;
|
||||
|
@ -1,11 +1,6 @@
|
||||
#ifndef BCOLL3D_H
|
||||
#define BCOLL3D_H
|
||||
|
||||
|
||||
extern void PointFaceCheck(CAR_DATA *cp0, CAR_DATA *cp1, int i, TestResult *least, int nSign); // 0x0001C160
|
||||
|
||||
extern int collided3d(CAR_DATA *cp0, CAR_DATA *cp1, TestResult *least); // 0x0001C408
|
||||
|
||||
extern int CarCarCollision3(CAR_DATA *c0, CAR_DATA *c1, int *depth, VECTOR *where, VECTOR *normal); // 0x0001C380
|
||||
|
||||
|
||||
|
@ -318,10 +318,8 @@ void GlobalTimeStep(void)
|
||||
StepCars();
|
||||
CheckCarToCarCollisions();
|
||||
|
||||
i = 0;
|
||||
|
||||
// step car forces (when no collisions with them)
|
||||
while (i < num_active_cars)
|
||||
for (i = 0; i < num_active_cars; i++)
|
||||
{
|
||||
cp = active_car_list[i];
|
||||
|
||||
@ -397,17 +395,14 @@ void GlobalTimeStep(void)
|
||||
|
||||
RebuildCarMatrix(st, cp);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
subframe = 0;
|
||||
|
||||
// do collision interactions
|
||||
do {
|
||||
for(subframe = 0; subframe < 4; subframe++)
|
||||
{
|
||||
RKstep = 0;
|
||||
|
||||
do {
|
||||
for (RKstep = 0; RKstep < 2; RKstep++) {
|
||||
for (i = 0; i < num_active_cars; i++)
|
||||
{
|
||||
cp = active_car_list[i];
|
||||
@ -500,9 +495,9 @@ void GlobalTimeStep(void)
|
||||
pointVel0[2] = (FIXEDH(thisState_i->n.angularVelocity[0] * lever0[1] - thisState_i->n.angularVelocity[1] * lever0[0]) + thisState_i->n.linearVelocity[2]) -
|
||||
(FIXEDH(thisState_j->n.angularVelocity[0] * lever1[1] - thisState_j->n.angularVelocity[1] * lever1[0]) + thisState_j->n.linearVelocity[2]);
|
||||
|
||||
howHard = (pointVel0[0] / 256) * (normal[0] / 32) +
|
||||
(pointVel0[1] / 256) * (normal[1] / 32) +
|
||||
(pointVel0[2] / 256) * (normal[2] / 32);
|
||||
howHard = (pointVel0[0] / 256) * (normal[0] / 32) +
|
||||
(pointVel0[1] / 256) * (normal[1] / 32) +
|
||||
(pointVel0[2] / 256) * (normal[2] / 32);
|
||||
|
||||
if (howHard > 0 && RKstep > -1)
|
||||
{
|
||||
@ -693,9 +688,7 @@ void GlobalTimeStep(void)
|
||||
}
|
||||
|
||||
// update forces and rebuild matrix of the cars
|
||||
i = 0;
|
||||
|
||||
while (i < num_active_cars)
|
||||
for (i = 0; i < num_active_cars; i++)
|
||||
{
|
||||
cp = active_car_list[i];
|
||||
|
||||
@ -709,44 +702,34 @@ void GlobalTimeStep(void)
|
||||
|
||||
if (RKstep == 0)
|
||||
{
|
||||
j = 0;
|
||||
do {
|
||||
for (j = 0; j < 13; j++)
|
||||
{
|
||||
tp->v[j] = st->v[j] + (d0->v[j] >> 2);
|
||||
j++;
|
||||
} while (j < 13);
|
||||
}
|
||||
|
||||
RebuildCarMatrix(tp, cp);
|
||||
}
|
||||
else if (RKstep == 1)
|
||||
{
|
||||
j = 0;
|
||||
do {
|
||||
for (j = 0; j < 13; j++)
|
||||
{
|
||||
st->v[j] += d0->v[j] + d1->v[j] >> 3;
|
||||
j++;
|
||||
} while (j < 13);
|
||||
}
|
||||
|
||||
RebuildCarMatrix(st, cp);
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
RKstep++;
|
||||
|
||||
} while (RKstep < 2);
|
||||
|
||||
subframe++;
|
||||
} while (subframe < 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// second sub frame passed, update matrices and physics direction
|
||||
// dent cars - no more than 5 cars in per frame
|
||||
i = 0;
|
||||
carsDentedThisFrame = 0;
|
||||
|
||||
while (i < num_active_cars)
|
||||
for (i = 0; i < num_active_cars; i++)
|
||||
{
|
||||
cp = active_car_list[i];
|
||||
|
||||
@ -760,7 +743,6 @@ void GlobalTimeStep(void)
|
||||
carsDentedThisFrame++;
|
||||
}
|
||||
|
||||
i++;
|
||||
cp->hd.direction = ratan2(cp->hd.where.m[0][2], cp->hd.where.m[2][2]);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define GAME_VERSION_N "6.0 alpha"
|
||||
#define GAME_VERSION_N "6.4 alpha"
|
||||
#define GAME_TITLE "REDRIVER2"
|
||||
#define GAME_VERSION GAME_TITLE " " GAME_VERSION_N
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user