Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (496) Games in Android Showcase (114) games submitted by our members Games in WIP (563) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 glrotation to vectors  (Read 1596 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: 49

 « 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...
 Games published by our own members! Check 'em out!
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
multiply your objects vertices
.

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

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

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.

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

its ALL working perfect..and i can start with my mad space sim idea

much thanks for that help
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 BurntPizza (14 views) 2014-09-19 03:14:18 Dwinin (32 views) 2014-09-12 09:08:26 Norakomi (58 views) 2014-09-10 13:57:51 TehJavaDev (80 views) 2014-09-10 06:39:09 Tekkerue (40 views) 2014-09-09 02:24:56 mitcheeb (62 views) 2014-09-08 06:06:29 BurntPizza (46 views) 2014-09-07 01:13:42 Longarmx (33 views) 2014-09-07 01:12:14 Longarmx (37 views) 2014-09-07 01:11:22 Longarmx (36 views) 2014-09-07 01:10:19
 BurntPizza 37x Riven 17x Rayvolution 17x princec 17x basil_ 16x ags1 16x KevinWorkman 15x kevglass 12x nsigma 11x theagentd 11x LiquidNitrogen 10x SHC 8x HeroesGraveDev 8x The Lion King 7x Gibbo3771 6x cylab 6x
 List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06List of Learning Resources2014-07-31 11:54:12HotSpot Optionsby dleskov2014-07-08 01:59:08
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org