Mouse coords to world coords -- Attaching a 3d object to cursor

Started by
0 comments, last by helix 19 years, 2 months ago
I know it's not a difficult problem but I'm stuck. I'm banging my head against the wall trying to figure this out. In my game, clicking on an object in the inventory will attach it to the mouse cursor so you can drop it somewhere else. Unfortunately the engine I'm using doesn't have a worldToScreen (and vice versa) function. The "picking" works (ie, I can select/deselect the objects in the inventory with no problem, but while my erroneous mouse following code runs as expected, it just doesn't look right). Can someone give me some psuedo-code or a description of what I need to do? I'll give any additional information that is needed. Thanks in advance!
Advertisement
Ok, I figured this one out (thanks google):

	D3DXVECTOR3 vPickRay;	vPickRay.x =  (((2.0f * fScreenX) / fWindowWidth) - 1.0f) / m_ProjectionMatrix._11;	vPickRay.y = -(((2.0f * fScreenY) / fWindowHeight) - 1.0f) / m_ProjectionMatrix._22;	vPickRay.z =  1.0f;	D3DXMATRIXA16 mInvView;	D3DXMatrixInverse( &mInvView, NULL, &m_ViewMatrix );	// Transform the screen space pick ray into 3D space	D3DXVECTOR3 vRayDir;	vRayDir.x = (vPickRay.x * mInvView._11) + (vPickRay.y * mInvView._21) + (vPickRay.z * mInvView._31);	vRayDir.y = (vPickRay.x * mInvView._12) + (vPickRay.y * mInvView._22) + (vPickRay.z * mInvView._32);	vRayDir.z = (vPickRay.x * mInvView._13) + (vPickRay.y * mInvView._23) + (vPickRay.z * mInvView._33);	D3DXVECTOR3 vRayOrigin;	vRayOrigin.x = mInvView._41;	vRayOrigin.y = mInvView._42;	vRayOrigin.z = mInvView._43;

This topic is closed to new replies.

Advertisement