Advertisement

Question about the view matrix

Started by July 07, 2001 01:03 PM
0 comments, last by gameovercl 23 years, 7 months ago
Well.. I''m switching from D3D to OpenGL and suffering a lot On D3D, you set (by hand) the view matrix this way:
  D3DXMATRIX* WINAPI D3DXMatrixLookAtLH
    ( D3DXMATRIX *pOut, const D3DXVECTOR3 *pEye, const D3DXVECTOR3 *pAt,
      const D3DXVECTOR3 *pUp )
{
#if DBG
    if(!pOut || !pEye || !pAt || !pUp)
        return NULL;
#endif

    D3DXVECTOR3 XAxis, YAxis, ZAxis;

    // Get the z basis vector, which points straight ahead; the

    // difference from the eye point to the look-at point. This is the 

    // direction of the gaze (+z).

    D3DXVec3Subtract(&ZAxis, pAt, pEye);

    // Normalize the z basis vector.

    D3DXVec3Normalize(&ZAxis, &ZAxis);

    // Compute the orthogonal axes from the cross product of the gaze 

    // and the pUp vector.

    D3DXVec3Cross(&XAxis, pUp, &ZAxis);
    D3DXVec3Normalize(&XAxis, &XAxis);
    D3DXVec3Cross(&YAxis, &ZAxis, &XAxis);

    // Start building the matrix. The first three rows contain the 

    // basis vectors used to rotate the view to point at the look-at 

    // point. The fourth row contains the translation values. 

    // Rotations are still about the eyepoint.

    pOut->_11 = XAxis.x;
    pOut->_21 = XAxis.y;
    pOut->_31 = XAxis.z;
    pOut->_41 = -D3DXVec3Dot(&XAxis, pEye);

    pOut->_12 = YAxis.x;
    pOut->_22 = YAxis.y;
    pOut->_32 = YAxis.z;
    pOut->_42 = -D3DXVec3Dot(&YAxis, pEye);

    pOut->_13 = ZAxis.x;
    pOut->_23 = ZAxis.y;
    pOut->_33 = ZAxis.z;
    pOut->_43 = -D3DXVec3Dot(&ZAxis, pEye);

    pOut->_14 = 0.0f;
    pOut->_24 = 0.0f;
    pOut->_34 = 0.0f;
    pOut->_44 = 1.0f;

    return pOut;
}  
Does anybody knows how to set up the view matrix on OpenGL using the same idea (i.e. by hand and almost the same way of the code above)? Thanks in advance! Cristián Ramírez (gameovercl) ICQ #38991565 Viña del Mar CHILE
opengl uses righthand + d3d lefthand coordinate systems search the net for info on hotwo interchange the two
this might also be of interest www2.ravensoft.com/users/ggribb/plane%20extraction.pdf

http://members.xoom.com/myBollux

This topic is closed to new replies.

Advertisement