Rotating and moving
-
- Posts: 69
- Joined: Sun Oct 12, 2003 3:42 pm
- Location: Germany
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 )
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 )
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...
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...
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
The German language forum is at: http://www.netvader.net/irrlichtforum
Crud, how do I do this again?
-
- Posts: 69
- Joined: Sun Oct 12, 2003 3:42 pm
- Location: Germany
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..
Every frame you rotate the vel. vector accordingly and write it to the scenenode. That should help..
"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
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
-
- Posts: 69
- Joined: Sun Oct 12, 2003 3:42 pm
- Location: Germany
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.
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.
-
- Posts: 69
- Joined: Sun Oct 12, 2003 3:42 pm
- Location: Germany
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 !
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 !