Problems with Picking (Ray intersection)

Started by
12 comments, last by Darker_Rage 19 years, 3 months ago
Enable debug output, and link to the d3dx9d.lib. Run it with the debugger and examine the debug output - it'll tell you why it's failing. Check the Forum FAQ for details on debugging.

Advertisement
ok, using DXTRACE_ERR_MSGBOX I get this:

File:
Line: 681
Error code: D3DERR_INVALIDCALL(0x8876086c)
Calling: Funciton failed:
Do you want to debug the program.

If I hit "yes" I get:

Unhandled exception at 0x77f767cd in Damien.exe: User breakpoint.
followed closely by: There is no source code for the current location.

In the output section, the error is:
Direct3D9: (ERROR) :GetTransform does not work in pure-device

Sooo... the question probably is now how do I not use pure-device :-S except I don't even know what that means!!

EDITED TO ADD:

I also get this:
c:\documents and settings\darker rage\my documents\visual studio projects\damien\damien\dicamera.cpp(681): function failed: hr=D3DERR_INVALIDCALL (0x8876086c)
D3DX: D3DXComputeBoundingBox: NULL min output parameter

Thanks again for help, especially that last bit (didn't know the usage of my debugger at all!)
IIRC pure devices do T&L in hardware, thus D3D doesn't have access to the world transformation matrix. Change your device creation code to use hardware vertex processing instead. Look up your CreateDevice code and check which vertex-processing flag you use.
[edit]
The last one is simple to solve - just provide all necessary parameters and double check whether they are NULL (e.g. set a break-point and look up the parameter values in the debug window).
[/edit]
Ach! Sorry to keep on with the same problem yet again...

You said earlier that I needed to:
For every tile in your grid:
Based on tile type, construct AABB
Translate AABB based on tile position
Intersect AABB with ray

I am doing this. I am calculating and transforming the pick ray by robbing the code from Microsoft's Pick sample (from the old SDKs). I am using this code to check for intersection:

D3DXMATRIXA16 matProj;	d3d::gd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );        POINT ptCursor;        GetCursorPos( &ptCursor );		ScreenToClient( d3d::ghMainWnd, &ptCursor );        // Compute the vector of the pick ray in screen space        D3DXVECTOR3 v;v.x =  ( ( ( 2.0f * ptCursor.x ) / d3d::gd3dPP.BackBufferWidth  ) - 1 ) / matProj._11;v.y = -( ( ( 2.0f * ptCursor.y ) / gd3dPP.BackBufferHeight ) - 1 ) / matProj._22;v.z =  1.0f;        // Get the inverse of the composite view and world matrix        D3DXMATRIXA16 matView, matWorld, m;        d3d::gd3dDevice->GetTransform( D3DTS_VIEW, &matView );        d3d::gd3dDevice->GetTransform( D3DTS_WORLD, &matWorld );                m = matWorld * matView;        D3DXMatrixInverse( &m, NULL, &m );        // Transform the screen space pick ray into 3D space        ray.origin.x  = v.x*m._11 + v.y*m._21 + v.z*m._31;        ray.origin.y  = v.x*m._12 + v.y*m._22 + v.z*m._32;        ray.origin.z  = v.x*m._13 + v.y*m._23 + v.z*m._33;        ray.direction.x = m._41;        ray.direction.y = m._42;        ray.direction.z = m._43;		for(int i=0; i<X_VALUE; i++)		{			for(int j=0; j<Y_VALUE; j++)			{				D3DXVECTOR3* raf;				meshes[j]->LockVertexBuffer(0,(void**)&raf);				HRESULT hr = D3DXComputeBoundingBox(				raf,				meshes[j]->GetNumVertices(),				D3DXGetFVFVertexSize(meshes[j]->GetFVF()),				&MRBBmin,				&MRBBmax);				MR->UnlockVertexBuffer();				//DXTRACE_ERR_MSGBOX("function failed:", hr);				if(FAILED(hr))				{					::MessageBox(0, "Twat",0,0);				}				if(Intersect(ray, MRBBmin, MRBBmax))				{					tracker.setComp(i,j,2);					return 0;				}


If I leave the "return 0" statement, only the first tile (at 0,0 in my array of ID3DXMesh*) is changed in the tracker array (which the render funcion gets it's information from) regardless of where I click on the screen. If I add these two statements:

map[j] = 2; //map is the workaround for errors earlier, and ixj int array
meshes[j] = FN; //FN is the mesh that i'm trying to change things to, meshes is an ixj array of ID3DXMesh*

The first tile in the array turns briefly to an FN then deletes its self.

If I comment out the "return 0," whatever was happening to the first tile happens to every tile on the grid

Edited by Coder: Source tags: [source]code[/source] [smile]

[Edited by - Coder on January 4, 2005 1:54:39 PM]

This topic is closed to new replies.

Advertisement