Coordinates of Mesh objects

Started by
4 comments, last by A A 17 years ago
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.
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?
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)
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;
No i want to find out the coordinates of the centre of each asteroid.
What if you calculate the bounding box (sphere) and take its center as
the center. Just in case: D3DXComputeBoundingBox or ..Sphere.

This topic is closed to new replies.

Advertisement