Draworder calculation depending on camera
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
What language and DirectX version?
You can get the view matrix, and read the position from it. Assuming C++ / DX9:
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.
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);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement