Jump to content
  • Advertisement
Sign in to follow this  
john13to

Problem with rotating camera around object

This topic is 2664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem of implementing the camera when it is going to rotate around an object in a form of a spacecraft
that you can steer. I have implemented the translation of the camera so it follows the spacecraft as properly when
you move it forward, backwards and left and right strafing. But for now, the camera rotates around its own axis when
I am rotating the spacecraft, in other words the camera doesn´t stay behind the spacecraft. I tried to implement it as the
same way as it is written in the Chase Camera example found in App Hub but it didn´t work properly.

This is how it is written right now:

//in Game:////////////////////////////
if (keyState.IsKeyDown(Keys.Right))
{
sC.SetTurnAmtYawRight(rotationSpeed);
cam.SetTurnAmtRight(rotationSpeed);
cam.RotateCamera(sC);
}

//In SpaceCraft://///////
public void SetTurnAmtYawRight(float rotationSpeed)
{
turnAmtYaw -= rotationSpeed;
}

//in Camera://////////////
public void SetTurnAmtRight(float rotationSpeed)
{
turnAmt -= rotationSpeed;
}

public void RotateCamera(SpaceCraft sC)
{

cameraRot = Matrix.CreateRotationY(turnAmt);

transRef = Vector3.Transform(cameraRef, cameraRot);

lookAt = cameraPos + transRef;

view = Matrix.CreateLookAt(cameraPos, lookAt, Vector3.Up);


}

I know that cameraPos should be updated in RotateCamera but how?

Share this post


Link to post
Share on other sites
Advertisement
If you want the camera (Or any other object that uses a Matrix for position and orientation) to follow the same position and direction as another object, you need to multiply the matrices together.

MatrixObject = MatrixObjectTranslation*MatrixObjectRotation*MatrixObjectScaling // Contains the position, rotation and scaling of the object

MatrixCameraOffset = MatrixCameraOffsetTranslation // Contains the distance from the object to the camera

MatrixCamera = MatrixObject*MatricCameraOffset // Contains the position of the camera

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!