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?

Thanks,

Jamie

Sure

``````roll=0.0f;
yaw=0.0f;
``````

Now that was easy …

Thats what I thought but when I replace

with

GL_QUAT q;
GLfloat m[4][4];
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
{
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];
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))
{
}
if (DomScene.GetKey(VK_RIGHT))
{
}
}
if (DomScene.GetKey(‘W’))
{
DomScene.ToggleWalkMode();
DomScene.ClearKey(‘W’);
}
}

any idea what I’m doing wrong?