03-14-2010, 05:35 AM
|
#4 |
Join Date: Feb 2005
Posts: 5,046
Reputation: 93094 Rep Power: 1116 | Here is my WorldToScreen function that I was using in the beta, I don't care to mess with this game anymore and it worked fine for myself. Code: D3DXVECTOR3 WorldToScreen(CPlayer* LocalPlayer, D3DXVECTOR3* EnemyPosition)
{
static UINT ScreenWidthCenter;
static UINT ScreenHeightCenter;
if(ScreenWidthCenter == 0 || ScreenHeightCenter == 0)
{
D3DVIEWPORT9 Viewport;
Renderer->Direct3DDevice->GetViewport(&Viewport);
ScreenWidthCenter = Viewport.Width / 2;
ScreenHeightCenter = Viewport.Height / 2;
}
D3DXVECTOR3 ViewPoint;
ViewPoint.x = LocalPlayer->View_Matrix._41;
ViewPoint.y = LocalPlayer->View_Matrix._42;
ViewPoint.z = LocalPlayer->View_Matrix._43;
D3DXVECTOR3 Distance;
D3DXVec3Normalize(&Distance, D3DXVec3Subtract(&Distance, &ViewPoint, EnemyPosition));
D3DXVECTOR3 Right;
Right.x = LocalPlayer->View_Matrix._11;
Right.y = LocalPlayer->View_Matrix._12;
Right.z = LocalPlayer->View_Matrix._13;
D3DXVECTOR3 Up;
Up.x = LocalPlayer->View_Matrix._21;
Up.y = LocalPlayer->View_Matrix._22;
Up.z = LocalPlayer->View_Matrix._23;
D3DXVECTOR3 Forward;
Forward.x = LocalPlayer->View_Matrix._31;
Forward.y = LocalPlayer->View_Matrix._32;
Forward.z = LocalPlayer->View_Matrix._33;
D3DXVECTOR3 DotProduct;
DotProduct.x = D3DXVec3Dot(&Distance, &Right);
DotProduct.y = D3DXVec3Dot(&Distance, &Up);
DotProduct.z = D3DXVec3Dot(&Distance, &Forward);
FLOAT AspectRatio = 1.333f;
FLOAT fovX = LocalPlayer->WeaponData->ZoomData->fovX;
FLOAT X = ScreenWidthCenter / DotProduct.z * ((AspectRatio + (0.3f / ( (fovX / 60.0f) * 10))) / (fovX / 60.0f));
FLOAT Y = ScreenHeightCenter / DotProduct.z * ((AspectRatio + (0.3f / ( (fovX / 60.0f) * 10))) / ((fovX / 60.0f) / AspectRatio));
D3DXVECTOR3 ScreenPosition;
ScreenPosition.x = ScreenWidthCenter + X * -DotProduct.x;
ScreenPosition.y = ScreenHeightCenter - Y * DotProduct.y;
ScreenPosition.z = DotProduct.z;
return ScreenPosition;
}
__________________ I've learned that something constructive comes from every defeat.
Sometimes i say things i shouldn't, and sometimes i say what other people are thinking.
Real programmer's don't document, if it was hard to write, it should be hard to understand.
First learn computer science and all the theory, next develop a programming style, then forget all that and just hack. |
Roverturbo is online now | |