Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotation Issue

Started by Luvman79 Jun 13, 2002 at 11:13 PM 1 replies 1.1k views
Original Post
Luvman79
Luvman79
I''m learning how to rotate objects and using Stacks, the small snippet of code is as follows glTranslatef(0.0f, 0.0f, -5.0f); glRotatef(fangle, 0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(0.5f, 0.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_POLYGON); auxSolidSphere(1.0); glEnd(); glPopMatrix(); I''m trying to just rotate the sphere around the origin, but I don''t want the sphere to spin around it''s axis. How do I do this? I''ve tried a few things and just can''t figure it out. One other thing, I''ve read the websites about Cg, but how do you use it with OpenGL?
:) Keep On Smiling :)
Advinus
Advinus
What you are trying to do is actully a little harder then you think it is glRotate will only rotate about the axis you specify not around a center i have include a function that i use for rotateing my camera around a point and you should be a ble to modify it for your purpose also take a look at www.gametutorials.com which is actully where i got this code from they will explian the techniques quite well in there camera tutorials

void CCamera::RotateAroundPoint(CVector3 vCenter, float X, float Y, float Z)
{
CVector3 vVector; // Vector for the position/view.

// To rotate our position around a point, what we need to do is find
// a vVector from our position to the center point we will be rotating around.
// Once we get this vVector then we rotate it along the specified axis with
// the specified degree. After that we add it to the center point that we
// rotated around (vCenter). That''s all it takes.

// Get the vVector from our position to the center we are rotating around

vVector.x = m_vPosition.x - vCenter.x; // This gets the direction of the X
vVector.y = m_vPosition.y - vCenter.y; // This gets the direction of the Y
vVector.z = m_vPosition.z - vCenter.z; // This gets the direction of the Z

// Rotate the position along the desired axis around the desired point vCenter
if(X) {
// Rotate the position up or down, then add it to the center point
m_vPosition.z = (float)(vCenter.z + sin(X)*vVector.y + cos(X)*vVector.z);
m_vPosition.y = (float)(vCenter.y + cos(X)*vVector.y - sin(X)*vVector.z);
}
if(Y) {
// Rotate the position right or left, then add it to the center point
m_vPosition.z = (float)(vCenter.z + sin(Y)*vVector.x + cos(Y)*vVector.z);
m_vPosition.x = (float)(vCenter.x + cos(Y)*vVector.x - sin(Y)*vVector.z);
}
if(Z) {
// Rotate the position diagnally right or diagnally down, then add it to the center point
m_vPosition.x = (float)(vCenter.x + sin(Z)*vVector.y + cos(Z)*vVector.x);
m_vPosition.y = (float)(vCenter.y + cos(Z)*vVector.y - sin(Z)*vVector.x);
}


// Now m_vPosition should be our new rotated position
}
and you would call it like this

g_Camera.RotateAroundPoint(g_Camera.m_vView, 0, -SPEED, 0);

hope this helps
iGore
iGore
What I would do is just change the order of Translating and Rotating. Usually you translate and then rotate, but if you rotate and then translate, you will get whatever object spinning around the origin. I used that method to create a spiral particle engine.

www.geocities.com/igoreprod
-iGore-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.