#### Archived

This topic is now archived and is closed to further replies.

# rotation problems...

This topic is 5340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am working on a simple idea. I want to build a solar system, complete with a sun and planets. As it stands now, I can create a sun and planets, but each planet I add ends up rotating the previously added planet. (And the name ends up rotating also) SpriteOrbittingPossition* spriteOrbittingPossition = new SpriteOrbittingPossition( Vector3D(0.0f, 0.0f, 0.0f), //Start Position 5000, //Mass 5.2, //Radius Vector3D(1.0f, 0.0f, 0.0f), //Rotation Vector3D(2.0f, 0.0f, 0.0f), //Rotation Speed "Sun"); … spriteOrbittingPossition->addPlannet( Vector3D(18.0f, 0.0f, 0.0f), //Start Position 1, //Mass 1.3, //Radius Vector3D(1.0f, 0.0f, 0.0f), //Rotation Vector3D(2.0f, 0.0f, 0.0f), //Rotation Speed 2, //Speed (orbit) "Plannet 1" //Name ); spriteOrbittingPossition->addPlannet( Vector3D(12.0f, -9.0f, 0.0f), //Start Position 1, //Mass 1.3, //Radius Vector3D(-1.0f, 0.0f, 0.0f), //Rotation Vector3D(2.0f, 0.0f, 0.0f), //Rotation Speed 2, //Speed (orbit) "Plannet 2" //Name ); … for (int a = 0; a < spriteOrbittingPossition->numPlannets+1; ++a) { Mass* mass = spriteOrbittingPossition->getMass(a); Vector3D* pos = &mass->pos; glPrint(pos->x, pos->y + mass->r + .5, pos->z, mass->massName); glBindTexture(GL_TEXTURE_2D, texture[2]); glTranslatef(pos->x,pos->y,pos->z); glRotatef(mass->xrot,0.0f,0.0f,1.0f); glRotatef(0,mass->yrot,0.0f,1.0f); glRotatef(0,0.0f,mass->zrot,1.0f); gluSphere(quadratic, mass->r,32,32); mass->xrot += mass->xrotSpeed; mass->yrot += mass->yrotSpeed; mass->zrot += mass->zrotSpeed; }

##### Share on other sites
I think your problem can be solved using the functions glPushMatrix() and glPopMatrix(). Do something like: Draw Sun, then for each planet: call rotatef to rotate next planet around sun, push matrix, translate to position of next planet, draw planet, then pop matrix. Then rinse and repeat. If you want to rotate the planet on it''s axis also then do another rotate just before drawing it. Hope that helps!

##### Share on other sites
I am working on a similar kind of thing, so let me tell you what I learned so you don''t literally spend DAYS correcting the slightest errors like I did (3d transformations are a real pain in the neck)

Use quaternions for rotations (and make sure you multiply them in the correct order... I can''t stress this enough). Then when drawing an object you should do as little calls of glRotatef() as possible... otherwise, beyond a certain scale the stuff you draw will start flickering, because of floating point rounding errors in matrix calculations. Again, as a rule make sure you do as little transformations as possible, trust me. You wouldn''t find that out just by drawing planets, but when you''d draw the planets'' satellites those glitches would creep up.

Like the previous poster said, use glPushMatrix() and glPopMatrix(), that will solve your problem in the meantime. But you''ll probably have to rewrite your code anyway if you will want to draw tiny asteroids along with the sun and the planets which are considerably larger objects.

Its all a matter of scale really. There was a nice oldish article on gamasutra about building a solar system, I suggest you take a look at it, it''s very good.

##### Share on other sites
Thanks for the help guys! The push and pop functions took care of it.

I will look into quaternions, I hope they are easy, because I am kind of worn-out fixing my code.

Thanks again!

~EToreo

##### Share on other sites
quote:

I will look into quaternions, I hope they are easy, because I am kind of worn-out fixing my code.

*snicker*

##### Share on other sites
Well, it turns out that they are not *that* bad. just some math, and if you ignore that, they are cake!

~EToreo

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011321
• ### Who's Online (See full list)

There are no registered users currently online

×