Skip to content

Commit

Permalink
- fix Tanner camera passing through walls bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapyMan committed May 27, 2023
1 parent 5d0455a commit 685cee7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 91 deletions.
140 changes: 68 additions & 72 deletions src_rebuild/Game/C/bcollide.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,94 +668,90 @@ int CarBuildingCollision(CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop,
cd[1].vel.vz = 0;
cd[1].avel = 0;

if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
{
collided = bcollided2d(cd, &gCameraBoxOverlap);
}
else
{
collided = bcollided2d(cd);
collided = bcollided2d(cd, cp->controlType == CONTROL_TYPE_CAMERACOLLIDER ? &gCameraBoxOverlap : 0);

#if defined(COLLISION_DEBUG) && !defined(PSX)
extern int gShowCollisionDebug;
if (gShowCollisionDebug == 1)
{
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
extern int gShowCollisionDebug;
if (gShowCollisionDebug == 1)
{
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);

CVECTOR bbcv = { 0, 0, 250 };
CVECTOR rrcv = { 250, 0, 0 };
CVECTOR yycv = { 250, 250, 0 };
CVECTOR bbcv = { 0, 0, 250 };
CVECTOR rrcv = { 250, 0, 0 };
CVECTOR yycv = { 250, 250, 0 };

// show both box axes
{
VECTOR _zero = { 0 };
VECTOR b1p = cd[0].x;
VECTOR b2p = cd[1].x;
b2p.vy = b1p.vy;
// show both box axes
{
VECTOR _zero = { 0 };
VECTOR b1p = cd[0].x;
VECTOR b2p = cd[1].x;
b2p.vy = b1p.vy;

// show position to position
//Debug_AddLine(b1p1, b2p1, yycv);
// show position to position
//Debug_AddLine(b1p1, b2p1, yycv);

VECTOR b1ax[2] = { {0} , {0} };
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);
VECTOR b1ax[2] = { {0} , {0} };
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);

// show axis of body 1
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);
// show axis of body 1
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);

// display 2D box 1
{
int h = b1ax[0].vy;
VECTOR box_points[4] = {
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right

{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
};

Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
}
// display 2D box 1
{
int h = b1ax[0].vy;
VECTOR box_points[4] = {
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right

{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
};

Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
}

VECTOR b2ax[2] = { {0} , {0} };
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);
VECTOR b2ax[2] = { {0} , {0} };
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);

// show axis of body 2
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);
// show axis of body 2
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);

CVECTOR& collColor = collided ? rrcv : yycv;
CVECTOR& collColor = collided ? rrcv : yycv;

// display 2D box 2
{
int h = b2ax[0].vy;
VECTOR box_points[4] = {
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right

{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
};

Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
}
// display 2D box 2
{
int h = b2ax[0].vy;
VECTOR box_points[4] = {
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right

{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
};

Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
}
}
}
#endif

if (cp->controlType != CONTROL_TYPE_CAMERACOLLIDER)
{
if (collided)
{
bFindCollisionTime(cd, &collisionResult);
Expand Down
37 changes: 18 additions & 19 deletions src_rebuild/Game/C/objcoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ char lineClear(VECTOR *v1, VECTOR *v2)
dx = va.vx - (tempCO.pos.vx + FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]));
dz = va.vz - (tempCO.pos.vz + FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]));

box.slab[0].upper = collide->xsize / 2 +testRadius;
box.slab[0].upper = collide->xsize / 2 + testRadius;
box.slab[0].lower = -box.slab[0].upper;
box.slab[1].upper = collide->ysize / 2 +testRadius;

box.slab[1].upper = collide->ysize / 2 + testRadius;
box.slab[1].lower = -box.slab[1].upper;
box.slab[2].upper = collide->zsize / 2 +testRadius;

box.slab[2].upper = collide->zsize / 2 + testRadius;
box.slab[2].lower = -box.slab[2].upper;

ray.org[0] = FIXEDH(cs * dx - sn * dz);
Expand Down Expand Up @@ -606,7 +606,6 @@ void CheckScenaryCollisions(CAR_DATA *cp)
{
int count;
int num_cb;
int coll_test_count;
int yang;
int minDist;
COLLISION_PACKET *collide;
Expand Down Expand Up @@ -727,28 +726,28 @@ void CheckScenaryCollisions(CAR_DATA *cp)
}
else if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
{
if ((model->flags2 & (MODEL_FLAG_CHAIR | MODEL_FLAG_SMASHABLE)) == 0 &&
(bbox.xsize > 100 || (bbox.zsize > 100)))
if ((model->flags2 & (MODEL_FLAG_CHAIR | MODEL_FLAG_SMASHABLE)) == 0 && (bbox.xsize > 100 || bbox.zsize > 100))
{
coll_test_count = 5;

int diff;
int coll_test_count = 2; // [A] only two tests needed
int prevDistance = gCameraDistance;

bbox.xsize += 100;
bbox.zsize += 100;

gCameraBoxOverlap = -1;

minDist = lbody / 2;

while (coll_test_count > 0 && minDist <= gCameraDistance && CarBuildingCollision(cp, &bbox, cop, 0))
while (coll_test_count > 0 && gCameraDistance > minDist && CarBuildingCollision(cp, &bbox, cop, 0))
{
gCameraDistance -= gCameraBoxOverlap;

if (gCameraDistance < minDist)
gCameraDistance = minDist;

cp->hd.where.t[0] = car_data[0].hd.where.t[0] + FIXEDH((gCameraDistance * RSIN(cp->hd.direction)) / 2);
cp->hd.where.t[2] = car_data[0].hd.where.t[2] + FIXEDH((gCameraDistance * RCOS(cp->hd.direction)) / 2);

gCameraDistance = MAX(minDist, gCameraDistance - gCameraBoxOverlap);
diff = prevDistance - gCameraDistance;
prevDistance = gCameraDistance;

cp->hd.where.t[0] -= FIXEDH((diff * RSIN(cp->hd.direction)) / 2);
cp->hd.where.t[2] -= FIXEDH((diff * RCOS(cp->hd.direction)) / 2);

coll_test_count--;
}
}
Expand Down

0 comments on commit 685cee7

Please sign in to comment.