Basic help about rotation..

Marioko

17-07-2006 22:35:58

Hi..

I am very newbie in Ogre and OgreDotNet, at last i could make a scene with a robot. When i press the arrows keys up, down, right, left, the robot walk very nice, the problem is in the rotation, i want that if i press right then the robot rotate to east, and if i press right and up (for example) the robot rotate to north-east..

I am using this code to try perform the rotation:


private void performRobotRotation()
{
Vector3 src = robotNode.GetOrientation() * Vector3.UnitX;
Vector3 dest = robotNode.GetPosition();

//mMoveRobot bits: 1=adelante, 2=atras, 4=izquierda, 8=derecha
if ((mMoveRobot & 1) > 0)
dest *= Vector3.NegativeUnitZ;
if ((mMoveRobot & 2) > 0)
dest *= Vector3.UnitZ;
if ((mMoveRobot & 4) > 0)
dest *= Vector3.NegativeUnitX;
if ((mMoveRobot & 8) > 0)
dest *= Vector3.UnitX;

Quaternion rotation = src.GetRotationTo(dest);
robotNode.Rotate(rotation);


}


Only the first time that i run the app works nice, but later the robot fuck it.. o rotate very ugly.. somebody can help me??

pepote

17-07-2006 23:28:32

Te recomiendo que leas algún manual sobre matrices de cuatro dimensiones. Son las que se utilizan para calcular la rotación. Hay diferentes posibilidades dependiendo del eje que rotas y de si usas DirectX u openGL.

Yo he trabajado mucho tiempo las rotaciones he conseguido resultados positivos, pero si lo relacionas con la cámara ya no...

Te dejo aquí un código sobre el que trabajé y que proviene de purple# un motor con el que trabajé hace tiempo pero que actualmente no dispone de mucha ayuda ni colaboración.

/// <summary>
/// moves the model in view space
/// </summary>
/// <param name="delta"></param>
public void Move(Vector3 delta)
{
position += Rotation.RightVector * delta.X +
Rotation.UpVector * delta.Y +
Rotation.LookAtVector * delta.Z;
}


Debes saber que para rotar hacen falta:

tiempo que pulsas una tecla o distancia que recorres con el ratón hacia un lado (delta.X, delta.Y o delta.Z), dirección en la que el modelo está mirando (LookAtVector, se utiliza como punto de referencia al rotar y para que la cámara sepa en qué dirección apuntar cuando estas en un FirstPerson o ThirdPerson game), después tendrás que pasar position a una translation matrix.

Estudia las matrices de 4 dimensiones de rotación y traslación y repásate la multiplicación de matrices y esas cosas.

Marioko

18-07-2006 01:35:35

Muchas Gracias pepote, tu aporte a sido muy bueno, y lo mejor es que solo espere una hora desde que puse el post para obtener buena ayuda. En ese tiempo estuve leyendo sobre los Quaternios en el wiki oficial de ogre, pero muchas cosas se me pasaron de largo (no las entendi muy bien). Voy a seguir tu consejo y leere bastante sobre las matrices 4D....

Ah tambien probare el codigo... :D