Author Topic: Problem with independlent setting coordinaties  (Read 5671 times)

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Problem with independlent setting coordinaties
« on: May 24, 2007, 10:22:49 am »
Hello,

Well... I have a table:

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

Later i use the table:

Quote
float 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:
Quote
camera.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 :)

Offline Remo

  • int
  • **
  • Posts: 64
    • View Profile
    • http://www.opsdirector.com/3dart
Re: Problem with independlent setting coordinaties
« Reply #1 on: May 24, 2007, 11:33:13 am »
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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #2 on: May 24, 2007, 05:40:52 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Problem with independlent setting coordinaties
« Reply #3 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.

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #4 on: May 28, 2007, 09:21:42 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Problem with independlent setting coordinaties
« Reply #5 on: May 28, 2007, 12:06:02 pm »
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.

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #6 on: June 16, 2007, 01:57:26 pm »
Sorry, one more think.

I solved my problem by

Quote
SimpleVector 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Problem with independlent setting coordinaties
« Reply #7 on: June 16, 2007, 08:02:01 pm »
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).

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #8 on: June 16, 2007, 08:12:25 pm »
How can i translate (PIx,PIy,PIz) to SimpleVector(x,y,z) ? It could solve my problem.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Problem with independlent setting coordinaties
« Reply #9 on: June 16, 2007, 08:41:33 pm »
What are PIx, PIy and PIz?

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #10 on: June 16, 2007, 09:00:49 pm »
It's X,Y and Z Angles

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11970
    • View Profile
    • http://www.jpct.net
Re: Problem with independlent setting coordinaties
« Reply #11 on: June 16, 2007, 09:14:21 pm »
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.

Offline Klaudiusz

  • int
  • **
  • Posts: 75
    • View Profile
Re: Problem with independlent setting coordinaties
« Reply #12 on: June 16, 2007, 10:35:52 pm »
OK, thank You. I'll try, as You advised before, clear the matrix and rotate x,y,z.