Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (581) Games in Android Showcase (162) games submitted by our members Games in WIP (632) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 glrotation to vectors  (Read 1814 times) 0 Members and 1 Guest are viewing this topic.
Therion_

Senior Newbie

 « Posted 2011-05-30 00:27:47 »

hello @all,

i got 3 vectors (X;Y;Z) and i need to setup an rotation in opengl/jogl to use this
for drawing objects.

the glu.lookat (0,0,0 ,Vx,Vy,Vz, Ux,Uy,Uz) is doing this perfect for the
camera..but i need this for the objects
(V'xyz= Z Vector , U'xyz is the Y/UP Vector..and i also got an X Vector to the side)

how can i do this ?

thanks for all help

cylab

JGO Ninja

Medals: 79

 « Reply #1 - Posted 2011-05-30 09:36:33 »

Take a look at: http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html, then create a appropriate 4x4 matrix incorporating your X, Y, Z vectors, multiply your objects vertices with it and you should be done.

Mathias - I Know What [you] Did Last Summer!
Therion_

Senior Newbie

 « Reply #2 - Posted 2011-05-30 22:30:08 »

omg,

i was looking for the strangest of all calculation-combinations to get the rotation....
(i am not an mathematics expert..i wrote an own vector 3axis rotation for an space sim
..not 100% exactly..but for gaming it works perfect )

and now..simple put the vectors to the matrix..and works... think i need some coffee

thanks alot cylab...
Roquen
 « Reply #3 - Posted 2011-05-31 05:14:33 »

Explicitly storing a full coordinate frame per object is overkill and kinda hard to manipulate.  Why not represent orientations by some rotation format?
Therion_

Senior Newbie

 « Reply #4 - Posted 2011-05-31 07:17:14 »

its working 99.0%

the only thing is, and that i think is what cylab wrote, is the
Quote
.

my camera is not interacting with the objects like it does before.
My old code was looking like that:

glu.glulookat for camera
...
push matrix
rotate ..
rotate...
translate
callList(xyz)
pop matrix

now i replaced the rotate ... with the set_rota funktion (see code)
when i got my camera fixed ( glu.gluLookAt(0,0,1,  0,0,0,  0,1,0);
the object is working perfect with the vector rotations.

when now putting the vectors in the lookat funktion for the camera
they make an twice rotation and the object is always in front of me.

greetings

// Paint object with vector offset 0
 1  2  3  4  5 `        gl.glPushMatrix();        texture[9].bind();        set_rota(drawable, 0);   //  build matrix from vector set 0        gl.glCallList(2005);        gl.glPopMatrix();`

// My build matrix from vector method
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34 `public void set_rota(GLAutoDrawable drawable,int off){   GL2 gl = drawable.getGL().getGL2();   float flc=0.0f;       FloatBuffer matrix2  = FloatBuffer.allocate(16);    matrix2.rewind();      flc=(float) vector[off+3] ;matrix2.put(flc);   flc=(float) vector[off+4] ;matrix2.put(flc);   flc=(float) vector[off+5] ;matrix2.put(flc);   flc=0.000000f             ;matrix2.put(flc);      flc=(float) vector[off+6] ;matrix2.put(flc);   flc=(float) vector[off+7] ;matrix2.put(flc);   flc=(float) vector[off+8] ;matrix2.put(flc);   flc=0.000000f             ;matrix2.put(flc);      flc=(float) vector[off+0] ;matrix2.put(flc);   flc=(float) vector[off+1] ;matrix2.put(flc);   flc=(float) vector[off+2] ;matrix2.put(flc);   flc=0.000000f             ;matrix2.put(flc);   flc=(float) 0             ;matrix2.put(flc);   flc=(float) 0             ;matrix2.put(flc);   flc=(float) -10           ;matrix2.put(flc);   flc=1.000000f             ;matrix2.put(flc);       matrix2.rewind();          gl.glLoadMatrixf(matrix2);   `

// My Camera Setup
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23 `    public void setcamera(GLAutoDrawable drawable,int was)    {    GL2 gl = drawable.getGL().getGL2();    GLU glu = new GLU();    gl.glMatrixMode(GL2.GL_PROJECTION);    gl.glLoadIdentity();     float pvi=35.0f;       float near=0.1f;     float far=50000.0f;     float asp = (float)screen_x / (float)screen_y;     if (asp==0) asp=1;    glu.gluPerspective( pvi, asp, near,far );    gl.glMatrixMode(GL2.GL_MODELVIEW);    gl.glLoadIdentity();   glu.gluLookAt(vector[0],vector[1],vector[2],   //look from                      0,0,0,                                    //look to zero                      vector[6],vector[7],vector[8]);  //up vector`

cylab

JGO Ninja

Medals: 79

 « Reply #5 - Posted 2011-05-31 14:43:17 »

All opengl commands affecting the location, perspective and orientation do modify the current matrix. So gluLookAt() in your camera code manipulates the modelview-matrix (you switch to it with glMatrixMode()). Your set_rota() method now loads your generated matrix effectively replacing your camera transformation. It's like calling glLoadIdentity() after the camera before applying the rotations in your old code.

Mathias - I Know What [you] Did Last Summer!
Therion_

Senior Newbie

 « Reply #6 - Posted 2011-05-31 18:56:37 »

i am haaaappppyyyyy

now i really understand this system