Draworder calculation depending on camera

Started by
0 comments, last by Evil Steve 15 years, 4 months ago
Hi How can I calculate the draworder depending on the current camera. I have a "Vector3" with the position of the object. I need to know the distance to the camera, so I can sort my items before drawing them. I have issues with the alphablending thing. Kind regards Alexander
Advertisement
What language and DirectX version?

You can get the view matrix, and read the position from it. Assuming C++ / DX9:
float GetDistanceToCamera(const D3DXVECTOR3& vPos){   D3DMATRIX matView;   HRESULT hResult = m_pDevice->GetTransform(D3DTS_VIEW, &matView);   if(FAILED(hResult))      return 9999.0f;   D3DXVECTOR3 vCameraPos;   vCameraPos.x = matView._41;   vCameraPos.y = matView._42;   vCameraPos.z = matView._43;   D3DXVECTOR3 vDistance = vPos - vCameraPos;   return D3DXVec3Length(&vDistance);}
That code is untested though. It's also worth noting that the usual way to do this is to have a camera class that contains the current camera orientation and frustum planes for clipping.

This topic is closed to new replies.

Advertisement