Skip to main content
added 418 characters in body
Source Link
Steve H
  • 5.1k
  • 20
  • 21

//This is the part that I'm having difficulty with, the rest works fine. cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle));

Yes, I can see the problem. On this line, you are orbiting the camera's position around the world origin instead of the center of your arc's sphere (which is your camera target). You need to translate the position/target system to the world origin, do the rotation, then translate them back like you did in the first rotation to set the pitch.

try this:

//This is the part that I used to have difficulty with, but now works fine.
        cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle)) + cameraTarget;

Edit: Additionally, you can combine the 2 rotations into one Vector3.Transform() like this:

Vector3 axisAngle = (Vector3.UnitX * tippingAngle) + (Vector3.UnitY * rotationAngle);
float angle = axisAngle.Length();
Vector3 axis = axisAngle / angle;//normalizes the axis
 cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(axis, angle)) + cameraTarget;

//This is the part that I'm having difficulty with, the rest works fine. cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle));

Yes, I can see the problem. On this line, you are orbiting the camera's position around the world origin instead of the center of your arc's sphere (which is your camera target). You need to translate the position/target system to the world origin, do the rotation, then translate them back like you did in the first rotation to set the pitch.

try this:

//This is the part that I used to have difficulty with, but now works fine.
        cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle)) + cameraTarget;

//This is the part that I'm having difficulty with, the rest works fine. cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle));

Yes, I can see the problem. On this line, you are orbiting the camera's position around the world origin instead of the center of your arc's sphere (which is your camera target). You need to translate the position/target system to the world origin, do the rotation, then translate them back like you did in the first rotation to set the pitch.

try this:

//This is the part that I used to have difficulty with, but now works fine.
        cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle)) + cameraTarget;

Edit: Additionally, you can combine the 2 rotations into one Vector3.Transform() like this:

Vector3 axisAngle = (Vector3.UnitX * tippingAngle) + (Vector3.UnitY * rotationAngle);
float angle = axisAngle.Length();
Vector3 axis = axisAngle / angle;//normalizes the axis
 cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(axis, angle)) + cameraTarget;
Source Link
Steve H
  • 5.1k
  • 20
  • 21

//This is the part that I'm having difficulty with, the rest works fine. cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle));

Yes, I can see the problem. On this line, you are orbiting the camera's position around the world origin instead of the center of your arc's sphere (which is your camera target). You need to translate the position/target system to the world origin, do the rotation, then translate them back like you did in the first rotation to set the pitch.

try this:

//This is the part that I used to have difficulty with, but now works fine.
        cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle)) + cameraTarget;