Example #1
0
File: Ray.cpp Project: FashGek/ZED
		void Pick( const ZED_UINT32 p_Width, const ZED_UINT32 p_Height,
			const ZED_UINT32 p_X, const ZED_UINT32 p_Y,
			const Matrix4x4 &p_Projection, const Matrix4x4 &p_View,
			Ray *p_Picked )
		{
			Vector3 RayPos, Origin, Direction;
			Matrix4x4 InvView;
			InvView.Copy( p_View );
			InvView.AffineInverse( );

			RayPos[ 0 ] = ( ( ( 2.0f * p_X )/p_Width ) - 1.0f )/
				p_Projection( 0, 0 );
			RayPos[ 1 ] = ( ( ( 2.0f * p_Y )/p_Height ) - 1.0f )/
				p_Projection( 1, 1 );
			RayPos[ 2 ] = 1.0f;

			Direction[ 0 ] = RayPos[ 0 ]*InvView( 0, 0 ) +
							 RayPos[ 1 ]*InvView( 1, 0 ) +
							 RayPos[ 2 ]*InvView( 2, 0 );
			Direction[ 1 ] = RayPos[ 0 ]*InvView( 0, 1 ) +
							 RayPos[ 1 ]*InvView( 1, 1 ) +
							 RayPos[ 2 ]*InvView( 2, 1 );
			Direction[ 2 ] = RayPos[ 0 ]*InvView( 0, 2 ) +
							 RayPos[ 1 ]*InvView( 1, 2 ) +
							 RayPos[ 2 ]*InvView( 2, 2 );

			Origin[ 0 ] = InvView( 0, 3 );
			Origin[ 1 ] = InvView( 1, 3 );
			Origin[ 2 ] = InvView( 2, 3 );

			p_Picked->Set( Origin, Direction );
		}
Example #2
0
File: Ray.cpp Project: FashGek/ZED
		void Ray::Detransform( const Matrix4x4 &p_Matrix )
		{
			Matrix4x4 Tmp;
			Tmp.Copy( p_Matrix );

			// Take the negated translation from the matrix
			m_Origin[ 0 ] -= p_Matrix( 0, 3 );
			m_Origin[ 1 ] -= p_Matrix( 1, 3 );
			m_Origin[ 2 ] -= p_Matrix( 2, 3 );

			// Get rid of the translation in the matrix
			Tmp( 0, 3 ) = Tmp( 1, 3 ) = Tmp( 2, 3 ) = 0.0f;

			// Invert the matrix
			Tmp.AffineInverse( );

/*UNCOMMENT!			m_Direction = m_Origin * Tmp;*/
		}