glrotation to vectors

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 :slight_smile:

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.

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… :slight_smile:

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

its working 99.0% :slight_smile:

the only thing is, and that i think is what cylab wrote, is the [quote]multiply your objects vertices
[/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 :slight_smile:

// Paint object with vector offset 0


        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


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


    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


You are overwriting your modelview matrix. Use glMultMatrix() instead of glLoadMatrix().

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.

i am haaaappppyyyyy :wink:

now i really understand this system :slight_smile:

its ALL working perfect…and i can start with my mad space sim idea :slight_smile:

much thanks for that help :slight_smile: