Thread: directx picking help ,

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    319

    directx picking help ,

    ok ive got a basic mesh loaded and now i want to move it around with mouse , ive followed the sdk sample and some tuts on the web but i cant get it to work ,

    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;
    			}

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No one has replied which probably means we need more of an explanation of what you are trying to do.

  3. #3
    ...and of whats wrong exactly. Come on people, a little information goes a long way. It also shows at least an attempt at effort.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with my DirectX program
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 01-23-2007, 06:28 PM
  2. Isometric Tile Engine using DirectX
    By Wraithan in forum Game Programming
    Replies: 3
    Last Post: 07-17-2006, 12:16 PM
  3. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  4. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  5. DirectX 8 with Borland
    By Tommaso in forum Game Programming
    Replies: 11
    Last Post: 08-12-2003, 09:30 AM