Page 1 of 2

Rotating and moving

Posted: Thu Oct 23, 2003 7:17 pm
by Isometric God
Hey,
sorry for asking this beginner question, but I could not find out on my own : I have a 3D models which can be rotated and moved. My problem is that the movement is axis-aligned and NOT linked with the rotation.

Let's say the rotation is 0 and the models moves "left". Everythings fine here. But if the rotation is 180 degrees and the model moves "left", it should move to the right ( seen through world coordinates ). See my problem ?

All I can think of is a dummy scene-node which holds the rotation and the model being a child to that taking the movement. Sounds crappy to me though..

Can anyone please help me ?
... thanks ! :wink: [/list]

Posted: Thu Oct 23, 2003 8:32 pm
by saigumi
Yep, that's right. The sceneNode is the holder for the model and should be used to handle position and rotation information. It also controls the bounding box.

This allows you to load a model, set the model upside down, load another model to the same node and be able to turn both using the same sceneNode rotator.

Sounds crappy? Nope, it's the common way to perform rotates and transforms.

Posted: Thu Oct 23, 2003 9:07 pm
by Isometric God
If you say so ... :wink:

So let's summarize : First I create a dummy scene node, that is a IDummyTransformationSceneNode. Then I load the model into a scenenode and make the dummy scene node the parent. The rotation goes into the dummy-scene-node-parent and the movement into the child-scenenode which contains the model.

Is that correct ??

Posted: Fri Oct 24, 2003 12:16 am
by DarkWhoppy

Code: Select all

ISceneNode* shipDummy = 0;

Dummy = scenemgr->addDummyTransformationSceneNode(0,1);

RealNode->setParent(Dummy); 

Eh? ... (i'm still a newb myself, and was just about to ask this same question Isometric God) :wink:

That did compile with no errors 8)

Posted: Fri Oct 24, 2003 3:00 am
by Epik
I was wondering this to :D Can you just use a normal scene node so you can use the setRotation/ getRotation, or do you have to use the dummy and rotate manually with the matrix? (because in the docs of IDummyTransformationSceneNode it says that set/getRotation does nothing...) btw. Im new to the forums :P

Posted: Fri Oct 24, 2003 1:13 pm
by hearsedriver
I had the problem myself. There is no scenenode yet that simply represents a node in the scenegraph, without any mesh/light/... attached. I used a temporary solution and created a light scenenode with light color/radius 0. I'm sure Niko will add an adequate scenenode in 0.5.

Cheers.

Posted: Fri Oct 24, 2003 3:11 pm
by Isometric God
What is the IDummyTransformationSceneNode good for then ? Can't see any use in that. Maybe niko knows ... :D

Posted: Fri Oct 24, 2003 4:34 pm
by niko
I used it when attaching scene nodes to bones of skeletal animated models. From the API docs:

This scene node does not render itself, and does not respond to set/getPosition, set/getRotation and set/getScale. Its just a simple scene node that takes a matrix as relative transformation, making it possible to insert any transformation anywhere into the scene graph. This scene node is for example used by the IAnimatedMeshSceneNode for emulating joint scene nodes when playing skeletal animations.

Posted: Fri Oct 24, 2003 5:58 pm
by Isometric God
Well ... it does respond to set/getPosition for me. At least the matrix is modified. So it this what I need or is it not ? And why does hearsedriver create his own dummy scenenode then ?

thanks

Posted: Fri Oct 24, 2003 8:52 pm
by DarkWhoppy
Someone should write a tutorial on this... theres quite a few people wondering how to get this working correctly.

Posted: Fri Oct 31, 2003 2:57 pm
by Isometric God
I found a quick & easy solution to my problem. For those who are fighting the same problem :

Code: Select all

	core::vector3df delta_v = m_Vel * m_TimeFactor;
	delta_v.rotateXZBy(m_Rotation.Y, core::vector3df(0, 0, 0));
	m_Pos += delta_v;
Hope this helps :) :)

Posted: Fri Oct 31, 2003 3:13 pm
by saigumi
*smacks head on desk*

And here I was performing long and involved geometry to do the same effect with cosines and sines and argggghhh.....

I should have taken my own advice and realized that Irrlicht makes hard things simple and started my search for an answer by looking for the simplest answer.

Thanks Isometric God, you just saved me 17 lines of code.

Posted: Sun Nov 02, 2003 7:11 pm
by DarkWhoppy
I need my model to rotate ONCE... like turing left or right (forward, back also) but it keeps rotating as the user/player presses the keys.... someone gime some help on this?

Posted: Sun Nov 02, 2003 9:39 pm
by hearsedriver
Isometric God wrote:And why does hearsedriver create his own dummy scenenode then ?
I did because I trusted the API docs. If Nikos dummy scenenode does respond to setPosition/Rotation, it might work as well.

Cheers.

Posted: Mon Nov 10, 2003 3:31 pm
by Guest
Hello,

yesterday I've started working with the Irrlicht-Engine and I've got the same problem.
I tried to solf it like that but it doesn't work:
//v1, v2 and Rotation: vector3d

//Keyboardinput W or S:
v = model_node->getPosition();
v2 = v;
v.X += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
v.rotateXZBy(Rotation.Y,v2);
model_node->setPosition(v);

// [...]

//Keyboardinput A or D
v = model_node->getPosition();
v2 = v;
v.rotateXZBy(Rotation.Y,v2);
model_node->setPosition(v);

// [...]

//Mousemove
Rotation = core::vector3df(0, event.MouseInput.X * 720 / ResX, 0);
model_node->setRotation(Rotation);
I don't use a FPS-Camera because I want a 3d-person camera.
First i tried to calculate the rotation myself with sin() and cos() functions, but it was exactly the same problem:
With 0° and 180° rotation -> everything is fine
With 90° and 270° rotation -> direction reversed
Between these rotations -> X and Z axis are swaped

@Isometric God
You say, your code works. Could you please comment it? I don't understand it, because I don't know what delta_v, m_Vel and m_TimeFactor are.

Thank you...

BTW: Is there a german forum, too?