Original Post
Guys, I'm looking into obtaining a rendered object's height once it has been transformed and rendered on the screen, the purpose of which is to place a label floating above the character's head. The object is stored within an ID3DXAnimationController using a series of bones and meshes. When attempting to use a bounding box to obtain the object height, I've expectedly obtained the model's height in the object space, which is several thousand units high, not the ~40 or so pixels that I need on the screen. I've attempted to use _22 within the material matrix assuming this to be the Max Y value for the object to be rendered to the screen... possibly a misunderstanding as to how the matrix works. I'm sure the solution is simple and related to my lack of experience, though i'm stumped. Note: using C++ and DX9.0 at this point. My object position to screen position code: [Edited by - Kalten on February 14, 2010 7:07:42 PM]
D3DXVECTOR3 ObjPosToScreenPos(D3DXMATRIX matProj, D3DXMATRIX matView, int type){
D3DXMATRIX identityMatrix;
D3DXMatrixIdentity(&identityMatrix);
D3DXMATRIX mat = identityMatrix * matView * matProj;
D3DXVECTOR4 trans;
if (type == 0)
{
D3DXVec3Transform(&trans, &pos, &mat);
}
else if (type == 1) // for words...
{
D3DXVECTOR3 tempPos = D3DXVECTOR3(pos.x,pos.y+(mat._22),pos.z); //guessing numbers...
D3DXVec3Transform(&trans, &tempPos, &mat);
}
if(trans.z >= 0) //if the translated Z depth is less than 0 then we have an object behind the camera.
{
D3DXVECTOR3 result = D3DXVECTOR3(((trans.x / trans.w) + 1) * (SCREEN_WIDTH/2),((1 - (trans.y / trans.w)) * (SCREEN_HEIGHT /2)), 0);
return result;
}else{
return D3DXVECTOR3(-1,-1,-1);
}
}