Skip to main content
gamedev.net
🔒 Locked

D3DxIntersect problem

Started by jimmy borch Aug 6, 2002 at 5:31 AM 2 replies 400+ views
Original Post
jimmy borch
jimmy borch
Hi can anyone help me with this: I want to enable my user to use a mouse click to pick an object in 3d space. I have used the code from the directX 8.1 SDK "PICK" demo, and all seems to be fine.... as long as my objects are placed at 0,0,0 In my program I use D3DXMatrixTranslation in FRAMEMOVE to place my objects in 3d... It seems that when I check the mesh for intersection, directx insists that it is still in 0,0,0. What can I do ? is there another way to place my objects so that they actual changes their position in 3d... or should I use some king of extra transfor when intersecting ? Please keep in mind that Im very new to directx (under one week) so I would very much like if you both give me an c++ or pascal eksample + a description of what I should do. Thank you Regards Jimmy Borch P.s. I did not include my source code here, as it is from delphi (dunno how may people that know the pascal syntax *grin*).. but you just say the word, and I send it
Spacecat
Spacecat
Luckily, what you''re trying to do -looks- simpler to me than picking a single triangle. Let''s see now...

From my own pickin'' codes, I have this tidbit.

  
BOOL IntersectOMesh(const D3DXVECTOR3& origin,
const D3DXVECTOR3& dir, COptimizeMesh *pMesh,
float* fDist, float* fBaryU, float* fBaryV){
// Convert ray to model space

D3DXVECTOR3 vNewOrig,vNewDir;
D3DXMATRIX invMat;
invMat=pMesh->GetFullTransform(invMat);
D3DXMatrixInverse(&invMat,NULL,&invMat);
D3DXVec3TransformCoord(&vNewOrig,&origin,&invMat);
D3DXVec3TransformNormal(&vNewDir,&dir,&invMat);

BOOL bHit;
DWORD dwFace;
D3DXIntersect(pMesh->m_pMeshOptimized
, &vNewOrig, &vNewDir
, &bHit, &dwFace, fBaryU, fBaryV, fDist, NULL, NULL);
return bHit;
}


I assume you can figure out how to build a pick ray from screen coordinates? Now, I think what you were missing is just the tricky code to transform a ray through a mesh''s position matrix. It isn''t shown in the Pick code, I believe. So here you have it!

=^.^=
=^.^= Leaders and teachers should remember: It is best to offer others what they Need, not what they Want.
jimmy borch
jimmy borch
Thanks... Im pretty sure that this could do it... but the reply raised a new question, COptimizeMesh ??????? I can not find it in directx help, nor can I find anything with the same functions (getfulltransform + m_pmeshoptimized), I would guess that this is your own class ?, what Im working with is a ID3DxMesh, what should I do to get the functionality that you show in your reply ? (getfulltransfor, would be to make a function that returns the value of my last transfor of the object, I guess.... but I dunno what the other one do, do I need it?)


Regards

JB
jimmy borch
jimmy borch
It works... thanks !!!

I guess that you only need m_pMeshOptimized because your model can change over time ? (it gets quite deform as you optimize it)... Well thanks this is great... almost got the code right before.... but did not have the d3dvectransformcoord and d3dxvectransformnormal in the function.... can anyone tell me why I need those ?

JB

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.