Circles

Started by
8 comments, last by digitalerr0r 22 years, 5 months ago
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 planets...how can I then make the planets to move around the sun ? The =)
Advertisement
look into using sin and cos

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
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 ...

cu


Thx for the help, i''l try these things out =)
ämm ...
whats about sin & cos ?
somewhere in the DrawGLScene

void DrawGLScene()
{

blabla;

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!

blabla;

}
J.A.N.K.E.Y.: Journeying Artificial Nocturnal Killing and Exploration Youth
i used:

x = (a)sin(time)
y = (b)cos(time)
glTranslate(x,y,z);

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.
(pdn@rmci.net)



I came, I saw, I got programmers block.
~V''''lion
~V'lionBugle4d
got it to work now, hehe...sin and cos are damn cool(and helpfull) =))

cya, and thx for all the replays!!§
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

glPushMatrix
glTranslate
draw sun

for each planet
{
glPushMatrix
glRotate
glTranslate
draw planet
glPopMatrix
}glPopMatrix



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

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,
Ranger

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."

-----------------------------"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."

This topic is closed to new replies.

Advertisement