Sry for double post but when i tried to edit,the message area was completely white&blank,and i couldnt click on it to type my message...
Got it somewhat working, no crashes whatsoever , but any idea why it seems to aim at random location ?
Logged the values of enemy and 2d result to check and the 2d result is just too weird.
Code:
Actual Enemy X : -2184.459961
Actual Enemy Y : -284.912109
Actual Enemy Z : 124.087891
2D Coordinate X : -536870912
2D Coordinate Y : -1610612736
-------------------------------------------------------------------
Loop Started
-------------------------------------------------------------------
Actual Enemy X : -2250.446777
Actual Enemy Y : -195.270508
Actual Enemy Z : 124.087891
2D Coordinate X : 536870912
2D Coordinate Y : 0
-------------------------------------------------------------------
Loop Started
-------------------------------------------------------------------
Actual Enemy X : -2316.903809
Actual Enemy Y : -105.044922
Actual Enemy Z : 124.087891
2D Coordinate X : -2147483648
2D Coordinate Y : -1073741824
-------------------------------------------------------------------
Loop Started
-------------------------------------------------------------------
Actual Enemy X : -2362.828125
Actual Enemy Y : 37.885254
Actual Enemy Z : 124.087891
2D Coordinate X : 0
2D Coordinate Y : 1610612736
-------------------------------------------------------------------
Loop Started
-------------------------------------------------------------------
Actual Enemy X : -2291.825684
Actual Enemy Y : 18.759766
Actual Enemy Z : 124.087891
2D Coordinate X : -1073741824
2D Coordinate Y : 1610612736
-------------------------------------------------------------------
Loop Started
-------------------------------------------------------------------
Actual Enemy X : -2185.870605
Actual Enemy Y : 23.869629
Actual Enemy Z : 124.087891
2D Coordinate X : 0
2D Coordinate Y : 0
My Code : (w2s taken from a online CA base and modified that i cant rmb who it was)
Code:
bool W2S(D3DXVECTOR3 Pos, D3DXVECTOR3* Screen)
{
D3DVIEWPORT9 pViewport;
pDevice->GetViewport(&pViewport);
D3DXMATRIX projection, view, world;
pDevice->GetTransform(D3DTS_VIEW, &view);
pDevice->GetTransform(D3DTS_PROJECTION, &projection);
pDevice->GetTransform(D3DTS_WORLD, &world);
D3DXVec3Project( Screen, &Pos, &pViewport, &projection, &view, &world);
if(Screen->x < 0.0f || Screen->y < 0.0f|| Screen->x > pViewport.Width || Screen->y > pViewport.Height )
return false;
return ( Screen->z < 1.0f );
}
How i assigned my values & called it
Code:
D3DXVECTOR3 Output,TargetPos;
TargetPos.x = List[Index]->X;
TargetPos.y = List[Index]->Y;
TargetPos.z = List[Index]->Z;
W2S(TargetPos,&Output);