Java-Gaming.org
 Featured games (81) games approved by the League of Dukes Games in Showcase (497) 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
 OpenGL Axis Rotations  (Read 2398 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: 345
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 Member

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.
 Games published by our own members! Check 'em out!
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 Member

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: 345
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: 345
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.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 UprightPath (8 views) 2014-09-20 20:14:06 BurntPizza (26 views) 2014-09-19 03:14:18 Dwinin (40 views) 2014-09-12 09:08:26 Norakomi (70 views) 2014-09-10 13:57:51 TehJavaDev (95 views) 2014-09-10 06:39:09 Tekkerue (49 views) 2014-09-09 02:24:56 mitcheeb (70 views) 2014-09-08 06:06:29 BurntPizza (52 views) 2014-09-07 01:13:42 Longarmx (39 views) 2014-09-07 01:12:14 Longarmx (45 views) 2014-09-07 01:11:22
 BurntPizza 36x Riven 18x Rayvolution 18x ags1 16x princec 16x basil_ 16x KevinWorkman 15x LiquidNitrogen 12x theagentd 11x kevglass 11x deathpat 11x nsigma 11x HeroesGraveDev 8x The Lion King 7x TehJavaDev 6x PandaMoniumHUN 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