Jump to content
  • Advertisement
Sign in to follow this  
Drats

Coordinates of Mesh objects

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

Hi there, For my 3d game I am loading up several asteroids (using the same mesh object). Now I want to find out the position coordinates x, y and z of each of those asteroids. Is there any function in direct3d that I can use to achieve this? Any help will be welcome.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Drats

Hi there,

For my 3d game I am loading up several asteroids (using the same mesh object). Now I want to find out the position coordinates x, y and z of each of those asteroids. Is there any function in direct3d that I can use to achieve this?
Any help will be welcome.


Do you mean you want to know the position of each vertex in your asteroid mesh, or that you want to know the actual position of the asteroid in your game world?

Share this post


Link to post
Share on other sites
Hey there, try looking up Picking or Ray Picking, and this D3DXVec3Unproject
heres the mouse look at ray


//ok we can set the rays locations based on the mouse points
POINT ptCursor = {x, y};


D3DXVECTOR3 *rt = NULL;//returned from call

D3DXVECTOR3 v, vmouse, temp;
vmouse.x = ptCursor.x;// + GetSystemMetrics(SM_CXSIZEFRAME);
vmouse.y = ptCursor.y;
vmouse.z = 0;//ViewPort->MinZ;//0.001f;//campos->z;



//Call D3DXVec3Unproject two times, once with MouseX,MouseY,0 and MouseX,MouseY,1.
//This returns you two points in 3d space which form a ray. Use that ray to do intersection tests.

rt = D3DXVec3Unproject(&rmc->m_rayDirection,//rayDir,//D3DXVECTOR3 *pOut,
&vmouse,//CONST D3DXVECTOR3 *pV,
ViewPort,//CONST D3DVIEWPORT9 *pViewport,
matProj,//CONST D3DXMATRIX *pProjection,
matView,//CONST D3DXMATRIX *pView,
pWorld);//CONST D3DXMATRIX *pWorld

if(rt == NULL)
{
MessageBeep(MB_OK);
return S_OK;
}



//temp.x = campos->x;//ptCursor.x;
//temp.y = campos->y;//ptCursor.y;
//vmouse = temp;// - (*campos);
//vmouse.z = campos->z;


vmouse.z = 1;//ViewPort->MaxZ;//0.99f;

//D3DXMATRIX matViewInv;


//D3DXMatrixInverse(&matViewInv, NULL, matView );

rt = D3DXVec3Unproject(&rmc->m_rayOrigin,//rayOrigin,//D3DXVECTOR3 *pOut,
&vmouse,//CONST D3DXVECTOR3 *pV,
ViewPort,//CONST D3DVIEWPORT9 *pViewport,
matProj,//CONST D3DXMATRIX *pProjection,
matView,//CONST D3DXMATRIX *pView,
pWorld);//CONST D3DXMATRIX *pWorld

if(rt == NULL)
{
MessageBeep(MB_OK);
return S_OK;//error
}


rayDir = rmc->m_rayDirection;
rayOrigin = rmc->m_rayOrigin;







it works ok when not using a camera but I still can't get this to work with the camera unless the cameras pos it at max z plane(Far Plane)

Share this post


Link to post
Share on other sites
I've just fixed the error now it works
Fixed All ok it was the direction did this and works great

rmc->m_rayDirection = rmc->m_rayDirection - rmc->m_rayOrigin;

rayDir = rmc->m_rayDirection;;
rayOrigin = rmc->m_rayOrigin;

Share this post


Link to post
Share on other sites
What if you calculate the bounding box (sphere) and take its center as
the center. Just in case: D3DXComputeBoundingBox or ..Sphere.

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!