Rotation of child elements around its axis

Apr 18, 2012 at 11:24 PM

Hi Dave,

I am currently working on a project that requires an object to rotate around a specific point and around its axis. Like simulating Moon circulating the Earth, Rotating at its axis and also around earth but when I add moon as child object of earth I am not able to rotate it around its axis. Your thoughts and suggestions also suggest tips to improve performance.

Coordinator
Apr 25, 2012 at 9:00 AM

Hi Usman,

 

Sorry about the late reply to this - I'm in the process of moving jobs and have been very busy!

OK the key things here are:

  • SceneObject
  • IHasObjectSpace

So let's look over it. If you have 'Earth' and it is a sceneobject that implements IHasObjectSpace then you can do this:

 

// Create earth.
var earth = new Earth();

// Earth implements IHasObjectSpace, so it has
// a linear transformation property.
// Rotate 30 degrees about the Y axis.
earth.LinearTransformation.RotateY = 30;

// Create the moon.
var moon = new Moon();

// The moon is a child of earth - immediately this means that it will be rotated WITH earth.
earth.Children.Add(moon);

// ...Moon also implements IHasObjectSpace - so we can transform it about its own axis.
moon.LinearTransformation.RotateY = 40;

So what happens here? Here's what the scene graph will do when rendering:

  1. Check to see if Earth implements IHasObjectSpace.
  2. It does - so it will apply the transformation and rotate by 30 degrees.
  3. Render the Earth geometry.
  4. Check to see if Earth has children.
  5.    It does - go through each child.
  6.    It finds 'moon' - it checks to see if moon implements IHasObjectSpace.
  7.    It does, so it applies the 40 degree rotatation.
  8.    It renders the moon geometry.
  9.    Moon has no children, so it 'pops' the moon transformation, meaning nothing else will have it.
  10. Now that earth and its children have rendered, it 'pops' the earth transformation and we're done.

Does this help?