• Create Account

## rotating space ship

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

30 replies to this topic

### #1phil67rpg  Members

213
Like
0Likes
Like

Posted 02 February 2014 - 09:40 PM

well I am going back to opengl.I am working on an asteroids game.it has been a long time since I have posted. I really like opengl.my question is how do I get a space ship rendered using line loop and vertices rotate around its center relative to where its drawn. I know I have asked this question before but I never solved this problem. I know I should use glRotate and glTranslate commands in the correct order.

### #2Álvaro  Members

20254
Like
3Likes
Like

Posted 02 February 2014 - 09:55 PM

What did you try? If that didn't work, try reversing the order of the rotation and the translation.

### #3dejaime  Members

4157
Like
2Likes
Like

Posted 02 February 2014 - 09:58 PM

What did you try? If that didn't work, try reversing the order of the rotation and the translation.

Take a look here. Looks like it is still an unsolved problem...

phil, what's your native language?

Edited by dejaime, 02 February 2014 - 10:01 PM.

### #4phil67rpg  Members

213
Like
0Likes
Like

Posted 02 February 2014 - 10:02 PM

I have tried reversing the order of the rotation and translate commands.

### #5phil67rpg  Members

213
Like
0Likes
Like

Posted 02 February 2014 - 10:04 PM

I am using c++ and opengl

### #6richardurich  Members

1187
Like
4Likes
Like

Posted 02 February 2014 - 10:34 PM

First, you have to translate your object so its center is at the origin. Then you rotate your object, and then you translate your object to its final destination.

### #7Álvaro  Members

20254
Like
4Likes
Like

Posted 02 February 2014 - 10:48 PM

First, you have to translate your object so its center is at the origin. Then you rotate your object, and then you translate your object to its final destination.

Yes, but objects typically start centered around the origin (a.k.a. "model space" or "model coordinates") and then they get put in the world through a transformation that consists of a rotation and a translation. I don't know why that basic method won't work for him.

### #8Trienco  Members

2555
Like
3Likes
Like

Posted 02 February 2014 - 10:50 PM

First, you have to translate your object so its center is at the origin. Then you rotate your object, and then you translate your object to its final destination.

That only works if you look at things from a "world view". Rotating (with glRotate) changes the local coordinate system of the object and the translation will move along the local coordinate system axes (just like rotation always happens around the current origin, aka. the objects position).

So the order in OpenGL (assuming the object is modeled around the origin) is glTranslate into position and then glRotate.

At least "thinking local" would seem a lot more intuitive than saying "OpenGL is doing everything backwards for some reason".

Of course those functions are technically deprecated and once handling matrices yourself it all boils down to multiplication order.

f@dzhttp://festini.device-zero.de

### #9phil67rpg  Members

213
Like
0Likes
Like

Posted 16 February 2014 - 08:59 PM

should I repost my code?

### #10dejaime  Members

4157
Like
0Likes
Like

Posted 16 February 2014 - 09:39 PM

Please, do post an updated version of it.

Can you do a small test?

What happens if you only rotate, and remove the translate?

What happens if you only translate?

### #11phil67rpg  Members

213
Like
0Likes
Like

Posted 16 February 2014 - 09:40 PM

What happens if you only rotate, and remove the translate?
What happens if you only translate?

ok I will try that

### #12phil67rpg  Members

213
Like
0Likes
Like

Posted 16 February 2014 - 09:43 PM

here is my code

void DrawShip(GLfloat position_X,GLfloat position_Y, GLfloat position_Z, GLfloat rotation,GLfloat color)
{
glPushMatrix();
glColor3f(color,0.0f,0.0f);
glRotatef(rotation,0.0f,0.0f,1.0f);
glTranslatef(position_X,position_Y,position_Z);
glBegin(GL_LINE_LOOP);
glVertex3f(0.0f,-0.25f,0.0f);
glVertex3f(-0.25f,-0.5f,0.0f);
glVertex3f(-0.5f,-0.5f,0.0f);
glVertex3f(-0.0f,0.5f,0.0f);
glVertex3f(0.5f,-0.5f,0.0f);
glVertex3f(0.25f,-0.5f,0.0f);
glVertex3f(0.0f,-0.25f,0.0f);
glEnd();
glPopMatrix();
}


### #13phil67rpg  Members

213
Like
0Likes
Like

Posted 22 February 2014 - 09:51 PM

I tried rotate only and it only rotates and I tried translate only and it only moves.

### #14dejaime  Members

4157
Like
0Likes
Like

Posted 22 February 2014 - 11:00 PM

I tried rotate only and it only rotates
But does it rotates correctly? Or around some weird point?

### #15phil67rpg  Members

213
Like
0Likes
Like

Posted 23 February 2014 - 05:04 PM

it rotates around the screen origin

### #16Paradigm Shifter  Members

5832
Like
3Likes
Like

Posted 23 February 2014 - 05:06 PM

I'm pretty sure you are beyond help you've been asking this same question for years. Have you tried learning some maths?

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #17Lactose!  GDNet+

9616
Like
1Likes
Like

Posted 23 February 2014 - 05:09 PM

I'm pretty sure you are beyond help you've been asking this same question for years. Have you tried learning some maths?

http://www.arcsynthesis.org/gltut/

This might be of help.

Hello to all my stalkers.

### #18phil67rpg  Members

213
Like
0Likes
Like

Posted 23 February 2014 - 05:40 PM

what math should  I study

### #19Paradigm Shifter  Members

5832
Like
0Likes
Like

Posted 23 February 2014 - 05:42 PM

Vectors and linear algebra.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #20phil67rpg  Members

213
Like
0Likes
Like

Posted 23 February 2014 - 06:07 PM

what part of linear algebra should I focus on?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.