directx picking help ,

This is a discussion on directx picking help , within the Game Programming forums, part of the General Programming Boards category; ok ive got a basic mesh loaded and now i want to move it around with mouse , ive followed ...

  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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    No one has replied which probably means we need more of an explanation of what you are trying to do.

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    ...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, 05: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, 06:16 PM
  4. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-24-2004, 11:49 PM
  5. DirectX 8 with Borland
    By Tommaso in forum Game Programming
    Replies: 11
    Last Post: 08-12-2003, 09:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21