locked
Rotate camera to point towards target.

    Question

  • I'm needing to create a camera that slowly turns to point at a target. Right now, I have a camera class that has an actual target and a desired target. The actual target simply moves towards the desired target. This is fine for situations where I need to track some moving object, but when I'm trying to get the camera to pan around and look at a fixed target, as if it's a waypoint, then I have a problem. The camera will not rotate linearly like you would think.

    Instead of just having the camera point at a target that's lerping, I need to rotate the camera from point a to point b. Are there any tutorials or documentation on how I could do this, thanks.


    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Wednesday, March 27, 2013 1:17 PM

Answers

  • I might be inclined to compute the initial and final orentation of the camera, and interpolate between those.  Represent your orientation of the camera using a quaternion, and perfom a slerp to compute the rotation required to get from initial to final orientation.  I'm sure you can search the internet for slerp, quaternion, and interpolation to get what you're looking for.
    Sunday, March 31, 2013 5:49 PM

All replies

  • Hi,

    Would you please explain your question more detail, what's the meaning of "rotate the camera from point a to point b". There is the CameraOptionsUI API displays a UI for adjusting camera settings. Maybe you can try this sample to see if it can meet your need.
    http://code.msdn.microsoft.com/windowsapps/CameraOptionsUI-Sample-44c06873

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 29, 2013 2:19 AM
    Moderator
  • I have a camera that is going to point at different targets. When the player presses the left key, the camera will move to the next target. In order to get the camera to turn towards the next target, "desired target", I simply interpolate the target towards the desired target. The problem is that this causes a non-linear movement.


    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Saturday, March 30, 2013 3:41 PM
  • You need to break down the rotation into yaw (rotation around the Up direction) and pitch angle deltas (cross product of Up and start direction vectors). Interpolate those deltas using whatever function looks most natural for your app. I imagine you would want to start fast and end slowly in yaw, to give the impression of zeroing in on target B. 
    Sunday, March 31, 2013 5:38 PM
  • I might be inclined to compute the initial and final orentation of the camera, and interpolate between those.  Represent your orientation of the camera using a quaternion, and perfom a slerp to compute the rotation required to get from initial to final orientation.  I'm sure you can search the internet for slerp, quaternion, and interpolation to get what you're looking for.
    Sunday, March 31, 2013 5:49 PM
  • Thanks, that's exactly what I did.

    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Thursday, April 18, 2013 12:32 PM