Switch between Orbit - Thirdperson Camera's
by Klaas Hemerijckx · in Torque Game Engine · 05/31/2007 (3:28 am) · 6 replies
In my game I can cycle between the orbit camera and a third person camera (Advanced Camera Resource). When I switch the cams I want the Orbit cam positioned on the exact same location as the 3th person cam was (on position x,y,z). My question is how can I accomplish this because setposition("x y z") for the orbit cam does not put the cam in the right place.
Thanx,
Klaas
Thanx,
Klaas
#2
05/31/2007 (8:13 am)
I tried getTransform/setTransform but this does not work. The problem is, I think, that the orbit cam uses spherical coordinated (azimuth, declination, zoomdistance) and the 3the person cam Cartesian coordinates (xyz). But I cant figure out how to align them.
#3
05/31/2007 (9:36 am)
Roger that. I tried getTransform/setTransform too, without effect.
#4
Replace the "case Orbitmode :" in the advanceTime function with this:
Put "$advCamera::resetOrbitCam = true;" in your script to reset the camera.
This aligns only the azimuth not the declination and zoomdistance. Can someone point me in the right direction for calculating the correct declination and zoomdistance?
Thanx,
Klaas
06/07/2007 (8:55 am)
I'have found a way to center the camera behind the player when you switch to the orbit camera mode:Replace the "case Orbitmode :" in the advanceTime function with this:
case OrbitMode :
{
if ( playerObj != NULL)
{
Point3F mConvertedOrbitOffset;
F32 mOffsetX;
F32 mOffsetY;
F32 mOffsetZ;
MatrixF objToWorld = playerObj->getRenderTransform();
objToWorld.mulP(mCurrentOrbitOffset, &cameraPosWorld);
//Added for camera reset
bool resetCam = Con::getBoolVariable("$advCamera::resetOrbitCam", false);
if (resetCam)
{
Con::setBoolVariable("$advCamera::resetOrbitCam", false);
Player* playerObjAsPlayer = dynamic_cast<Player*>(playerObj);
Point3F Rotation = playerObjAsPlayer->getRotation();
mAzimuth = mAzimuth - (mAzimuth - ((-Rotation.z) + (1.5 * M_PI)));
}
//Added for camera reset
// use spherical to cartesian coord transforms to calculate offset
mOffsetX = mZoomDistance * sin(mDeclination) * cos(mAzimuth);
mOffsetY = mZoomDistance * sin(mDeclination) * sin(mAzimuth);
mOffsetZ = mZoomDistance * cos(mDeclination);
mConvertedOrbitOffset.set(mOffsetX, mOffsetY, mOffsetZ);
cameraPosWorld += mConvertedOrbitOffset;
}
break;
}Put "$advCamera::resetOrbitCam = true;" in your script to reset the camera.
This aligns only the azimuth not the declination and zoomdistance. Can someone point me in the right direction for calculating the correct declination and zoomdistance?
Thanx,
Klaas
#5
Big thanks for this info Klaas! Which sorce file have you modified?
06/28/2007 (6:21 am)
I'm just back from vacation... :-)Big thanks for this info Klaas! Which sorce file have you modified?
#6
06/28/2007 (6:39 am)
Chris, I modified the advancedCamera.cc source file.
Community Manager Michael Perry
ZombieShortbus