Skip to content

Commit 1d7fcbf

Browse files
authored
Merge pull request #79 from OpenDriver2/develop-SoapyMan
Optimizations & bug fixes
2 parents ee18dca + 981319b commit 1d7fcbf

File tree

7 files changed

+322
-321
lines changed

7 files changed

+322
-321
lines changed

src_rebuild/Game/C/camera.c

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -574,28 +574,7 @@ void PlaceCameraInCar(PLAYER *lp, int BumperCam)
574574

575575
viewer_position.vx = 0;
576576
viewer_position.vy = 0;
577-
578-
if (cp == NULL)
579-
{
580-
viewer_position.vz = 0;
581-
if(lp->pPed)
582-
viewer_position.vy += lp->pPed->head_pos;
583-
}
584-
else if (cp->ap.carCos != NULL) // [A] prevent crash from happening
585-
{
586-
viewer_position.vy = 7;
587-
viewer_position.vz = cp->ap.carCos->colBox.vz - 80;
588-
}
589-
590-
// [A] handle REDRIVER2 dedicated look back button
591-
if ((paddCamera & CAMERA_PAD_LOOK_BACK) == CAMERA_PAD_LOOK_BACK || (paddCamera & CAMERA_PAD_LOOK_BACK_DED))
592-
viewer_position.vz = 0;
593-
594-
angle = baseDir & 0xfff;
595-
596-
lp->cameraPos.vx = basePos[0] + FIXEDH(rcossin_tbl[angle * 2] * viewer_position.vz);
597-
lp->cameraPos.vy = viewer_position.vy - basePos[1];
598-
lp->cameraPos.vz = basePos[2] + FIXEDH(rcossin_tbl[angle * 2 + 1] * viewer_position.vz);
577+
viewer_position.vz = 0;
599578

600579
TurnHead(lp);
601580

@@ -605,61 +584,57 @@ void PlaceCameraInCar(PLAYER *lp, int BumperCam)
605584
else
606585
camera_angle.vy = (lp->headPos >> 16) - baseDir & 0xfff;
607586

608-
SetGeomScreen(scr_z = gCameraDefaultScrZ);
609-
610-
if (cp == NULL)
587+
if (cp)
611588
{
612-
ClearMem((char *)&inv_camera_matrix, sizeof(MATRIX));
589+
// build custom matrix using car draw matrix
590+
InvertMatrix(&cp->hd.drawCarMat, &inv_camera_matrix);
613591

614-
angle = 2048U - baseDir & 0xfff;
592+
if (!((paddCamera & CAMERA_PAD_LOOK_BACK) == CAMERA_PAD_LOOK_BACK || (paddCamera & CAMERA_PAD_LOOK_BACK_DED)))
593+
{
594+
viewer_position.vz += cp->ap.carCos->colBox.vz - 250;
615595

616-
inv_camera_matrix.m[0][0] = rcossin_tbl[angle * 2 + 1];
617-
inv_camera_matrix.m[0][2] = rcossin_tbl[angle * 2];
618-
inv_camera_matrix.m[1][1] = 4096;
619-
inv_camera_matrix.m[2][0] = -inv_camera_matrix.m[0][2];
620-
inv_camera_matrix.m[2][2] = inv_camera_matrix.m[0][0];
621-
}
622-
else
623-
{
624-
InvertMatrix(&cp->hd.drawCarMat, &inv_camera_matrix);
625-
}
596+
_RotMatrixY(&inv_camera_matrix, 2048);
597+
_RotMatrixY(&inv_camera_matrix, (lp->headPos >> 16));
598+
}
626599

627-
// [A] handle REDRIVER2 dedicated look back button
628-
if ((paddCamera & CAMERA_PAD_LOOK_BACK) == CAMERA_PAD_LOOK_BACK || (paddCamera & CAMERA_PAD_LOOK_BACK_DED))
629-
{
630-
if (cp != NULL)
631-
viewer_position.vz = 170;
600+
MulMatrix0(&aspect, &inv_camera_matrix, &inv_camera_matrix);
601+
InvertMatrix(&inv_camera_matrix, &camera_matrix);
602+
603+
face_camera_work.m[0][0] = ONE;
604+
face_camera_work.m[0][2] = 0;
605+
face_camera_work.m[2][0] = 0;
606+
face_camera_work.m[2][2] = ONE;
607+
608+
RotMatrixY(-(camera_angle.vy & 0xfff), &face_camera_work);
609+
MulMatrix0(&inv_camera_matrix, &face_camera_work, &face_camera);
610+
611+
viewer_position.vy = -40;
612+
613+
SetRotMatrix(&camera_matrix);
614+
_MatrixRotate(&viewer_position);
615+
616+
lp->cameraPos.vx = basePos[0] + viewer_position.vx;
617+
lp->cameraPos.vy = viewer_position.vy - basePos[1];
618+
lp->cameraPos.vz = basePos[2] + viewer_position.vz;
632619
}
633-
else
620+
else
634621
{
635-
_RotMatrixY(&inv_camera_matrix, 2048);
636-
_RotMatrixY(&inv_camera_matrix, (lp->headPos >> 16));
637-
638-
if (cp != NULL)
639-
viewer_position.vz = -170;
640-
else
641-
_RotMatrixX(&inv_camera_matrix, -tannerLookAngle.vx);
642-
}
643-
644-
MulMatrix0(&aspect, &inv_camera_matrix, &inv_camera_matrix);
645-
InvertMatrix(&inv_camera_matrix, &camera_matrix);
622+
camera_angle.vx = -tannerLookAngle.vx;
646623

647-
face_camera_work.m[0][0] = 4096;
648-
face_camera_work.m[0][2] = 0;
649-
face_camera_work.m[2][0] = 0;
650-
face_camera_work.m[2][2] = 4096;
624+
// pedestrian camera is much simpler
625+
BuildWorldMatrix();
651626

652-
RotMatrixY(-camera_angle.vy & 0xfff, &face_camera_work);
653-
MulMatrix0(&inv_camera_matrix, &face_camera_work, &face_camera);
627+
viewer_position.vy += lp->pPed->head_pos - 25;
628+
//viewer_position.vz += 45;
654629

655-
viewer_position.vy = -40;
630+
angle = -baseDir & 0xfff;
656631

657-
SetRotMatrix(&camera_matrix);
658-
_MatrixRotate(&viewer_position);
632+
lp->cameraPos.vx = basePos[0] + FIXEDH(rcossin_tbl[angle * 2] * viewer_position.vz);
633+
lp->cameraPos.vy = viewer_position.vy - basePos[1];
634+
lp->cameraPos.vz = basePos[2] - FIXEDH(rcossin_tbl[angle * 2 + 1] * viewer_position.vz);
635+
}
659636

660-
lp->cameraPos.vx += viewer_position.vx;
661-
lp->cameraPos.vy += viewer_position.vy;
662-
lp->cameraPos.vz += viewer_position.vz;
637+
SetGeomScreen(scr_z = gCameraDefaultScrZ);
663638

664639
switch_detail_distance = 10000;
665640
}

0 commit comments

Comments
 (0)