Page 1 of 1

Rotating a Custom Scene Node Around Itself

Posted: Fri Nov 07, 2008 12:35 am
by jddevnet
Hi,

I've been trying to understand how rotations work. I've found many examples on the forums and tutorials regarding rotations, yet they always seem to cause a given node to rotate around something else.

My goal is to understand how to keep a node's center in one location and rotate around it. This way, I will learn how to manipulate however I want - with or without movement around another point.

For example, like this... picture the images below keeping the center at (50,50,50) the entire time...

Code: Select all

____
|   |
|   |
|___|

  /|
 | |
  \|
 
.

Any help with this is greatly appreciated.

Thank you.

Posted: Fri Nov 07, 2008 5:43 am
by MasterGod
Two advices:
1. Check the source code of vector3d and matrix4.
2. Search the forum. I Know the answer is there.

Posted: Fri Nov 07, 2008 5:48 am
by jontan6
not sure if possible, may be parent it to an invisible object and rotate that object

Posted: Fri Nov 07, 2008 6:57 am
by jddevnet
Mastergod,

Appreciate the advice however I have spent the last 3 days or so searching the forums and still don't quite get it. I am always hesitate to post, as I truly don't want to waste anyone's time.

In re-reading my post though, I didn't mention the Custom Scene Node anywhere other than the title. Sorry about that. The problem definitely lies in my understanding of how it works. Below, I have added some additional information.

So, my experience thus far has been that this works great:

Code: Select all

ISceneNode * cube = myEngine->getSceneManager()->addCubeSceneNode(20.f); 
	cube->setMaterialTexture(0, myEngine->getDriver()->getTexture("./media/music/Folder.jpg")); 
    cube->setMaterialFlag(video::EMF_LIGHTING, false); 
    cube->setPosition(vector3df(50,50,50)); 

// To rotate similar to my example above
    cube->setRotation(vector3df(0,45,0)); 
The custom scene node I've created has the following :

Code: Select all

vertices[0] = video::S3DVertex(position.X-10, position.Y-10, position.Z, 1,0,0, video::SColor(255,255,255,255), 0, 1);
vertices[1] = video::S3DVertex(position.X+10, position.Y-10, position.Z, 0,1,0, video::SColor(255,255,255,255), 1, 1);
vertices[2] = video::S3DVertex(position.X+10, position.Y+10, position.Z, -1,0,0, video::SColor(255,255,255,255), 1, 0);
vertices[3] = video::S3DVertex(position.X-10, position.Y+10, position.Z, 0,-1,0, video::SColor(255,255,255,255), 0, 0);

... 

u16 indices[] = { 2,1,0, 2,0,3 };
Without rotation:
Image

With vector3df(0,18.f,0) rotation:
Image

Why does it move off the screen? The coordinates don't move - only the image (as it rotates)...

Thank you again.

Posted: Fri Nov 07, 2008 8:43 am
by bitplane
make your custom node relative to 0,0,0, which is the point it rotates around. The node's world space position is provided by the node's absolute transformation, which is set by setPosition/setScale/setRotation of all of its parents.

Posted: Fri Nov 07, 2008 9:21 am
by JP
Yeah so basically get rid of the position references you're adding when creating your vertices, just have the vertices ranging from -0.5 to +0.5 and then once you've created your node you can use node->setPosition() and node->setScale() to get the correct sizing and positioning, or of course you just pass the constructor parameters into the ISceneNode constructor and it'll set them up from the start. You don't need to handle position and scale in your custom node at all.

Posted: Fri Nov 07, 2008 5:03 pm
by jddevnet
You guys rock!!

Works like a charm now. Thanks.