Wrong World2Screen Calculation

Posts 1–8 of 8 · Page 1 of 1
Wrong World2Screen Calculation
Hi
I have the x,y,z coordinates and the pitch/yaw of my player entity. Same with the enemy players. I tried to find out their screen location via World2Screen.

This is my function
Code:
D3DXVECTOR3 *World2Screen(LPDIRECT3DDEVICE9 pDevice, D3DXVECTOR3 &vScreenCoord, D3DXVECTOR3 vEnemy)
{
	if( !pDevice ) return NULL;

	D3DXMATRIX matProj;
	float fAspect = (float)(1280) / 720;
	D3DXMatrixPerspectiveFovRH(&matProj, (float)(D3DX_PI/180*90), fAspect, 0.1, -1);
	
	float *pX = (float*)(*(DWORD*)(Base)+0x60);
	float *pY = (float*)(*(DWORD*)(Base)+0x68);
	float *pZ = (float*)(*(DWORD*)(Base)+0x64);
	float *pitch = (float*)(*(DWORD*)(Base)+0x6C);
	float *yaw = (float*)(*(DWORD*)(Base)+0x70);

	D3DXVECTOR3 vEye ( *pX, *pY, *pZ);
	D3DXVECTOR3 vTarget ( *pX + *yaw, *pY + (*pitch * -1), *pZ);
	D3DXVECTOR3 vUp ( 0, 0, 1 );
	D3DXMATRIX matView;
	D3DXMatrixLookAtRH( &matView, &vEye, &vTarget, &vUp);

	D3DVIEWPORT9 viewPort;
	D3DXMATRIX identity;

	pDevice->GetViewport( &viewPort );
	D3DXMatrixIdentity( &identity );

	D3DXVec3Project(&vScreenCoord, &vEnemy, &viewPort, &matProj, &matView, &identity );

	if(vScreenCoord.z < 1)
		return &vScreenCoord;

	return NULL;
}
It kind of works but the 2d coordinates are absolutely not correct. I will post some screenshots l8r.


Maybe you might want to have a look at the Source SDK? I don't know.
Quote Originally Posted by master131 View Post
Maybe you might want to have a look at the Source SDK? I don't know.
Yea, i think i saw a func for that somewhere in the SDK.
Seeing CS brings back such good memories. I think imma play it again just this night
@Arnibold I would like to see the whole project source. I can add some hacks if you want also?
Also, it looks like the 2D - Y is right, but the X is off?
Sorry for the late response,
I used the engine anyhow.
Result:

(missing HUD and darkish screen is cuz of screenshot hotkey f10)
Try scaling from 800x600 to 1280x720

New X & Y would become 578, 280, which would be right above the 2nd player from the left.
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us