# Coordinates of Mesh objects

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

## 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 on other sites
Quote:
 Original post by DratsHi 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 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 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 on other sites
No i want to find out the coordinates of the centre of each asteroid.

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

1. 1
2. 2
Rutin
22
3. 3
A4L
15
4. 4
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013639
×