Finally THANKS to __Daedalus__ I get it to work!!!
This is my final code:
<!--STARTSCRIPT-->
BOOL SottoTiro( D3DXMESHCONTAINER_EX* Obj, D3DXMATRIX* ObjMatrix){ // Pick ray direction D3DXVECTOR3 vPickRayDir; // Pick ray origin D3DXVECTOR3 vPickRayOrig; // Vector used in computation D3DXVECTOR3 v; // Retrieved computation matrix D3DXMATRIXA16 m; // Cursor position POINT ptCursor; D3DXVECTOR3 vNear, vDir; D3DXMATRIX invMat; BOOL bHit; DWORD dwIndex; float uCoord, vCoord; float dist; LPDIRECT3DSURFACE9 pBackBuffer = NULL; D3DSURFACE_DESC Desc; ID3DXMesh* Mesh = Obj->MeshData.pMesh; // Get back buffer description g_pD3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &Desc ); pBackBuffer->Release(); g_pD3DDevice->GetTransform( D3DTS_PROJECTION, &matProj ); // Create a local copy of where your Zen mouse postion is (not using the windows mouse) ptCursor = MousePoint; // Change coordinates relative to the window which the level is rendered in ScreenToClient( g_hWndMain, &ptCursor ); // Compute the pick ray in screen space v.x = ( ( ( 2.0f * ptCursor.x ) / Desc.Width ) - 1 ) / matProj._11; v.y = -( ( ( 2.0f * ptCursor.y ) / Desc.Height ) - 1 ) / matProj._22; v.z = 1.0f; g_pD3DDevice->GetTransform( D3DTS_VIEW, &matView ); D3DXMatrixInverse( &m, NULL, &matView ); // Transform the screen space pick ray in to 3D coordinates vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; vPickRayOrig.x = m._41; vPickRayOrig.y = m._42; vPickRayOrig.z = m._43; // Calclate the origin as intersection with the near frustum plane vPickRayOrig += vPickRayDir * 1.0f; // Convert the ray to model space D3DXMatrixInverse( &invMat, NULL, ObjMatrix ); D3DXVec3TransformCoord( &vNear, &vPickRayOrig ,&invMat); D3DXVec3TransformNormal( &vDir, &vPickRayDir, &invMat); // Test for intersection D3DXIntersect( Mesh, &vNear, &vDir, &bHit, &dwIndex, &uCoord, &vCoord, &dist, NULL, NULL ); // I took out the distance check here from my source on your Gamedev thread. // This would only have returned TRUE if you were within 8 units of the // dresser when picking it. if( bHit == TRUE ) { return TRUE; } else{ return FALSE; } }
<!--ENDSCRIPT-->
It''s almost identical to __Daedalus__ code...
THANKS TO ALL!!!
I hope this''ll help other newbie as me!!!
Byez
-----------------------------------------------
- GENTS -
"Every man dies, not every man really lives"
[William Wallace]