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



Recommended Posts

digitalerr0r    122
Hey, I have a Question. How do I make a object to move around in cricles...let''s say the I have a Sun, and some can I then make the planets to move around the sun ? The =)

Share this post

Link to post
Share on other sites
Sebbi    122
i think that it is the best thing to use the glRotate functions to rotate objects around a circle ...

the example of a solarsystem is good for explaining it ... may be you set the sun into the origin of the coordsystem ... then you declare a variable holding the angle of the planet and you increment it every frame ... you will give that variable as the angle parameter to the glRotate function ... but first you have to translate the object about the radius away from the origin with the glTranslate function after that you have to rotate ...

but you have to implement it the other way round ...

-> first rotate
-> than translate


hope it helps ... you can do it of course with the help of sin and cosine but therefore you have a lot of calculation that is not nessecary ...


Share this post

Link to post
Share on other sites
Jankey    122
ämm ...
whats about sin & cos ?
somewhere in the DrawGLScene

void DrawGLScene()


rot += 0.001f; // Global Defined!! -> GLfloat rot = 0.0;

obejct.x = sin( rot / speed ) * Radius;
obejct.y = 0.0;
obejct.x = cos( rot / speed ) * Radius;

glTranslatef(obejct.x , obejct.y , obejct.z );

// The works!



Share this post

Link to post
Share on other sites
Vlion    151
i used:

x = (a)sin(time)
y = (b)cos(time)

Vary the a and b vars and you come up with a ellipse.

If its just basic shaded spheres you really dont need to worry about rotating.

I actually have some elementry solar system code laying around, if you care to look at it.

I came, I saw, I got programmers block.

Share this post

Link to post
Share on other sites
ANSI2000    122
YEah helpfull but very slow... If you wish to do it the math way... Pre compute your angles in an array.

The Rotate and transalte method will be alot faster though.

1- Translate your sun to the "middle" of the scene.
2- For each planet push matrix stack glRotate and glTranslate pop matrix stack.

glTranslate // Transform Scene
glRotate // TrasnFor Scene
glScale // Transform Scene

draw sun

for each planet
draw planet

Edited by - ANSI2000 on October 22, 2001 4:01:51 PM

Share this post

Link to post
Share on other sites
Ranger_One    300

Don''t know how complex your simulation will become- but here is 1 limitation I found myself:

Do the positioning of the objects yourself in OpenGL. This way you can do accurate depth testing of objects and force a proper draw order.

Here is my rant:

I have a OpenGL driven 3d engine and was developing an advanced blending effects demo. In this demo I had three objects, one blended textured quad in the center, one transparent quad in the back, and some texture text in the front. The entire scene was rotated using glRotate().
Everything would work fine until the object in the back was rotated in the front, then it would actually become solid and block the other objects. After struggling for a bit- I discovered the cause. I was using the GL standard DEPTH_TEST, and when the first object drawn is in the front, it cause the other objects to fail the DEPTH_TEST and not be rendered.
My FIX: Rotate/Transform the objects using matrix math (like OpenGL would)- then use fast sqrt functions to figure the depth and qsort the objects from back to front, so the draw order is always proper.

My two cents,

Share this post

Link to post
Share on other sites
cMADsc    122
This post came at a good time. I am making a solar system demo right now, just the sun and 9 planets for now. I currently use glPop and glPush for each planet. Although, doesn''t all the pushing and popping add to the overall time?

"There are ones that say they can and there are those who actually do."

"...u can not learn programming in a class, you have to learn it on your own."

Share this post

Link to post
Share on other sites