Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (605) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 OpenGL Axis Rotations  (Read 2625 times) 0 Members and 1 Guest are viewing this topic.
kieve

Senior Newbie

I am Awesome.

 « Posted 2011-05-07 04:12:33 »

SOLVED
See my last post for details.

I am programming a 3x3 puzzle cube (aka Rubik's Cube) and I am having some difficulty with axis rotations.
When i press "X" i have the rotX increase by 90 degrees, the same goes for Y, and Z. You can only rotate on one axis at a time.
The problem is, I wish for my cube to rotate relative to my perspective. An example of what happens now is if i rotate 90 degrees on the X axis, then try rotating on the Y axis, the cube turns on (what i see to be) the Z axis.

 1  2  3 `      GL11.glRotatef(rotX, 1.0f, 0.0f, 0.0f);      GL11.glRotatef(rotY, 0.0f, 1.0f, 0.0f);      GL11.glRotatef(rotZ, 0.0f, 0.0f, 1.0f);`

If you wish to demo the program: File Beam
Controls:
1 - turn red
2 - turn orange
3 - turn blue
4 - turn green
5 - turn yellow
6 - turn white
X - rotate on "X" axis
Y - rotate on "Y" axis
Z - rotate on "Z" axis
Left Shift - Hold to turn / rotate opposite direction.
Right Shift - Reset cube.
Escape - Exit.
Enter - Scramble cube.
Backspace - Undo last move (includes scramble moves).

import universe.characteristics.Awesome
class kieve extends Awesome{
public kieve(){
beAwesome();
}
public void beAwesome(){
while(true)awesomeness++;
}
}
ra4king

JGO Kernel

Medals: 367
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #1 - Posted 2011-05-07 05:02:13 »

I get a NullPointerException in org.lwjgl.opengl.GL11.glShadeModel() at line 160 in rubikEngine.Engine.initGL()
I also get a RuntimeException saying "Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation." (haha they misspelled initialization) This was thrown inside the Slick library at line 426 in rubikEngine.Engine.loadTextures()

Hope that helped

Captain Awesome

Junior Devvie

Medals: 2

Hi

 « Reply #2 - Posted 2011-05-07 14:40:59 »

I get a NullPointerException in org.lwjgl.opengl.GL11.glShadeModel() at line 160 in rubikEngine.Engine.initGL()
I also get a RuntimeException saying "Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation." (haha they misspelled initialization) This was thrown inside the Slick library at line 426 in rubikEngine.Engine.loadTextures()

Hope that helped

The game worked fine here on W7.

To op: I see what you mean by that weird rotation thingy, it does seem like when you rotate around the x-axis, the y and z axis switch places with each other.
I haven't worked with opengl that much before, but wouldn't it be better to just have one glRotatef call? Like glRotatef(1.0f, rotX, rotY, rotZ); or something like that.
kieve

Senior Newbie

I am Awesome.

 « Reply #3 - Posted 2011-05-07 14:58:13 »

I get a NullPointerException in org.lwjgl.opengl.GL11.glShadeModel() at line 160 in rubikEngine.Engine.initGL()
I also get a RuntimeException saying "Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation." (haha they misspelled initialization) This was thrown inside the Slick library at line 426 in rubikEngine.Engine.loadTextures()

Hope that helped

The NPE might have been caused by your video card not supporting smooth shading, i removed it and re-uploaded. My The Slick texture loader is bound to fail sometimes, if it does it just loads with basic GL11.glColor3f() calls instead of texture binding, so that should be fine.

To op: I see what you mean by that weird rotation thingy, it does seem like when you rotate around the x-axis, the y and z axis switch places with each other.
I haven't worked with opengl that much before, but wouldn't it be better to just have one glRotatef call? Like glRotatef(1.0f, rotX, rotY, rotZ); or something like that.

Maybe, but from what I understand is that glRotatef(angle, x,y,z) where angle is the angle of rotation, and x,y,z is either 1.0f or 0.0f, depending if you want to rotate that angle on that axis. The problem is that the angle for each axis is not the same, say maybe I want to rotate 90 degrees on the X-axis, but 180 degrees on the Y-axis.

import universe.characteristics.Awesome
class kieve extends Awesome{
public kieve(){
beAwesome();
}
public void beAwesome(){
while(true)awesomeness++;
}
}
Captain Awesome

Junior Devvie

Medals: 2

Hi

 « Reply #4 - Posted 2011-05-07 15:01:33 »

To op: I see what you mean by that weird rotation thingy, it does seem like when you rotate around the x-axis, the y and z axis switch places with each other.
I haven't worked with opengl that much before, but wouldn't it be better to just have one glRotatef call? Like glRotatef(1.0f, rotX, rotY, rotZ); or something like that.

Maybe, but from what I understand is that glRotatef(angle, x,y,z) where angle is the angle of rotation, and x,y,z is either 1.0f or 0.0f, depending if you want to rotate that angle on that axis. The problem is that the angle for each axis is not the same, say maybe I want to rotate 90 degrees on the X-axis, but 180 degrees on the Y-axis.

Maybe, I just heard somewhere that you should minimize your calls to opengl. I should probably let someone more experienced answer this though
ra4king

JGO Kernel

Medals: 367
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #5 - Posted 2011-05-07 22:54:13 »

Haha now I get an NPE at the next line, glClearColor(), and the same Slick exception.
Wow, my computer is the crappiest thing ever :/

kieve

Senior Newbie

I am Awesome.

 « Reply #6 - Posted 2011-05-08 01:47:43 »

I have been reading, and I'm coming across "quaternions" frequently and "gimbal lock". Any help with this?

import universe.characteristics.Awesome
class kieve extends Awesome{
public kieve(){
beAwesome();
}
public void beAwesome(){
while(true)awesomeness++;
}
}
ra4king

JGO Kernel

Medals: 367
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #7 - Posted 2011-05-08 05:11:26 »

Are Google and Wikipedia broken again?

kieve

Senior Newbie

I am Awesome.

 « Reply #8 - Posted 2011-05-08 13:46:02 »

Are Google and Wikipedia broken again?

Absolutely not, like i said, I have been reading, a TON. The thing is I don't know how to implement it in OpenGL.

import universe.characteristics.Awesome
class kieve extends Awesome{
public kieve(){
beAwesome();
}
public void beAwesome(){
while(true)awesomeness++;
}
}
kieve

Senior Newbie

I am Awesome.

 « Reply #9 - Posted 2011-05-08 16:57:33 »

I have come up with some code that to me seems that it should work, but does not and does work.
 1  2  3  4  5  6  7  8  9  10  11  12  13 `if(rotating){   currentSpeed = rotationSpeed;   quatRotationChange.setFromAxisAngle(new Vector4f(turnX, turnY, turnZ, (isPrime? -1:1) * currentSpeed));         Quaternion.mul(quatCurrentRotation, quatRotationChange, quatCurrentRotation);   quatCurrentRotation.normalise();   createMatrixBuffer();}            GL11.glLoadIdentity();GL11.glTranslatef(0f, 0f, -10f);createMatrixBuffer();GL11.glMultMatrix(matrixBuffer);`

createMatrixBuffer method is this:
 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  35  36 `private void createMatrixBuffer(){   float w,x,y,z;   w = quatCurrentRotation.w;   x = quatCurrentRotation.x;   y = quatCurrentRotation.y;   z = quatCurrentRotation.z;   Matrix4f m = new Matrix4f();         m.m00 = sq(w) + sq(x) - sq(y) - sq(z);   m.m01 = 2 * x * y + 2 * w * z;   m.m02 = 2 * x * z - 2 * w * y;   m.m03 = 0;   m.m10 = 2 * x * y - 2 * w * z;   m.m11 = sq(w) - sq(x) + sq(y) - sq(z);   m.m12 = 2 * y * z + 2 * w * x;   m.m13 = 0;      m.m20 = 2 * x * z + 2 * w * y;   m.m21 = 2 * y * z - 2 * w * x;   m.m22 = sq(w) - sq(x) - sq(y) + sq(z);   m.m23 = 0;   m.m30 = 0;   m.m31 = 0;   m.m32 = 0;   m.m33 = sq(w) + sq(x) + sq(y) + sq(z);         matrixBuffer.clear();   m.store(matrixBuffer);   matrixBuffer.flip();}   private float sq(float x){   return x*x;}`

I used the formula found Here

import universe.characteristics.Awesome
class kieve extends Awesome{
public kieve(){
beAwesome();
}
public void beAwesome(){
while(true)awesomeness++;
}
}
Pages: [1]
 ignore  |  Print

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

 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (35 views) 2015-03-13 17:50:16 Olo (41 views) 2015-03-13 17:47:07 ClaasJG (40 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (47 views) 2015-03-05 14:36:23
 LiquidNitrogen 23x KevinWorkman 21x BurntPizza 21x basil_ 20x EgonOlsen 17x theagentd 16x Roquen 16x Riven 12x princec 12x Varkas 10x SHC 9x Ashedragon 8x NegativeZero 8x lcass 7x ClaasJG 7x teletubo 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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