Archived

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

Using the View Matrix

This topic is 5807 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

I seem to be having some trouble getting the view matrix to work the way I want. The following example source seems to work fine:
  
	D3DXVECTOR3 vLook(0,0,1.0f);
	D3DXVECTOR3 vUp(0,1.0f,0);
	D3DXVECTOR3 vRight(1.0f,0,0);
	D3DXVECTOR3 vPos(0,0.0f,24.0f);

	D3DXMatrixIdentity(&m_matPosition);
	m_matPosition._11 = vRight.x; m_matPosition._12 = vUp.x; m_matPosition._13 = vLook.x; 
	m_matPosition._21 = vRight.y; m_matPosition._22 = vUp.y; m_matPosition._23 = vLook.y; 
	m_matPosition._31 = vRight.z; m_matPosition._32 = vUp.z; m_matPosition._33 = vLook.z; 
	m_matPosition._41 = D3DXVec3Dot(&vPos, &vRight);
	m_matPosition._42 = D3DXVec3Dot(&vPos, &vUp);
	m_matPosition._43 = D3DXVec3Dot(&vPos, &vLook);

	m_pd3dDevice->SetTransform(D3DTS_VIEW, &m_matPosition );
  
However, if I modify the position of the camera to be above the object looking down, the object is no longer in view? What am I missing?
  
	D3DXVECTOR3 vLook(0,0,1.0f);
	D3DXVECTOR3 vUp(0,1.0f,0);
	D3DXVECTOR3 vRight(1.0f,0,0);
	D3DXVECTOR3 vPos(0, 100.0f, 0.0f);  // Camera is above the object?


	D3DXMatrixIdentity(&m_matPosition);
	m_matPosition._11 = vRight.x; m_matPosition._12 = vUp.x; m_matPosition._13 = vLook.x; 
	m_matPosition._21 = vRight.y; m_matPosition._22 = vUp.y; m_matPosition._23 = vLook.y; 
	m_matPosition._31 = vRight.z; m_matPosition._32 = vUp.z; m_matPosition._33 = vLook.z; 
	m_matPosition._41 = D3DXVec3Dot(&vPos, &vRight);
	m_matPosition._42 = D3DXVec3Dot(&vPos, &vUp);
	m_matPosition._43 = D3DXVec3Dot(&vPos, &vLook);

	m_pd3dDevice->SetTransform(D3DTS_VIEW, &m_matPosition );
  

Share this post


Link to post
Share on other sites
Never mind, as with everthing you only figure it out after you ask for help:

  
D3DXVECTOR3 vLook(0,1.0f, 0.0f);
D3DXVECTOR3 vUp(0, 0.0f,1.0f);

Share this post


Link to post
Share on other sites