Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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 1567 times)
0 Members and 1 Guest are viewing this topic.
Offline 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 Smiley



Offline cylab

JGO Ninja


Medals: 43



« 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!
Offline 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... Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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?
Offline Therion_

Senior Newbie





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


its working 99.0% Smiley

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 Smiley

// 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

Offline cylab

JGO Ninja


Medals: 43



« 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!
Offline Therion_

Senior Newbie





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

i am haaaappppyyyyy Wink

now i really understand this system Smiley


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

much thanks for that help Smiley
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.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (28 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!