Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

JOGL problem

Name: Anonymous 2010-04-27 16:58

hey i ve got a problem with JOGL(Java + openGL). I have created a hero that the user controls. any ideas how i can make it move to explore an area? till now i have achieved to make him move forward and rotate its body but when it rotates and i press the forward key again it keeps on moving in the same direction as before the rotation but with its body rotated.

Name: Anonymous 2010-04-27 17:02

You mean you copied someone else's code without understanding it and now you want our help?

Name: Anonymous 2010-04-27 17:08

no it is my code but i have a problem making my hero explore an area. it is not acting as it should. i do:

gl.glRotatef(rotate, 0.0f, 1.0f, 0.0f);
gl.glTranslatef(0.0f, 0.0f, move);

where rotate is a value that increases as 'w' is pressed and move is a value that increases/decreases when 'a' or 'd' are pressed. i use these inside a glPushMatrix(), glPopMatrix() that inside i keep everything but the hero.

Name: Anonymous 2010-04-27 17:17

This sounds like a concept of video games problem, not a JOGL problem (after-all, it's basically just OpenGL all wrapped into a Java class).  This may even be just an OpenGL problem.

It sounds like the only thing you are doing is rotating the graphics object but not the movement vector.  A good idea is to keep those two concepts separated but indirectly connected.
For example, when you press "Up" you move unit_vector(1.0, 0.0, 0.0); when you turn 90-degrees, pressing "Up" should move you unit_vector(0.0, +/-1.0, 0.0).  You need to make that calculation.

Name: Anonymous 2010-04-27 17:25

actually i was thinking of something like:

gl.glRotatef(rotate, 0.0f, 1.0f, 0.0f);
gl.glTranslatef(move * s1, 0.0f, move * s2);

where s1 becomes as the environment rotates:

         0 (heading up)

-1(heading left)       1 (heading right)

         0 (heading down)

and s2 becomes:

     1
0        0
    -1

Name: Anonymous 2010-04-27 17:32

Ignore OpenGL; that is not the problem, as >>4 said.
Imagine those two functions are something you have written:
rotate_guy( rotation );
move_guy( 0, 1 );

move_guy, as you have written it, does not care about the rotation of the guy. Why should it? Position and rotation are independent of each other.

This is what happens. OpenGL does not care about an object's rotation when moving it. You need to take into account the rotation of the guy, through trigonometry or vectors or otherwise.
move_guy( sin( rotation ), cos( rotation ) );

Name: Anonymous 2010-04-27 17:32

i tried s1 = (float)Math.cos(rotate%360)
and s2 = (float)Math.sin(rotate%360)

but now when i hit 'a' or 'd' the whole screen rotates not just the object!

Name: Anonymous 2010-04-27 17:34

>>7
Rotate it back again after drawing the object.

Name: Anonymous 2010-04-27 17:44

>>6 what you said makes sense but this way the hero does not stay in position while rotating.

>>8 what do you mean? maybe you wanted to say translate it back right? i m working on it now!

Name: Anonymous 2010-04-27 17:58

well i think i found my problem! Math.cos() and Math.sin() both work with rads so i should convert it to rads!

Name: Anonymous 2010-04-27 18:12

>>9
You need to define the center of the "hero" as the position to rotate around.
Here's a thought:
Set a vector to 1.0 0.0 0.0 connected to "Up" and whenever you press "Up" you glTranslatefthe Hero this vector. Call this vector R(x, y, z).

When you press left or right you glRotatef the hero as many radians as turned; but, you also make R equal to (x + cos(r), y + sin(r), 0).  There's more to it than that, but the basic idea is you alter the direction the Hero will walk when you glTranslatef with "Up."  As these are concepts, you will need to modify the calculations so that they work with whatever other movement code you have prepared but this is the core idea.

Name: Anonymous 2010-04-27 18:12

>>10
Instead of chiding you I'm just going to remark that Nintendo uses 0..255 ``degrees'' to the circle on the DS. I thought it was stupid at first but since powers of two halve nicely (int->int, no remainder) I've changed my mind. It's very nice for approximating in your head.

Name: Anonymous 2010-04-27 18:22

>>12
powers of two halve nicely
I don't quite get what you mena and your point.

Name: Anonymous 2010-04-27 18:37

>>13
That's because you just shipped in from /pr/ and haven't yet read your SICP.

Name: Anonymous 2010-04-27 18:47

>>14
No, it's because you're a jerkface.

Name: Anonymous 2010-04-27 19:51

>>15
I'm a jerkface? I'm going to stop helping you now. I must maintain the integrity of my character after all.

Name: Anonymous 2010-04-27 20:45

>>13
I have no clue.  I imagine his point was intended to be something about how clever Nintendevs were at condensing circular rotation to an eight-bit base two number (and not allowing half degrees, I guess) but his supporting argument confused me.

I think he may be arguing this: Nintendo can ignore the first bit in the eight bit number and will produce a correct, rounded down value.  Consider:
02: 00000010 is 00000010 + 00000000;
  00000010 divided by 2, rounded down, is 00000001 (1)
03: 00000011 is 00000010 + 00000001;
  00000010 divided by 2, rounded down, is 00000001 (1)
05: 00000101 is 00000100 + 00000001;
  00000100 divided by 2, rounded down, is 00000010 (2)
10: 00001010 is 00001010 + 00000000;
  00001010 divided by 2, rounded down, is 00000101 (5)
12: 00001100 is 00001100 + 00000000;
  00001100 divided by 2, rounded down, is 00000110 (6)
13: 00001101 is 00001100 + 00000001;
  00001100 divided by 2, rounded down, is 00000110 (6)

... I don't know.  I'm just speculating on ramblings.

Name: Anonymous 2010-04-27 20:55

>>17
This is a bitwise operator zone.  All bits are subject to controlled shifting in this zone.

Name: Anonymous 2010-04-27 20:58

>>16
And how were you helping me in the first place?

since powers of two halve nicely
As do other numbers. I believe that your point was that you can represent any 1/2n of a circle as a whole number (instead of going 45 -> 22.5), but your wording was awkward.

Name: Anonymous 2010-04-27 20:59

>>16 OP here. >>15 was not posted by me! sorry anyway

Name: Anonymous 2010-04-27 21:01

OP again. >>19 not posted by me as well

Don't change these.
Name: Email:
Entire Thread Thread List