Archived

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

rotating an object around a point

This topic is 5747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
why dont you just use glRotatef(axis,x,y,z)
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

Share this post


Link to post
Share on other sites
I'd use glTranslatef()....glRotate will rotate it around itself I think rather than around another point


        
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
sure you can use glRotatef() in different directions:


  
LoadIdentity(); // reset the matrices

glRotate();
//draw whatever


LoadIdentity(); // reset the matrices

glRotate(); //rotate in a different direction

//draw something else




Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
glRotate takes the angle in degrees (yes, its actually degrees and not radians) and the axis of rotation.

glRotatef (90, 0, 1, 0);

rotates by 90 degrees with respect to the origin about the y axis.

Share this post


Link to post
Share on other sites
so the first is the rotation angle and the second the axis around which it will be rotated thx

is there another rotation where i can specify the angle at every axis?

Share this post


Link to post
Share on other sites
there is no "angle at each axis", the euler-angles are completely wrong math, works only in integrals for differencials of angles.

axis-angles are the way to go, its always an angle around some axis, nothing more, nothing less.

for good rotation/orientation-representation, use quaternions or 3x3-rotation-matrices. you can find a lot of info about it..

to rotate around a point, bring the point to the origin, rotate around the origin, and move back..

Share this post


Link to post
Share on other sites