Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rotate cammera around center of object wpf

Tags:

c#

wpf

vector

xaml

3d

Expression blend enables you to import 3d models. I want to animate a 3d object with code. I just can't seem to figure out what are the property values that I have to modify in order to make an object rotate. Let me show you what I mean:

enter image description here

so if I want to rotate this object I could use the camera orbit tool enter image description here and If I use it I can end up with something like:

enter image description here

I know I can create a storyboard and create the animation by modifying the object. I need to rotate the object along the x axis with a slider. If I modify just one value it will rotate in a weird way I actually have to change several properties if I wish to do so. For example when I am rotating the object along the x-axis with the camera orbit tool I can see that all these enter image description here properties are changing. I need to figure out what is the algorithm being used to rotate the object.

like image 374
Tono Nam Avatar asked Jun 27 '11 00:06

Tono Nam


1 Answers

The math to move the camera position around so that you appear to be rotating around the X axis is just the parametric equation of a circle:

Parametric Equation of a Circle

where t is the angle from zero to 2 pi.

Imagine you are standing on the street looking at a house. The camera's coordinates have to follow a circle around the house and the latitude and longitude are continuously changing to keep the same distance from the house. So there is no one value you can change to make it rotate.

Once you know the camera position, the direction is just the difference between the origin and the camera position.

All this is not hard to calculate but there is an easier way. Instead, keep the camera fixed and rotate the object. This makes animations much easier. Here is an MSDN article contains examples of that approach, including animations:

  • 3-D Transformations Overview

That article is meant for WPF and Visual Studio but you can easily adapt the same ideas to Expression Blend.

like image 143
Rick Sladkey Avatar answered Sep 30 '22 15:09

Rick Sladkey