• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# D3dXIntersect ,not picking

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Anddos  Members

Posted 10 October 2012 - 05:55 AM

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...

}


### #2Ripiz  Members

Posted 10 October 2012 - 07:36 AM

I think you need to transform ray only by inverse of mesh's world matrix.

### #3Anddos  Members

Posted 10 October 2012 - 09:40 AM

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, 10 October 2012 - 09:47 AM.

### #4Ripiz  Members

Posted 10 October 2012 - 10:05 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.