• Advertisement
Sign in to follow this  

D3dXIntersect ,not picking

This topic is 1930 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if my model i am rendering is using a effect shader like this

VS_OUTPUT VertScene( float4 Pos : POSITION,
float3 Normal : NORMAL,
float2 Tex0 : TEXCOORD0 )
{
VS_OUTPUT o;

o.Pos = mul( Pos, g_mWorld );
o.Pos = mul( o.Pos, g_mViewProj );
o.Tex0 = Tex0;
float3 N = normalize( mul( Normal, (float3x3)g_mWorld ) );
// Always fully lit the floor
o.Diffuse = 1.0f;

return o;
}

what space so i need to convert the ray to ? , i am not using picking btw, i am placing a ray at a position of an object and and the direction is 0.0f,-1.0f,0.0f
this is the intersect function

void CTiny::IntersetFloor(IDirect3DDevice9* pd3dDevice,ID3DXMesh* mesh,D3DXMATRIX Param)
{
pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
origin = D3DXVECTOR3(m_vPos.x, m_vPos.y, m_vPos.z);
direction = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
// find the inverse matrix
D3DXMatrixInverse(&matInverse, NULL, &(Param* matView)); //(matWorld * matView));
// convert origin and direction into model space
D3DXVec3TransformCoord(&origin, &origin, &matInverse);
D3DXVec3TransformNormal(&direction, &direction, &matInverse);
D3DXVec3Normalize(&direction, &direction);
// detect picking
BOOL hit;
D3DXIntersect(mesh, &origin, &direction, &hit, NULL, NULL, NULL, NULL, NULL, NULL);
if(hit)
{
pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

//MessageBox(NULL,L"Hit",L"",0);
}
else
{
pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
}
}

the call

// draw each tiny
vector <CTiny*>::iterator itCur, itEnd = g_v_pCharacters.end();
for( itCur = g_v_pCharacters.begin(); itCur != itEnd; ++ itCur )
{
// set the time to update the hierarchy
( *itCur )->AdvanceTime( fElapsedTime, &vEye );
// draw the mesh
( *itCur )->Draw();
( *itCur )->IntersetFloor(pd3dDevice,g_pMeshFloor,g_mxFloor); //last param is the floor matrix rot and translate...

}

Share this post


Link to post
Share on other sites
Advertisement
I think you need to transform ray only by inverse of mesh's world matrix.

Share this post


Link to post
Share on other sites
ive tried with just this , it set the game to wireframe all the time which indicates a hit, so that cant be right :/

D3DXMatrixInverse(&matInverse, NULL, &(Param)); which is the passed floor matrix Edited by Anddos

Share this post


Link to post
Share on other sites
You say direction is (0,-1,0) but in the code it's (0,1,0). So how it really is?
Are you aware 1 is up and -1 is down? At least that's how it is usually.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement