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

How to let the camera look at a position

This topic is 5621 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 have programmed several camera functions. Move,Rotate,... , Now I want to write a function where I say : Camera look at x,y,z or look at object. So the idea is to give a) The camera´s position b) the Position or object´s position that has to be seen. How can I realize this? Thanks in Advance!!!! this is my Camera structur en Update Function typedef struct _S3DX8_Camera { float m_Roll; float m_Pitch; float m_Yaw; // The position D3DVECTOR m_Position; // The look at vector D3DVECTOR m_LookAt; // The up vector D3DVECTOR m_Up; // The rigth vector D3DVECTOR m_Right; // The cameras velocity D3DVECTOR m_Velocity; bool update; } S3DX8_Camera; void DX8_Camera_Update(S3DX8_Device* pDevice,S3DX8_Camera *pCamera) { D3DXMATRIX matPitch, matRoll, matYaw; D3DXMATRIX mView; pCamera->m_Position.x += pCamera->m_Velocity.x * pCamera->m_Right.x; pCamera->m_Position.y += pCamera->m_Velocity.y * pCamera->m_Right.y; pCamera->m_Position.z += pCamera->m_Velocity.z * pCamera->m_Right.z; pCamera->m_Position.x += pCamera->m_Velocity.x * pCamera->m_Up.x; pCamera->m_Position.y += pCamera->m_Velocity.y * pCamera->m_Up.y; pCamera->m_Position.z += pCamera->m_Velocity.z * pCamera->m_Up.z; pCamera->m_Position.x += pCamera->m_Velocity.x * pCamera->m_LookAt.x; pCamera->m_Position.y += pCamera->m_Velocity.y * pCamera->m_LookAt.y; pCamera->m_Position.z += pCamera->m_Velocity.z * pCamera->m_LookAt.z; D3DXVec3Normalize( &pCamera->m_LookAt, &pCamera->m_LookAt ); D3DXVec3Cross(&pCamera->m_Right,&pCamera->m_Up,&pCamera->m_LookAt); D3DXVec3Normalize( &pCamera->m_Right, &pCamera->m_Right ); D3DXVec3Cross(&pCamera->m_Up,&pCamera->m_LookAt,&pCamera->m_Right); D3DXVec3Normalize( &pCamera->m_Up, &pCamera->m_Up ); D3DXMatrixRotationAxis( &matYaw, &pCamera->m_Up, pCamera->m_Yaw ); D3DXMatrixRotationAxis( &matPitch, &pCamera->m_Right, pCamera->m_Pitch ); D3DXMatrixRotationAxis( &matRoll, &pCamera->m_LookAt, pCamera->m_Roll ); D3DXVec3TransformCoord( &pCamera->m_LookAt, &pCamera->m_LookAt, &matYaw ); D3DXVec3TransformCoord( &pCamera->m_Right, &pCamera->m_Right, &matYaw ); D3DXVec3TransformCoord( &pCamera->m_LookAt, &pCamera->m_LookAt, &matPitch ); D3DXVec3TransformCoord( &pCamera->m_Up, &pCamera->m_Up, &matPitch ); D3DXVec3TransformCoord( &pCamera->m_Right, &pCamera->m_Right, &matRoll ); D3DXVec3TransformCoord( &pCamera->m_Up, &pCamera->m_Up, &matRoll ); D3DXMatrixIdentity( &mView ); mView._11=pCamera->m_Right.x; mView._12=pCamera->m_Up.x; mView._13=pCamera->m_LookAt.x; mView._14=0; mView._21=pCamera->m_Right.y; mView._22=pCamera->m_Up.y; mView._23=pCamera->m_LookAt.y; mView._24=0; mView._31=pCamera->m_Right.z; mView._32=pCamera->m_Up.z; mView._33=pCamera->m_LookAt.z; mView._34=0; mView._41=- D3DXVec3Dot( &pCamera->m_Position, &pCamera->m_Right ); mView._42=- D3DXVec3Dot( &pCamera->m_Position, &pCamera->m_Up ); mView._43=- D3DXVec3Dot( &pCamera->m_Position, &pCamera->m_LookAt ); mView._44=1; pDevice->pd3dDevice->lpVtbl->SetTransform(pDevice->pd3dDevice,D3DTS_VIEW,&mView); }

Share this post

Link to post
Share on other sites