Code:
case WM_MOUSEMOVE:
{
//MessageBox(NULL,L"mouse moved" , L"",0);
POINT lp;
char Text[64];
DWORD written;
GetCursorPos(&lp);
//X
sprintf(Text , "%s %i\n" ,"lp.y" , lp.y);
WriteConsole(ConsoleHandle , Text , strlen(Text) , &written , NULL);
//Y
sprintf(Text , "%s %i\n" ,"lp.x" , lp.x);
WriteConsole(ConsoleHandle , Text , strlen(Text) , &written , NULL);
d3ddev->GetTransform(D3DTS_WORLD , &world);
v.x = ( ( ( 2.0f * lp.x ) / SCREEN_WIDTH ) - 1 ) / world._11;
//mouse pick X
sprintf(Text , "%s %i\n" ,"v.x" , v.x);
WriteConsole(ConsoleHandle , Text , strlen(Text) , &written , NULL);
v.y = -( ( ( 2.0f * lp.y ) / SCREEN_HEIGHT ) - 1 ) / world._22;
//mouse pick Y
sprintf(Text , "%s %i\n" ,"v.y" , v.y);
WriteConsole(ConsoleHandle , Text , strlen(Text) , &written , NULL);
//mouse pick Z
v.z = 1.0f;
//convert
D3DXMATRIX matView;
D3DXMATRIX m;
D3DXVECTOR3 rayOrigin,rayDir;
D3DXMatrixInverse( &m, NULL, &matView );
// Transform the screen space pick ray into 3D space
rayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
rayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
rayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
rayOrigin.x = m._41;
rayOrigin.y = m._42;
rayOrigin.z = m._43;
// Use inverse of matrix
D3DXMATRIX matInverse;
D3DXMatrixInverse(&matInverse,NULL,&matView);
// Transform ray origin and direction by inv matrix
D3DXVECTOR3 rayObjOrigin,rayObjDirection , rayDirection;
D3DXVec3TransformCoord(&rayObjOrigin,&rayOrigin,&matInverse);
D3DXVec3TransformNormal(&rayObjDirection,&rayDirection,&matInverse);
D3DXVec3Normalize(&rayObjDirection,&rayObjDirection);
BOOL ha........;
float distanceToCollision;
D3DXIntersect(meshSpaceship, &rayObjOrigin, &rayObjDirection, &ha........, NULL, NULL, NULL, &distanceToCollision, NULL, NULL);
if(ha........)
{
sprintf(Text , "%s\n" ,"collision");
WriteConsole(ConsoleHandle , Text , strlen(Text) , &written , NULL);
}
break;
}