Binding a camera to a body (once more ;))

Loockas

08-09-2007 11:14:48

I know this topic was brought up some time ago, but since the new version of NxOgre has come, some things has changed.

Simply, I have a body with a sphere shape and I'd like to bind a camera to it. The problem is that the camera attached directly to the body's node is rotating in the same way as my moving ball. If the body was a character there wouldn't be any problem with it, but I couldn't get my ball rolling. How can I solve this?

betajaen

08-09-2007 11:28:21

You could do two things:

1. Don't bind the Camera to the Sphere, Just copy the position of the Sphere to the Camera.

2. Bind the Camera and freeze the rotational movement of the Sphere.

Loockas

08-09-2007 12:02:21

Yup, the first way is the best for me, thanks. Geez.. I wish I had thought about it earlier.

Loockas

09-09-2007 11:09:17

OK I've got the camera rotating around my ball using getGlobalPosition(). However there happen weird things while moving the ball. If I add a force to it, the camera immediately is getting a great speed in the same direction as I forced the ball but the speed is disproportionately high. There are also some unexpected rotations of the camera node..
Note: The mBallPos value is updated each frame.

void PlayCam::update(Ogre::Real timeElapsed)
{
Vector3 mBallPos = Global->mBall->getBallPos(); // get the updated ball position
Vector3 mCamPos = mCamNode->getPosition();

const MouseState &ms = Global->mMouse->getMouseState();

float RotX = ms.Y.rel * -mRotateScale;
float RotY = ms.X.rel * -mRotateScale;

Quaternion rotateQuaternionCam = mCamera->getOrientation();
rotateQuaternionCam.normalise();
Vector3 CamAxisX = rotateQuaternionCam.xAxis();
CamAxisX.normalise();

Quaternion rotateQuaternionCamX( rotateQuaternionCam.getPitch(false), CamAxisX );

Quaternion rotateQuaternionX(Degree(RotX), CamAxisX);
Quaternion rotateQuaternionY(Degree(RotY), Vector3::UNIT_Y);

Vector3 targetPos = Vector3(mBallPos.x,0,mBallPos.z);

mCamNode->setPosition(targetPos + rotateQuaternionX*rotateQuaternionY * mCamPos);
mCamera->lookAt(targetPos);
}


EDIT: Aww what a shame.. The camera position was set wrong. More sleep, less coffee..