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.
Apr 25, 2012 at 9:00 AM
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:
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.
// ...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:
- Check to see if Earth implements IHasObjectSpace.
- It does - so it will apply the transformation and rotate by 30 degrees.
- Render the Earth geometry.
- Check to see if Earth has children.
- It does - go through each child.
- It finds 'moon' - it checks to see if moon implements IHasObjectSpace.
- It does, so it applies the 40 degree rotatation.
- It renders the moon geometry.
- Moon has no children, so it 'pops' the moon transformation, meaning nothing else will have it.
- Now that earth and its children have rendered, it 'pops' the earth transformation and we're done.
Does this help?