Ejemplo n.º 1
0
LTBOOL gr_IntersectPlanes(
	LTPlane &plane0,
	LTPlane &plane1,
	LTPlane &plane2,
	LTVector &vOut)
{
	LTMatrix mPlanes;

	/*
		Math behind this:

		Plane equation is Ax + By + Cz - D = 0
		Standard matrix equation Ax = b.

		So stick the plane equations into the A matrix:

		A B C -D	(from plane 0)
		A B C -D	(from plane 1)
		A B C -D	(from plane 2)
		0 0 0  1

		then the b vector is:
		[0 0 0 1]

		and we're solving for the x vector so:
		~AAx = ~Ab
		x = ~Ab
	*/

	mPlanes.Init(
		plane0.m_Normal[0], plane0.m_Normal[1], plane0.m_Normal[2], -plane0.m_Dist,
		plane1.m_Normal[0], plane1.m_Normal[1], plane1.m_Normal[2], -plane1.m_Dist,
		plane2.m_Normal[0], plane2.m_Normal[1], plane2.m_Normal[2], -plane2.m_Dist,
		0.0f, 0.0f, 0.0f, 1.0f);

	// If we can't invert the matrix, then two or more planes are equal.
	if(!mPlanes.Inverse())
		return LTFALSE;

	// Since our b vector is all zeros, we don't need to do a full matrix multiply.
	// vOut = mPlaneNormal * vPlaneDist;
	vOut.Init(
		mPlanes.m[0][3],
		mPlanes.m[1][3],
		mPlanes.m[2][3]);

	vOut *= (1.0f / mPlanes.m[3][3]);
	return LTTRUE;
}
Ejemplo n.º 2
0
void CTransitionAggregate::Save( ILTMessage_Write *pMsg, uint32 dwSaveFlags )
{
	if( !pMsg ) return;

	SAVE_HOBJECT( m_hObject );

	// The rest is dependent on the save type...
	
	if( dwSaveFlags != LOAD_TRANSITION ) return;

	HOBJECT hTransArea = g_pTransMgr->GetTransitionArea();
	if( !hTransArea ) return;

	TransitionArea *pTransArea = (TransitionArea*)g_pLTServer->HandleToObject( hTransArea );
	if( !pTransArea ) return;

	LTransform tfLocal;
	LTransform tfObjectWorld;
	LTransform const& tfTransAreaWorld = pTransArea->GetWorldTransform( );
	LTMatrix mInverseRot;
	tfTransAreaWorld.m_Rot.ConvertToMatrix( mInverseRot );
	mInverseRot.Inverse( );

	g_pLTServer->GetObjectPos( m_hObject, &tfObjectWorld.m_Pos );
	g_pLTServer->GetObjectRotation( m_hObject, &tfObjectWorld.m_Rot );
	LTVector vVel;
	g_pPhysicsLT->GetVelocity( m_hObject, &vVel );

	tfLocal.m_Pos = mInverseRot * ( tfObjectWorld.m_Pos - tfTransAreaWorld.m_Pos );
	tfLocal.m_Rot = tfObjectWorld.m_Rot * ~tfTransAreaWorld.m_Rot;
	LTVector vRelVel = mInverseRot * vVel;

	SAVE_VECTOR( tfLocal.m_Pos );
	SAVE_ROTATION( tfLocal.m_Rot );
	SAVE_VECTOR( vRelVel );
}