D3DXIntersect()

Started by
14 comments, last by GENTS 19 years, 10 months ago
quote:Original post by GENTS
Thanks you all!!!

I''ll now try __Daedalus__ code and then I''d say you results!!!

I''m also installing DirectX Debug Runtime for my and your pleasure!!!

Only a last question for __Daedalus__...

But your model matrix is the one of the loading or you pick it during the game just before of the call to your function?!

THANKS A LOT!!!

PS: I''ve installed the Debug Runtime but it give me no information!!! [except the memory freed - all other is ok! ]

-----------------------------------------------
- GENTS -

"Every man dies, not every man really lives"
[William Wallace]




[edited by - GENTS on June 11, 2004 7:33:34 AM]


Hello,

The mesh you''re trying to pick is the first parameter of the function and it''s orientation matrix is the second parameter (that is the combined translation, rotation and scale matrices).
I am assuming each of your meshes has it''s own matrix to orient it in your world. You would obvioulsly have to update each of your meshes corresponding orientation matrices before testing them in calls to this function.

Advertisement
I''m sorry for you all and for ME, but it still doesn''t work!!!

It''s impossible to use in my game!!!

I''m so sad!!!!!!!

THANKS A LOT in any case!!!

-----------------------------------------------
- GENTS -

"Every man dies, not every man really lives"
[William Wallace]


----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
quote:Original post by GENTS
PS: I''ve installed the Debug Runtime but it give me no information!!! [except the memory freed - all other is ok!]


Hmm... if you''re linking to d3dxd.lib, and you''ve got the debug output sliders ramped up to full, it should at least tell you something... weird.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Gents did you get my e-mail?
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]   [edited by - GENTS on June 13, 2004 4:55:34 AM]
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
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]


----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -

This topic is closed to new replies.

Advertisement