Thanks for the fast reply.
that “did not work” thing meant that it seams to be very wrong
If I rotate the sprite a few degrees and try to let it move forward it moves
in one way and if I rotate it some more degrees it moves in a totally
I increse the angle with 0.15 if I press the right arrow on the keyboard and
-0.15 with the left arrow key (just for testing now). And then when I press
the up arrow it should move in the direction it is pointing to (just to
explain how I test this).
Well here the rendering / rotation code is:
(GL_Rect is a structure with the x,y,w,h in floats are in)
void gfx::draw_rect(GL_Rect rect, GLuint texture, double rotate)
glTranslatef(rect.x, rect.y, 0.0f);
glRotatef(rotate, 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0, 0);
glTexCoord2f(1.0f, 1.0f); glVertex2f(rect.w, 0);
glTexCoord2f(1.0f, 0.0f); glVertex2f(rect.w, rect.h);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0, rect.h);
Anything wrong in there?On Wednesday 10 September 2003 15.07, David Olofson wrote:
On Wednesday 10 September 2003 14.38, Alexander Bussman wrote:
I’m using OpenGL and SDL for a 2D game that I’m trying to make.
I have a sprite that I rotate with help of glRotatef and it works
but… I want to make the sprite to move in the direction that it
is “pointing to”, I cannot find a way to make it work.
I have tested with something like this (I read about it somewhere):
xpos += velx * std::cos(angle) * time_scale;
ypos += vely * -std::sin(angle) * time_scale;
But that did not work, anyone who knows how I can do this?
“Did not work” in what way?
The only thing I can imagine is that your sprites end up rotating in
the wrong direction, as a result of the visual rotation having a
different axis orientation from that of the game logic code above.
Anyway, the signs depend on the relation between OpenGL rotations and
axis orientation. Keep in mind that OpenGL things increasing Y means
upwards, while many other APIs has it the other way around!
If you’re not sure about this (and the trig and stuff), this is a case
where you can simply remove all “mysterious” negations, test, and
then insert one in a sensible place if things are mirrored.
Anyther thing to check: Are your sprite images drawn pointing in the
0? direction…? If not, you’ll have to fix them, or (probably
better) adjust the rendering rotation appropriately.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
— http://olofson.net — http://www.reologica.se —
SDL mailing list
SDL at libsdl.org