rotating an object around a point
i''m trying just get this triangle to rotate around the pt. 0,3. the sides of the triangle spin and then collapse into the center of the triangle at the pt(0,3).. how do i keep them spinning where they are and not changing distance from that point.. here''s part of the code:
glBegin (GL_TRIANGLES);
glVertex3f(-1, 3, 3); glVertex3f(0, 4, 3);
glVertex3f(1, 3, 3);
glEnd();
x1 = (float)(0 + cos(angle)*(x1-0) - sin(angle)*(z1-3));
z1 = (float)(3 + sin(angle)*(x1-0) + cos(angle)*(z1-3));
x2 = (float)(0 + cos(angle)*(x2-0) - sin(angle)*(z2-3));
z2 = (float)(3 + sin(angle)*(x2-0) + cos(angle)*(z2-3));
x3 = (float)(0 + cos(angle)*(x3-0) - sin(angle)*(z3-3));
z3 = (float)(3 + sin(angle)*(x3-0) + cos(angle)*(z3-3));
thanks to anyone who can help
why dont you just use glRotatef(axis,x,y,z)
manual calculations are just a bitch
but i think this MIGHT work
not sure, thats off the topa my head, ill post a proper one l8ter
xr gives you X the coord & zr gives you the Z pos, (relative to
(0,0)!!!)
hope this helps
manual calculations are just a bitch
but i think this MIGHT work
static float angle;static float radius = 3.f;angle+=0.1f;float xr=(float)(cos(2*angle)*M_PI/360.f)/radius;float zr=(float)(sin(2*angle)*M_PI/360.f)/radius;...
not sure, thats off the topa my head, ill post a proper one l8ter
xr gives you X the coord & zr gives you the Z pos, (relative to
(0,0)!!!)
hope this helps
I'd use glTranslatef()....glRotate will rotate it around itself I think rather than around another point
I think that'll work but it's only off the top of my head...you can of course change the radius & y value in the translate
A CRPG in development...
Need help? Well, go FAQ yourself.
[edited by - Nazrix on March 19, 2002 11:02:49 PM]
float x, z, radius=3.0f;angle+=PI/180;x = radius * cos (angle);z = radius * sin (angle);glLoadIdentity();glTranslatef(x, 0, z+3); // z+3 cause of rotating around (0,3)// Then draw your triangle
I think that'll work but it's only off the top of my head...you can of course change the radius & y value in the translate
A CRPG in development...
Need help? Well, go FAQ yourself.
[edited by - Nazrix on March 19, 2002 11:02:49 PM]
Move the triangle back to the origin with glTranslate (better yet, just create it with the pivot point on the origin), rotate it with glRotate (all rotations are about 0,0,0) now move it back to where you want it with glTranslate
thanks for the answers.. i''m not sure what i will use yet.. i was just trying to rotate a triangle before i start rotating objects, such as a character in a game..
then my new question is can you use glRotatef() to rotate more than one object in different directions.. because that''s what this is all going to be used for, and i figured i could just do this by rotating the verticies individually, even though that''s probably an expensive call..
then my new question is can you use glRotatef() to rotate more than one object in different directions.. because that''s what this is all going to be used for, and i figured i could just do this by rotating the verticies individually, even though that''s probably an expensive call..
sure you can use glRotatef() in different directions:
LoadIdentity(); // reset the matricesglRotate();//draw whateverLoadIdentity(); // reset the matricesglRotate(); //rotate in a different direction//draw something else
Do not use loadIdentity. OpenGL has only one MODELVIEW matrix. If you just LoadIdentity you obliterate the view portion. Use glPushMatrix and glPopMatrix instead.
glPushMatrix (); //save view
//Do object rotate and transform
glPopMatrix (); //restore view
glPushMatrix (); //save view
//Do object rotate and transform
glPopMatrix (); //restore view
ok, i''m learning a lot of good stuff here.. so now the question is how do i use glRotate to rotate around a point?
the easiest method to undeeeerstand is
pushmatrix
translate to point
do rotation
popmatrix
http://uk.geocities.com/sloppyturds/gotterdammerung.html
pushmatrix
translate to point
do rotation
popmatrix
http://uk.geocities.com/sloppyturds/gotterdammerung.html
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement