Problem with independlent setting coordinaties

Started by Klaudiusz, May 24, 2007, 10:22:49 AM

Previous topic - Next topic

Klaudiusz

Hello,

Well... I have a table:

Quotefloat Coordinates[] = {
     XPos,YPos,ZPos,XAxis,YAxis,ZAxis,
     ...
     ...};    // * TotalFrameLenght

Later i use the table:

Quotefloat XPos = Coordinaties[CurrentFrame*6];
float YPos = Coordinaties[CurrentFrame*6+1];
float ZPos = Coordinaties[CurrentFrame*6+2];
float XAxis = Coordinaties[CurrentFrame*6+3];
float YAxis = Coordinaties[CurrentFrame*6+4];
float ZAxis = Coordinaties[CurrentFrame*6+5];

And finnaly i want to set it.

And here is my problem. For camera i have this problem solved:
Quotecamera.setPosition = (XPos,YPos,ZPos);
But i don't know how i can set the Axis.

So this is my question:

How i can set camera axis and how i can set posision and axis for each object, independly of previous position/rotation?

Thanks in advice.

Egon, maybe you could add setPosision and something like setAxis also for Object3d in further version? It would be great for me :)

Remo

void    translate(float x, float y, float z)  Translates ("moves") the object in worldspace by modifying the translation matrix.
void    translate(SimpleVector trans)  Translates ("moves") the object in worldspace by modifying the translation matrix
setTranslationMatrix(Matrix mat)   Sets the translation matrix for the object.



One of the 3 should do it :)


And for rotation:

void    setRotationMatrix(Matrix mat)     Sets the rotation matrix for the object.
void    setRotationPivot(SimpleVector pivot)      Sets the rotation pivot of the object.

Melssj5

Well, the translation methods uses relative positions, so you may need to get an absolute position using the getTranslation () to find the position from the (0, 0, 0) and then add it the new coordinates to move it without mattering the old position.
Nada por ahora

EgonOlsen

To set an Object3D's axis, you may feed the axis into a SimpleVector, get the rotation matrix from it and put that back into the Object3D's rotation matrix.

Klaudiusz

Quote from: EgonOlsen on May 24, 2007, 05:45:12 PM
To set an Object3D's axis, you may feed the axis into a SimpleVector, get the rotation matrix from it and put that back into the Object3D's rotation matrix.

Ok thanks, i have it. But this method doen't work for camera. How can i set camera axis?

EgonOlsen

Similar. The camera has a setBeck()-method that does the same. But because the camera's rotation matrix is actually a world's rotation matrix inversed, you may have to put the inverse matrix into that method...it depends on what exactly you want to do.

Klaudiusz

Sorry, one more think.

I solved my problem by

QuoteSimpleVector dir=new SimpleVector(x,y,z);
camera.setBack(dir.getRotationMatrix().invert3x3());

It works fine but for SimpleVector only.

I would like to make a rotation based on the Math.PI values for each axis. It is possible?

Matrix is not my strong point. Could You post some source please?

EgonOlsen

The problem with storing a rotation as x/y/z-axis rotation is, that you'll run into a problem called gimbal lock (google for it for more info). Matrices (or quaternions) are used to avoid this. You may try it (just use the rotate?()-methods and reset the rotation matrix every frame), but generally it's not a good idea (although there are applications, where it is sufficient).

Klaudiusz

How can i translate (PIx,PIy,PIz) to SimpleVector(x,y,z) ? It could solve my problem.

EgonOlsen



EgonOlsen

Ok, so...i'm not sure what exactly you want to do...you have a point (x,y,z) and what to apply the rotations PIx-PIz to get a point (x',y',z')? If so, just use rotateX, ..Y and ..Z on the point. But be aware of that gimbal lock thing...doing rotations that way is not as easy as i looks like at first glance.

Klaudiusz

OK, thank You. I'll try, as You advised before, clear the matrix and rotate x,y,z.