Skip to content

Commit 685cee7

Browse files
committed
- fix Tanner camera passing through walls bug
1 parent 5d0455a commit 685cee7

2 files changed

Lines changed: 86 additions & 91 deletions

File tree

src_rebuild/Game/C/bcollide.c

Lines changed: 68 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -668,94 +668,90 @@ int CarBuildingCollision(CAR_DATA *cp, BUILDING_BOX *building, CELL_OBJECT *cop,
668668
cd[1].vel.vz = 0;
669669
cd[1].avel = 0;
670670

671-
if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
672-
{
673-
collided = bcollided2d(cd, &gCameraBoxOverlap);
674-
}
675-
else
676-
{
677-
collided = bcollided2d(cd);
671+
collided = bcollided2d(cd, cp->controlType == CONTROL_TYPE_CAMERACOLLIDER ? &gCameraBoxOverlap : 0);
678672

679673
#if defined(COLLISION_DEBUG) && !defined(PSX)
680-
extern int gShowCollisionDebug;
681-
if (gShowCollisionDebug == 1)
682-
{
683-
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
684-
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
674+
extern int gShowCollisionDebug;
675+
if (gShowCollisionDebug == 1)
676+
{
677+
extern void Debug_AddLine(VECTOR & pointA, VECTOR & pointB, CVECTOR & color);
678+
extern void Debug_AddLineOfs(VECTOR & pointA, VECTOR & pointB, VECTOR & ofs, CVECTOR & color);
685679

686-
CVECTOR bbcv = { 0, 0, 250 };
687-
CVECTOR rrcv = { 250, 0, 0 };
688-
CVECTOR yycv = { 250, 250, 0 };
680+
CVECTOR bbcv = { 0, 0, 250 };
681+
CVECTOR rrcv = { 250, 0, 0 };
682+
CVECTOR yycv = { 250, 250, 0 };
689683

690-
// show both box axes
691-
{
692-
VECTOR _zero = { 0 };
693-
VECTOR b1p = cd[0].x;
694-
VECTOR b2p = cd[1].x;
695-
b2p.vy = b1p.vy;
684+
// show both box axes
685+
{
686+
VECTOR _zero = { 0 };
687+
VECTOR b1p = cd[0].x;
688+
VECTOR b2p = cd[1].x;
689+
b2p.vy = b1p.vy;
696690

697-
// show position to position
698-
//Debug_AddLine(b1p1, b2p1, yycv);
691+
// show position to position
692+
//Debug_AddLine(b1p1, b2p1, yycv);
699693

700-
VECTOR b1ax[2] = { {0} , {0} };
701-
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
702-
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
703-
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
704-
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);
694+
VECTOR b1ax[2] = { {0} , {0} };
695+
b1ax[0].vx = FIXEDH(cd[0].axis[0].vx * cd[0].length[0]);
696+
b1ax[0].vz = FIXEDH(cd[0].axis[0].vz * cd[0].length[0]);
697+
b1ax[1].vx = FIXEDH(cd[0].axis[1].vx * cd[0].length[1]);
698+
b1ax[1].vz = FIXEDH(cd[0].axis[1].vz * cd[0].length[1]);
705699

706-
// show axis of body 1
707-
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
708-
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);
700+
// show axis of body 1
701+
Debug_AddLineOfs(_zero, b1ax[0], b1p, rrcv);
702+
Debug_AddLineOfs(_zero, b1ax[1], b1p, yycv);
709703

710-
// display 2D box 1
711-
{
712-
int h = b1ax[0].vy;
713-
VECTOR box_points[4] = {
714-
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
715-
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right
716-
717-
{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
718-
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
719-
};
720-
721-
Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
722-
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
723-
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
724-
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
725-
}
704+
// display 2D box 1
705+
{
706+
int h = b1ax[0].vy;
707+
VECTOR box_points[4] = {
708+
{b1ax[0].vx - b1ax[1].vx, h, b1ax[0].vz - b1ax[1].vz, 0}, // front left
709+
{b1ax[0].vx + b1ax[1].vx, h, b1ax[0].vz + b1ax[1].vz, 0}, // front right
710+
711+
{-b1ax[0].vx + b1ax[1].vx, h, -b1ax[0].vz + b1ax[1].vz, 0}, // back right
712+
{-b1ax[0].vx - b1ax[1].vx, h, -b1ax[0].vz - b1ax[1].vz, 0} // back left
713+
};
714+
715+
Debug_AddLineOfs(box_points[0], box_points[1], b1p, bbcv);
716+
Debug_AddLineOfs(box_points[1], box_points[2], b1p, bbcv);
717+
Debug_AddLineOfs(box_points[2], box_points[3], b1p, bbcv);
718+
Debug_AddLineOfs(box_points[3], box_points[0], b1p, bbcv);
719+
}
726720

727-
VECTOR b2ax[2] = { {0} , {0} };
728-
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
729-
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
730-
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
731-
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);
721+
VECTOR b2ax[2] = { {0} , {0} };
722+
b2ax[0].vx += FIXEDH(cd[1].axis[0].vx * cd[1].length[0]);
723+
b2ax[0].vz += FIXEDH(cd[1].axis[0].vz * cd[1].length[0]);
724+
b2ax[1].vx += FIXEDH(cd[1].axis[1].vx * cd[1].length[1]);
725+
b2ax[1].vz += FIXEDH(cd[1].axis[1].vz * cd[1].length[1]);
732726

733-
// show axis of body 2
734-
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
735-
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);
727+
// show axis of body 2
728+
Debug_AddLineOfs(_zero, b2ax[0], b2p, rrcv);
729+
Debug_AddLineOfs(_zero, b2ax[1], b2p, yycv);
736730

737-
CVECTOR& collColor = collided ? rrcv : yycv;
731+
CVECTOR& collColor = collided ? rrcv : yycv;
738732

739-
// display 2D box 2
740-
{
741-
int h = b2ax[0].vy;
742-
VECTOR box_points[4] = {
743-
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
744-
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right
745-
746-
{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
747-
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
748-
};
749-
750-
Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
751-
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
752-
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
753-
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
754-
}
733+
// display 2D box 2
734+
{
735+
int h = b2ax[0].vy;
736+
VECTOR box_points[4] = {
737+
{b2ax[0].vx - b2ax[1].vx, h, b2ax[0].vz - b2ax[1].vz, 0}, // front left
738+
{b2ax[0].vx + b2ax[1].vx, h, b2ax[0].vz + b2ax[1].vz, 0}, // front right
739+
740+
{-b2ax[0].vx + b2ax[1].vx, h, -b2ax[0].vz + b2ax[1].vz, 0}, // back right
741+
{-b2ax[0].vx - b2ax[1].vx, h, -b2ax[0].vz - b2ax[1].vz, 0} // back left
742+
};
743+
744+
Debug_AddLineOfs(box_points[0], box_points[1], b2p, collColor);
745+
Debug_AddLineOfs(box_points[1], box_points[2], b2p, collColor);
746+
Debug_AddLineOfs(box_points[2], box_points[3], b2p, collColor);
747+
Debug_AddLineOfs(box_points[3], box_points[0], b2p, collColor);
755748
}
756749
}
750+
}
757751
#endif
758752

753+
if (cp->controlType != CONTROL_TYPE_CAMERACOLLIDER)
754+
{
759755
if (collided)
760756
{
761757
bFindCollisionTime(cd, &collisionResult);

src_rebuild/Game/C/objcoll.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ char lineClear(VECTOR *v1, VECTOR *v2)
396396
dx = va.vx - (tempCO.pos.vx + FIXEDH(collide->xpos * mat->m[0][0] + collide->zpos * mat->m[2][0]));
397397
dz = va.vz - (tempCO.pos.vz + FIXEDH(collide->xpos * mat->m[0][2] + collide->zpos * mat->m[2][2]));
398398

399-
box.slab[0].upper = collide->xsize / 2 +testRadius;
399+
box.slab[0].upper = collide->xsize / 2 + testRadius;
400400
box.slab[0].lower = -box.slab[0].upper;
401-
402-
box.slab[1].upper = collide->ysize / 2 +testRadius;
401+
402+
box.slab[1].upper = collide->ysize / 2 + testRadius;
403403
box.slab[1].lower = -box.slab[1].upper;
404-
405-
box.slab[2].upper = collide->zsize / 2 +testRadius;
404+
405+
box.slab[2].upper = collide->zsize / 2 + testRadius;
406406
box.slab[2].lower = -box.slab[2].upper;
407407

408408
ray.org[0] = FIXEDH(cs * dx - sn * dz);
@@ -606,7 +606,6 @@ void CheckScenaryCollisions(CAR_DATA *cp)
606606
{
607607
int count;
608608
int num_cb;
609-
int coll_test_count;
610609
int yang;
611610
int minDist;
612611
COLLISION_PACKET *collide;
@@ -727,28 +726,28 @@ void CheckScenaryCollisions(CAR_DATA *cp)
727726
}
728727
else if (cp->controlType == CONTROL_TYPE_CAMERACOLLIDER)
729728
{
730-
if ((model->flags2 & (MODEL_FLAG_CHAIR | MODEL_FLAG_SMASHABLE)) == 0 &&
731-
(bbox.xsize > 100 || (bbox.zsize > 100)))
729+
if ((model->flags2 & (MODEL_FLAG_CHAIR | MODEL_FLAG_SMASHABLE)) == 0 && (bbox.xsize > 100 || bbox.zsize > 100))
732730
{
733-
coll_test_count = 5;
734-
731+
int diff;
732+
int coll_test_count = 2; // [A] only two tests needed
733+
int prevDistance = gCameraDistance;
734+
735735
bbox.xsize += 100;
736736
bbox.zsize += 100;
737737

738738
gCameraBoxOverlap = -1;
739739

740740
minDist = lbody / 2;
741741

742-
while (coll_test_count > 0 && minDist <= gCameraDistance && CarBuildingCollision(cp, &bbox, cop, 0))
742+
while (coll_test_count > 0 && gCameraDistance > minDist && CarBuildingCollision(cp, &bbox, cop, 0))
743743
{
744-
gCameraDistance -= gCameraBoxOverlap;
745-
746-
if (gCameraDistance < minDist)
747-
gCameraDistance = minDist;
748-
749-
cp->hd.where.t[0] = car_data[0].hd.where.t[0] + FIXEDH((gCameraDistance * RSIN(cp->hd.direction)) / 2);
750-
cp->hd.where.t[2] = car_data[0].hd.where.t[2] + FIXEDH((gCameraDistance * RCOS(cp->hd.direction)) / 2);
751-
744+
gCameraDistance = MAX(minDist, gCameraDistance - gCameraBoxOverlap);
745+
diff = prevDistance - gCameraDistance;
746+
prevDistance = gCameraDistance;
747+
748+
cp->hd.where.t[0] -= FIXEDH((diff * RSIN(cp->hd.direction)) / 2);
749+
cp->hd.where.t[2] -= FIXEDH((diff * RCOS(cp->hd.direction)) / 2);
750+
752751
coll_test_count--;
753752
}
754753
}

0 commit comments

Comments
 (0)