Page 2 of 2

Posted: Mon Nov 10, 2003 3:35 pm
by Tequilla
Oups.. In Keyboardinput A or D I've forgotten to post the following line:

v.Z += event.KeyInput.Key == KEY_KEY_A ? 2.0f : -2.0f;

But, of course, it is integrated in my code...

Posted: Mon Nov 10, 2003 6:29 pm
by Isometric God
in your code the coordinates are switched every frame. you read it from memory, turn around, write back to memory, read it again and turn AGAIN. The rotation gets more and more, but this is not what you want.

m_TimeFactor is the time delta between last frame and this frame
m_Vel is a member of the entity class and contains the velocity ( you might need this value too )

Posted: Mon Nov 10, 2003 6:52 pm
by Tequilla
I hope i may post in german, too, but I just do it ;)

Wieso werden die Koordinaten jeden Frame getauscht?
Der Code den ich geschrieben habe, steht im Event-Receiver. Das wird also nur ausgeführt, wenn eine Taste gedrückt wird, bzw die Maus bewegt wird...
Oder geht es doch besser über einen Dummy-SceneNode? Also ich bewege den Dummy über eine Transformationsmatrix an die jetztige Position meines Models, drehe es dann über eine weitere Transformationsmatrix und bewege dann das Model inerhalb des nun gedrehten Koordinatensystems entlang der Z- bzw. X-Achse, jenachdem in welche Richtung ich mich bewegen möchte.
Also ähnlich als würde ich direkt mit OpenGL die Push- und Pop-Matrixfunktionen benutzen...


I'm sorry for all, who don't understand german...

Posted: Mon Nov 10, 2003 7:44 pm
by saigumi
There indeed is a German language forum. I try to read it via http://babelfish.altavista.com once in a while but things don't always come out that good.

The German language forum is at: http://www.netvader.net/irrlichtforum

Posted: Mon Nov 10, 2003 7:55 pm
by Tequilla
Yes, I know... but Niko speaks german and Isometric God speaks german... So I think it is ok to write here german once to comunicate with Isometric God or niko. When a solution for the problem is fund, I would summarise it in english. Is that ok?

Posted: Mon Nov 10, 2003 8:55 pm
by Isometric God
You read the velocity from the scenenode, rotate it and write the ROTATED vel. vector back to the scenenode. It don't think that it will do you good. Better would be a member variable that stores the entitity's velocity.

Every frame you rotate the vel. vector accordingly and write it to the scenenode. That should help..

Posted: Tue Nov 11, 2003 2:36 pm
by Tequilla
"You read the velocity from the scenenode, rotate it and write the ROTATED vel. vector back to the scenenode"
What's wrong with it? It's what I wanted: I set the velicity to the wanted position of the entite and rotate it with a radius which is the distance the entity moved...

Ok, I'll try it like that. I think, there are not much more ways to try it ;)

Posted: Tue Nov 11, 2003 2:45 pm
by Isometric God
Well, if you write the rotated velocity vector to the scenenode and read it out again during the next frame, you will receive the rotated vector again. Then, you rotate it again and so on. See the point ?

Posted: Tue Nov 11, 2003 3:04 pm
by Tequilla
Oh, now I know what you mean... but i don't do so. I do the rotation in the OnEvent-function of my EventReceiver.
I tried it now, like you sayed, but it's the same problem. I think it could be a misstake in the calculation for the sin() and cos() functions from degrees to Bogenmaß (sorry, I don't know the english word), because it is exactly the same problem as performing the rotation of the axis my self:

Position.Z += sin(Rotation.Y / 180 * PI) * event.KeyInput.key == KEY_KEY_W ? 2.0f : -2.0f;
Position.X += cos(Rotation.Y / 180 * PI) * event.KeyInput.key == KEY_KEY_W ? 2.0f : -2.0f;

The same for side moving with Z and X switched...

That was my first try and the effect is the same.

Posted: Tue Nov 11, 2003 4:00 pm
by Isometric God
The english word for "bogenmaß" is "radians" I think. pi / 180 is stored in a global const calles core::GRAD_PI2. But I don't think you will need it.
What I did is the following :
The entity has a "world-view" velocity vector m_Vel, which is rotated around 0.

void CEntity::Update()
- m_Vel.rotateXZBy(m_Rotation.Y, core::vector3df(0, 0, 0));

Then I modify the velocity any way I like.

if (keyPressed)
- m_Vel.Z += m_ShipData->m_Acceleration * timeFactor;

And last but not least I rotate the vector back.

m_Vel.rotateXZBy(-m_Rotation.Y, core::vector3df(0, 0, 0));

In case you do not want your velocity vector to be "global" it might be enough to rotate is once and keep it. I use a "global" one because collision detection is much easier with that. Hope that helps !

Posted: Tue Nov 11, 2003 6:57 pm
by Tequilla
Ok, thank you!
I'll try it... but I think.. hmm.. have you already tried that? I think by rotating around 0|0|0 an moving, the model is not rotating correctly arround it self, but arround 0|0|0... I tried this already by playing arround with OpenGL-APIs...