Rotating a Custom Scene Node Around Itself

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jddevnet
Posts: 17
Joined: Mon Oct 06, 2008 8:27 pm

Rotating a Custom Scene Node Around Itself

Post 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.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Two advices:
1. Check the source code of vector3d and matrix4.
2. Search the forum. I Know the answer is there.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

not sure if possible, may be parent it to an invisible object and rotate that object
jddevnet
Posts: 17
Joined: Mon Oct 06, 2008 8:27 pm

Post 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.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post 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.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post 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.
Image Image Image
jddevnet
Posts: 17
Joined: Mon Oct 06, 2008 8:27 pm

Post by jddevnet »

You guys rock!!

Works like a charm now. Thanks.
Post Reply