Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
30 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

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.



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13670

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.

#3 dejaime   Crossbones+   -  Reputation: 4053

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.


#4 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 02 February 2014 - 10:02 PM

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



#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 02 February 2014 - 10:04 PM

I am using c++ and opengl



#6 richardurich   Members   -  Reputation: 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   Crossbones+   -  Reputation: 13670

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.

#8 Trienco   Crossbones+   -  Reputation: 2215

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

#9 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 February 2014 - 08:59 PM

should I repost my code?



#10 dejaime   Crossbones+   -  Reputation: 4053

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?



#11 phil67rpg   Members   -  Reputation: 767

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



#12 phil67rpg   Members   -  Reputation: 767

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();
}


#13 phil67rpg   Members   -  Reputation: 767

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.



#14 dejaime   Crossbones+   -  Reputation: 4053

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?

#15 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 23 February 2014 - 05:04 PM

it rotates around the screen origin



#16 Paradigm Shifter   Crossbones+   -  Reputation: 5411

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

#17 Lactose!   GDNet+   -  Reputation: 3620

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.



#18 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 23 February 2014 - 05:40 PM

what math should  I study



#19 Paradigm Shifter   Crossbones+   -  Reputation: 5411

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

#20 phil67rpg   Members   -  Reputation: 767

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.



PARTNERS