Jump to content
  • Advertisement
Sign in to follow this  
ankhd

If the View Matrix for the camera is use

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

to render to. Would this mean that this view matrix is ok. if so why the hell does the D3DXVec3Unproject not work, the world, view , projection, all are good. It only works when the cameras z is move to the far plane max value.
//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;

Share this post


Link to post
Share on other sites
Advertisement
rmc->m_rayDirection doesn't get a direction, the name is misleading. I don't know how you handle that value later on, but i guess you do use it as direction.

You really get two 3d points, i'd name them Ray Origin and Ray End. You need to calculate the ray direction as subtraction of the two.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!