Merge pull request #2001 from pacomont/Let's_appling_Camera_FX_when_mount_on_driver_position

Why not apply Camera FX on vehicle driver position?
This commit is contained in:
Areloch 2017-05-15 00:58:11 -05:00 committed by GitHub
commit 726790bacf

View file

@ -1009,23 +1009,24 @@ void Vehicle::getCameraParameters(F32 *min,F32* max,Point3F* off,MatrixF* rot)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void Vehicle::getCameraTransform(F32* pos,MatrixF* mat) void Vehicle::getCameraTransform(F32* pos, MatrixF* mat)
{ {
// Returns camera to world space transform // Returns camera to world space transform
// Handles first person / third person camera position // Handles first person / third person camera position
if (isServerObject() && mShapeInstance) if (isServerObject() && mShapeInstance)
mShapeInstance->animateNodeSubtrees(true); mShapeInstance->animateNodeSubtrees(true);
if (*pos == 0) { if (*pos == 0)
{
getRenderEyeTransform(mat); getRenderEyeTransform(mat);
return;
} }
else
{
// Get the shape's camera parameters. // Get the shape's camera parameters.
F32 min,max; F32 min, max;
MatrixF rot; MatrixF rot;
Point3F offset; Point3F offset;
getCameraParameters(&min,&max,&offset,&rot); getCameraParameters(&min, &max, &offset, &rot);
// Start with the current eye position // Start with the current eye position
MatrixF eye; MatrixF eye;
@ -1034,39 +1035,39 @@ void Vehicle::getCameraTransform(F32* pos,MatrixF* mat)
// Build a transform that points along the eye axis // Build a transform that points along the eye axis
// but where the Z axis is always up. // but where the Z axis is always up.
if (mDataBlock->cameraRoll) if (mDataBlock->cameraRoll)
mat->mul(eye,rot); mat->mul(eye, rot);
else else
{ {
MatrixF cam(1); MatrixF cam(1);
VectorF x,y,z(0,0,1); VectorF x, y, z(0, 0, 1);
eye.getColumn(1, &y); eye.getColumn(1, &y);
mCross(y, z, &x); mCross(y, z, &x);
x.normalize(); x.normalize();
mCross(x, y, &z); mCross(x, y, &z);
z.normalize(); z.normalize();
cam.setColumn(0,x); cam.setColumn(0, x);
cam.setColumn(1,y); cam.setColumn(1, y);
cam.setColumn(2,z); cam.setColumn(2, z);
mat->mul(cam,rot); mat->mul(cam, rot);
} }
// Camera is positioned straight back along the eye's -Y axis. // Camera is positioned straight back along the eye's -Y axis.
// A ray is cast to make sure the camera doesn't go through // A ray is cast to make sure the camera doesn't go through
// anything solid. // anything solid.
VectorF vp,vec; VectorF vp, vec;
vp.x = vp.z = 0; vp.x = vp.z = 0;
vp.y = -(max - min) * *pos; vp.y = -(max - min) * *pos;
eye.mulV(vp,&vec); eye.mulV(vp, &vec);
// Use the camera node as the starting position if it exists. // Use the camera node as the starting position if it exists.
Point3F osp,sp; Point3F osp, sp;
if (mDataBlock->cameraNode != -1) if (mDataBlock->cameraNode != -1)
{ {
mShapeInstance->mNodeTransforms[mDataBlock->cameraNode].getColumn(3,&osp); mShapeInstance->mNodeTransforms[mDataBlock->cameraNode].getColumn(3, &osp);
getRenderTransform().mulP(osp,&sp); getRenderTransform().mulP(osp, &sp);
} }
else else
eye.getColumn(3,&sp); eye.getColumn(3, &sp);
// Make sure we don't hit ourself... // Make sure we don't hit ourself...
disableCollision(); disableCollision();
@ -1087,14 +1088,15 @@ void Vehicle::getCameraTransform(F32* pos,MatrixF* mat)
if (t > 0.0f) if (t > 0.0f)
ep = sp + offset + mCameraOffset + (vec * t); ep = sp + offset + mCameraOffset + (vec * t);
else else
eye.getColumn(3,&ep); eye.getColumn(3, &ep);
} }
mat->setColumn(3,ep); mat->setColumn(3, ep);
// Re-enable our collision. // Re-enable our collision.
if (isMounted()) if (isMounted())
getObjectMount()->enableCollision(); getObjectMount()->enableCollision();
enableCollision(); enableCollision();
}
// Apply Camera FX. // Apply Camera FX.
mat->mul( gCamFXMgr.getTrans() ); mat->mul( gCamFXMgr.getTrans() );