my pick function , need help

This is a discussion on my pick function , need help within the Game Programming forums, part of the General Programming Boards category; i cant seem to get the mouse postion to intersect with the teapot ive done this code from reading this ...

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

    my pick function , need help

    i cant seem to get the mouse postion to intersect with the teapot
    ive done this code from reading this article
    can you spot anything wrong and know why it dosent intersect?
    http://www.toymaker.info/Games/html/picking.html

    Code:
    void pick()
    {
    	D3DXVECTOR3 v;
    	D3DXMATRIX matProjection;
    	D3DXMATRIX matView;
    	D3DXMATRIX matWorld;
    	D3DVIEWPORT9 d3dviewport;
    	static POINT point;
    	char buffer[64];
    	DWORD written;
    	GetCursorPos(&point);
    	HWND GetWindowFromMousePostion = WindowFromPoint(point);
    	
    	d3ddev->GetTransform(D3DTS_PROJECTION , &matProjection);
    	d3ddev->GetViewport(&d3dviewport);
    
    	sprintf(buffer,"%s %d\n", "d3dviewport.Height" , d3dviewport.Height );
        WriteConsole(Console , buffer , strlen(buffer) , &written , NULL);
    
    	sprintf(buffer,"%s %d\n", "d3dviewport.Width" , d3dviewport.Width );
        WriteConsole(Console , buffer , strlen(buffer) , &written , NULL);
    
        v.x =  ( ( ( 2.0f * point.x ) / d3dviewport.Height  ) - 1 ) / matProjection._11;
        v.y = -( ( ( 2.0f * point.y ) / d3dviewport.Width ) - 1 ) / matProjection._22;
        v.z =  1.0f;
    	//sprintf(buffer,"%s %f              %s %f \n" , "v.x" , v.x , "v.y" , v.y);
        //WriteConsole(Console , buffer , strlen(buffer) , &written , NULL);
    	
    
    	D3DXMATRIX m;
        D3DXVECTOR3 rayOrigin,rayDir;
    
    	d3ddev->GetTransform(D3DTS_VIEW, &matView);
    	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,&matWorld);
    
    	d3ddev->GetTransform(D3DTS_WORLD , &matWorld);
    
    	// Transform ray origin and direction by inv matrix
        D3DXVECTOR3 rayObjOrigin,rayObjDirection;
    
    	D3DXVec3TransformCoord(&rayObjOrigin,&rayOrigin,&matInverse);
    	D3DXVec3TransformNormal(&rayObjDirection,&rayDir,&matInverse);
        D3DXVec3Normalize(&rayObjDirection,&rayObjDirection);
    
    	BOOL ha........;
        float distanceToCollision;
    
        D3DXIntersect(meshTeapot, &rayObjOrigin, &rayObjDirection, &ha........, NULL, NULL, NULL, &distanceToCollision, NULL, NULL);
    
    	if(ha........) //this is hhasHHit , i think the forum is seeing this word as s.h.i.t lol
    	{
    		sprintf(buffer,"%s\n" , "intersecting");
            WriteConsole(Console , buffer , strlen(buffer) , &written , NULL);
    	}
    	else
    	{
    		sprintf(buffer,"%s\n" , "not intersecting");
            //WriteConsole(Console , buffer , strlen(buffer) , &written , NULL);
    	}
    
    
    
    }
    Last edited by Anddos; 11-07-2008 at 09:56 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

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