Originally Posted by
GodHack2
so now we have the class and the address
what are we waiting for ? lets go go go
get your w2s to work :P
this could be optimized by only getting the viewport once unless screen resolution change or you alt tab
Code:
D3DXVECTOR3 W2S(LPDIRECT3DDEVICE9 pDevice,_Object * p)
{
pDevice->GetViewport(&vp);
pDevice->GetTransform(D3DTS_VIEW, &view);
pDevice->GetTransform(D3DTS_PROJECTION, &projection);
D3DXMatrixMultiply(&ViewProjecti********, &view, &projection);
D3DXVec4Transform(&temp,&D3DXVECTOR4(p->Origin.x,
p->Origin.y,
p->Origin.z,1),
&ViewProjecti********);
float tempInvW2 = 1.0f/temp.w;
out.x = (1.0f + (temp.x*tempInvW2)) * vp.Width /2;
out.y = (1.0f - (temp.y*tempInvW2)) * vp.Height /2;
out.z = temp.z;
return out;
}
If you want the camera coords
Code:
pDevice->GetTransform(D3DTS_VIEW, &view);
::D3DXMatrixInverse(&iView,0,&view);//so you know this is kinda slow alot of math/loops in this function
//iView._41,iView._42,iView._43