Rotating and moving

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.
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Rotating and moving

Post 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]
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post 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.
Crud, how do I do this again?
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post 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 ??
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post 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)
Epik
Posts: 2
Joined: Wed Oct 22, 2003 2:28 am

Post 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
hearsedriver
Posts: 81
Joined: Fri Aug 22, 2003 12:06 pm
Location: Germany
Contact:

Post 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.
matthias gall, lead programmer at sechsta sinn - email matthias@sechsta-sinn.de
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post by Isometric God »

What is the IDummyTransformationSceneNode good for then ? Can't see any use in that. Maybe niko knows ... :D
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post 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.
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post 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
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

Someone should write a tutorial on this... theres quite a few people wondering how to get this working correctly.
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post 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 :) :)
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post 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.
Crud, how do I do this again?
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post 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?
hearsedriver
Posts: 81
Joined: Fri Aug 22, 2003 12:06 pm
Location: Germany
Contact:

Post 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.
matthias gall, lead programmer at sechsta sinn - email matthias@sechsta-sinn.de
Guest

Post 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?
Post Reply