Jump to content
  • Advertisement
Sign in to follow this  
sms-timing

Draworder calculation depending on camera

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!