Angle conversion

Hi, I am trying to convert the following command to a Euler angle (roll, pitch, yaw), but I am not sure how to do it. Does anyone have a routine that will do the conversion?

glRotatef(360.0f-heading,0,1.0f,0)

Thanks,

Jamie

Sure

roll=0.0f;
pitch=heading;
yaw=0.0f;

Now that was easy …

Thats what I thought but when I replace

glRotatef(360.0f-heading,0,1.0f,0);

with

GL_QUAT q;
GLfloat m[4][4];
gluEulerToQuat_EXT(0, heading, 0, &q);
gluQuatToMat_EXT(&q, m);
glMultMatrixf(&m[0][0]);

The program doesn’t work. I am trying to use quaternions in some code for 3D movement but when you rotate the view and then try and move forward, you don’t head exactly in the direction that you’re facing. You sort of side forward/sideways. Any ideas?

Ahh, now you’re talking. When you rotate your view, you transform your local coordinate system. That’s why translations can go in unexpected directions.

Try swapping the order in which you do translation and rotation.

Here’s a snippet from my code:

void
Camera::set_modelview()const
{
	glLoadMatrixf(orientation);
	glTranslatef(-translate.x,-translate.y,-translate.z);
}

So in my case, I rotate first, then translate. Always did it for me (static terrain geometry, free camera, absolute camera position in world space).

It’s still not working.

My code, as it stands is as follows…

int domScene: raw(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );

GL_QUAT q;
GLfloat m[4][4];
gluEulerToQuat_EXT(0, heading, 0, &q);
gluQuatToMat_EXT(&q, m);
glMultMatrixf(&m[0][0]);

if (walkMode)
{
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
glTranslatef(xtrans, 0.0f, ztrans);
}

// … Drawing stuff is here

glFlush();
}

void ProcessKeys()
{
if (DomScene.GetWalkMode())
{
if (DomScene.GetKey(VK_UP))
{
DomScene.xpos -= (float)sin(DomScene.heading * piover180) * 0.05f;
DomScene.zpos -= (float)cos(DomScene.heading * piover180) * 0.05f;
}
if (DomScene.GetKey(VK_DOWN))
{
DomScene.xpos += (float)sin(DomScene.heading * piover180) * 0.05f;
DomScene.zpos += (float)cos(DomScene.heading * piover180) * 0.05f;
}
if (DomScene.GetKey(VK_LEFT))
{
DomScene.heading += 0.01f;
}
if (DomScene.GetKey(VK_RIGHT))
{
DomScene.heading -= 0.01f;
}
}
if (DomScene.GetKey(‘W’))
{
DomScene.ToggleWalkMode();
DomScene.ClearKey(‘W’);
}
}

any idea what I’m doing wrong?

Thanks for all your help :slight_smile:

woops! the firt line should have read:

int domScene::Draw(GLvoid)

Not to worry, I’ve figured it out! The routine that I was using to convert the angles expected the values in radians. Obviously I supplied them in degrees! I have replaced the routine with one that expects degrees and it now works fine.

Thanks for your help :slight_smile:

Jamie