MaverickHL

06-02-2001, 05:03 PM

Hi everyone, I need a little bit of help

building two objects and merging them into one whole object, if it is even possible. My school project requires a simulation using Runge Kutta and I need help animating it using a thin cylinder and sphere to represent a pendulum swinging. I am fairly new with OpenGL and started only about a week. I was if it is possible to merge a sphere and a cylinder and with the equation from Runge Kutta send values for the x and y coordinates swinging the pendulum.

MarcusL

06-03-2001, 08:19 AM

Drawing the cylinder is a bit tricky, since it is always aligned along the z-axis (extending towards positive). I suggest translating to the 'fixed' endpoint of the pendulum then rotating so that the positive z-axis is pointing towards the other endpoint.

Now you can draw your cylinder with gluCylinder. To draw the end of the pendulum, translate along the positive z-axis with the length of the pendulum. Now you have the 'local' origo perfectly positioned for drawing a sphere, using gluSphere.

It's all about moving between different coordinate systems, which takes a bit of time to get used to, but once you've got it, it's a breeze.

(Surrounding the above by glPushMatrix/glPopMatrix is a good idea, btw.)

[This message has been edited by macke (edited 06-03-2001).]

MaverickHL

06-04-2001, 06:43 PM

Thanks I was able to build the pendulum, now though when I tried to loop angle values for rotation it seems to always get stuck and the i variable seems to be changing the position of the pendulum, I dunno if its the equation or the code for looping, check this out:

void display(void)

{

quadratic=gluNewQuadric();

gluQuadricNormals(quadratic, GLU_SMOOTH);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/*For building sets of objects*/

glPushMatrix();

glColor3f (0.0f, 1.0f, 1.0f);

glTranslatef(0.0f,0.0f,-20.0f); // Center The Cylinder/Origin

glRotatef(90, 1.0f, 0.0f, 0.0f);//Orientates Cylinder

for (loop =0; loop <10; ++loop)

{

test.RK4(); //Class that does calculations

glRotatef(test.getTheta(), 0.0f,1.0f,0.0f);//Used to swing pendulum.

}

gluCylinder(quadratic,0.03f,0.03f,test.getLength() ,32,32); // Draw Our Cylinder

glTranslatef(0.0f,0.0f,test.getLength());//Aligns sphere with Clyinder

gluSphere(quadratic,0.3f,32,32); //Draw a Sphere

glPopMatrix();

glutSwapBuffers();

}

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.