Skip to main content
gamedev.net
🔒 Locked

D3DXIntersect help

Started by rpg_code_master 0 replies 550+ views
Original Post
rpg_code_master
rpg_code_master
i have a problem with the D3DXIntersect function, when i pass the Hit varible, D3DXIntersect doesn''t change it''s value to TRUE or FALSE, so i can''t tell weather the collision was a success or not. It works great on my world mesh collision algorithems but not here, heres the code. Can you think of why??? // here i am going to use the mouse-to-mesh-collision techneque to see if the enimie is in the center // of the screen D3DXVECTOR3 vecRay, vecDir; // rays direction and position D3DXVECTOR3 v; // temp vector D3DXMATRIX matProj, matView; // projection and view matricies D3DXMATRIX m; // temp matrix // get the current view and projection matrix g_Graphics.GetDeviceCOM( )->GetTransform( D3DTS_PROJECTION, &matProj ); g_Graphics.GetDeviceCOM( )->GetTransform( D3DTS_VIEW, &matView ); // inverse the view martix D3DXMatrixInverse( &m, NULL, &matView ); // get the center screen coordinates static int CenterX = SCREEN_WIDTH >> 1; static int CenterY = SCREEN_HEIGHT >> 1; // compute the vector of the pick ray in screen space v.x = ( ( ( 2.0f*g_Mouse.GetXPos( )/*CenterX<<1*/ ) / g_Graphics.GetWidth( ) ) - 1 ) / matProj._11; v.y = -( ( ( 2.0f*g_Mouse.GetYPos( )/*CenterY<<1*/ ) / g_Graphics.GetHeight( ) ) - 1 ) / matProj._22; v.z = 1.0f; // transform the screen space ray vecRay.x = m._41; vecRay.y = m._42; vecRay.z = m._43; vecDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31; vecDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32; vecDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33; // see if an enimie was hit ID3DXMesh *pMesh = NULL; BOOL Hit; DWORD Face; float u, v2, Dist; // get pointer to parent mesh pMesh = g_Char.GetObject( ).GetMesh( )->GetParentMesh( )->m_Mesh; // see if the player hit an enimie D3DXIntersect( pMesh, &vecRay, &vecDir, &Hit, &Face, &u, &v2, &Dist ); // if the shot was successful, kill the random character if ( Hit == TRUE ) g_Char.SetState( OBJECTSTATE_DEAD );
DarkPixel
DarkPixel
See if your D3DXIntersect function returns an error code or
not ! It is possible that the function failed, so it hasn''t
changed the flag ! Try it and analyse the error code !


There is no problem, only solutions...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.