Jump to content
  • Advertisement
Sign in to follow this  
DickieChen

problem using D3DXIntersect() to check the collision between the scene and the role..

This topic is 2855 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

Hey guys,
Well,I just got the book<Programming.Role.Playing.Games.with.DirectX.2nd.Edition>,and I read chapter9"collision with meshes"and I copied the codes,in my program a wrote a SkinMesh class to load a character,I used ID3DXMesh interface to load the scene,I also got the input message and changed the position.Then a problem happened when I wrote the function following the book:

BOOL CheckIntersect(ID3DXMesh* pMesh, //function to check the collision between the scene and the role
float XStart,float YStart,float ZStart,
float XEnd,float YEnd,float ZEnd,float *Distance){

BOOL hit;
float u,v,dist;
float XDiff,YDiff,ZDiff,Size;
DWORD FaceIndex;
D3DXVECTOR3 vecDir;

XDiff=XEnd-XStart;
YDiff=YEnd-YStart;
ZDiff=ZEnd-ZStart;

D3DXVec3Normalize(&vecDir,&D3DXVECTOR3(XDiff,YDiff,ZDiff));

D3DXIntersect(pMesh,
&D3DXVECTOR3(XStart,YStart,ZStart),
&vecDir,&hit,&FaceIndex,&u,&v,&dist,
NULL,NULL);

if(hit){
Size=(float)sqrt(XDiff*XDiff+YDiff*YDiff+ZDiff*ZDiff);
if(dist>Size)
hit=FALSE;
else{
if(Distance!=NULL)
*Distance=dist;
}
}
return hit;
}

And I wrote:

LPD3DXMESH scene;//load scene.x
......
SkinMesh Role;//load the role
.....

if(KeyDown....){
if(CheckInterSect(scene,Role->GetPosition()->x,Role->GetPosition()->y, Role->GetPosition()->z
Role->GetPosition()->x, Role->GetPosition()->y, Role->GetPosition()->z+0.7f,NULL) == TRUE) {
move=false;
}
}

And there's no effect! The role could still go through the walls! What's wrong ?
please help me ,thank you so much.

Share this post


Link to post
Share on other sites
Advertisement
Does your scene mesh have an identity transform? I.e., when you render it, is the world matrix set to an identity matrix?

Also, if your skinmesh position is, for instance, at (0,0,0), try shooting the intersect ray from, for instance, (0, 0.1f, 0)*, slightly elevated from the actual position.

*assuming the Y axis is your up direction.

Share this post


Link to post
Share on other sites
Well,whatever,I solved this problem at last.
For details,you can see this:
http://www.gamedev.net/community/forums/topic.asp?topic_id=254636
Anyway,thanks a lot.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!