PDA

View Full Version : move cube on circle



alex2
04-05-2011, 02:11 PM
Sry for my English.
I translate right part my cube on invisible circle on right but I would like to stop left side this cube in sphere - see on below images:
http://img808.imageshack.us/i/91488272.jpg/
http://img405.imageshack.us/i/58047318.jpg/
now left side my cube is in the same position like right part during translation :p

This is my code:



if (rotateValueZ <= 0) rotateValueZ = 360;
else rotateValueZ -= 1;

//cube:
glLoadIdentity();
glTranslatef(5.0f, 10.0f, -70.0f);
glTranslatef(5.0f * cos(PI * rotateValueZ / 180), 5.0f * sin(PI * rotateValueZ / 180), 0);
glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
glScalef(0.02f, 1.0f, 0.02f);
glutSolidCube(50.0f);

//circle:
glLoadIdentity();
glTranslatef(-20.0f, 10.0f, -70.0f);
glTranslatef(float(5.0f) * cos(2 * 3.14 * rotateValueZ / 360), 0, 0);
glutSolidSphere(1.5, 7, 7);

alex2
04-06-2011, 04:34 AM
I have added:


glRotatef(asin(5.0f / 50.0f) * 180 / PI * sin(PI * rotateValueZ / 180), 0, 0, 1);


ant it works but I don't understand this code - can somebody tell me how it works ?

mobeen
04-06-2011, 05:01 AM
ant it works but I don't understand this code - can somebody tell me how it works?

Hmmm u have added this statement so u should be in a better position to answer this not us.

alex2
04-06-2011, 05:20 AM
I have found this code in google.