• Advertisement

Archived

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

Getting a Ray's direction from Camera matrix

This topic is 5557 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about getting the ray's direction based on the Camera matrix? I am trying to cast a ray from the position of the Camera, ( Camera.GetPosition() ) and casting it into the direction the Camera is looking at. My question is how do I extract the *angle* which the Camera is looking at? I thought about just taking the look at vector3 from my Camera class but then I run into the problem where I never change the look at directly, it is always <0,0,1>. ( trying to do basic collision detection with a triangle and seeing if the ray will hit it. ) Here is code of my update() function in my camera class..
    


void CXCamera::Update( void )
{

	
	
     FLOAT fAngularSpeed = 2.0f*fElapsedTime;

    

     // Update the position vector

     D3DXVECTOR3 vT = m_vVelocity;
     D3DXVec3TransformNormal( &vT, &vT, &m_matOrientation );
     m_vPosition += vT;
	



    // Update the yaw-pitch-rotation vector

    m_fYaw   += fAngularSpeed * m_fYawVelocity;
    m_fPitch += fAngularSpeed * m_fPitchVelocity;

	

	
    // Set the view matrix

    D3DXQUATERNION qR;

    D3DXQuaternionRotationYawPitchRoll( &qR, m_fYaw, m_fPitch, 0.0f );

    D3DXMatrixAffineTransformation( &m_matOrientation, 1.25f,   NULL, &qR, &m_vPosition );


     D3DXMatrixInverse( &m_matView, NULL, &m_matOrientation );

     g_pd3dDevice->SetTransform( D3DTS_VIEW, &m_matView );


     return;

}     
Edit: blah tags~ [edited by - Zern on December 7, 2002 9:50:35 AM]

Share this post


Link to post
Share on other sites
Advertisement
Today''s post is sponsored by the term "Orthonormal basis"

The matrix itself contains ("basis") the camera direction vector, even better than that, unless it''s doing any warping etc it''s very likely to normalised ("orthonormal") . Simply:

vCameraLookDirection.x = mView._13;
vCameraLookDirection.y = mView._23;
vCameraLookDirection.z = mView._33;


If you need the angles from that from each major axis, then you could use a bit of trigonometry on 3 the right angled triangles formed between the view vector components and each principle axis (1,0,0 and 0,1,0 and 0,0,1). Keywords "Direction cosines"

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites

  • Advertisement