#### Archived

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

# rotating an object around a point

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

## 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 on other sites
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 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 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 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 on other sites
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

##### 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 on other sites
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?

##### Share on other sites
the easiest method to undeeeerstand is

pushmatrix
translate to point
do rotation
popmatrix

http://uk.geocities.com/sloppyturds/gotterdammerung.html

##### Share on other sites
do i use degrees or coordinate with the glrotate command

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631710
• Total Posts
3001846
×