Archived

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

scottdewald

Create Matrix from Vectors

Recommended Posts

I have an airplane that contains four vectors, m_pos, m_lookAt, m_right, and m_up. I am pretty sure that I am doing the rotations correctly when the user moves the joystick, but the plane is not rendering w/ the correct orientation. I read somewhere else that I could create a rotation/translation matrix from my vectors, but is is not working correctly. Here is my render method:
void CPlayer::render(CCamera *p_cam)
{
    float m[16];

    m[0] = m_right.x; m[4] = m_up.x; m[8] = m_lookAt.x; m[12] = 0.0f;
    m[1] = m_right.y; m[5] = m_up.y; m[9] = m_lookAt.y; m[13] = 0.0f;
    m[2] = m_right.z; m[6] = m_up.z; m[10]= m_lookAt.z; m[14] = 0.0f;
    m[3] = m_pos.x;   m[7] = m_pos.y;m[11]= m_pos.z;    m[15] = 1.0f;

    glPushMatrix();
        glLoadIdentity();
        glMultMatrixf(m);
        CObjModel::render(p_cam);
    glPopMatrix();
}
[edited by - scottdewald on March 20, 2004 9:31:15 PM]

Share this post


Link to post
Share on other sites
Your rendering routine doesn''t help us if we don''t know how you''re calculating your rotations. Are you using yaw/pitch/roll?


"Gay marriage will encourage people to be gay, in the same way that hanging around tall people will make you tall." - Grizwald

Share this post


Link to post
Share on other sites
Here are the functions I use for rotations:

void CPlayer::rotateYaw(float p_fDegYaw)
{
static float fRad;
fRad = DEG2RAD(p_fDegYaw);

rotate(m_lookAt, fRad, m_up); // rotates m_lookAt about m_up

rotate(m_right, fRad, m_up); // rotates m_right about m_up

m_up = cross(m_right, m_lookAt);
}

void CPlayer::rotatePitch(float p_fDegPitch)
{
static float fRad;
fRad = DEG2RAD(p_fDegPitch);

rotate(m_lookAt, fRad, m_right); // rotates m_lookat about m_right

rotate(m_up, fRad, m_right); // rotates m_up about m_right

m_right = cross(m_lookAt, m_up);
}

void CPlayer::rotateRoll(float p_fDegRoll)
{
static float fRad;
fRad = DEG2RAD(p_fDegRoll);

rotate(m_up, fRad, m_lookAt); // rotates m_up about m_lookAt

rotate(m_right, fRad, m_lookAt); // rotates m_right about m_lookAt

m_lookAt = cross(m_up, m_right);
}

[edited by - scottdewald on March 20, 2004 9:23:35 PM]

[edited by - scottdewald on March 20, 2004 9:28:54 PM]

[edited by - scottdewald on March 20, 2004 9:30:00 PM]

Share this post


Link to post
Share on other sites