Exemple #1
0
/*!
  Build a line thanks to 4 points.
  
  The method is the following : Two plane are computed thanks to (P1,P2,P3) and (P1,P2,P4) (see the buildPlane method). Then the line equation is computed thanks to the intersection between the two planes.
  
  \param P1 : The first point to compute the line.
  \param P2 : The second point to compute the line.
  \param P3 : The third point to compute the line.
  \param P4 : The fourth point to compute the line.
  \param L : The instance of vpLine to store the computed line equation.
*/
void
buildLine(vpPoint &P1, vpPoint &P2, vpPoint &P3, vpPoint &P4, vpLine &L)
{
  vpPlane plane1;
  vpPlane plane2 ;
  buildPlane(P1,P2,P3,plane1) ;
  buildPlane(P1,P2,P4,plane2) ;

  L.setWorldCoordinates(plane1.getA(),plane1.getB(), plane1.getC(),plane1.getD(),
			plane2.getA(),plane2.getB(), plane2.getC(),plane2.getD()) ;
}
void Frustum::generate( const ngl::Matrix& _mat )
{
	buildPlane( m_planes[e_left], _mat, 0, e_plus );
	buildPlane( m_planes[e_right], _mat, 0, e_minus );
	buildPlane( m_planes[e_bottom], _mat, 1, e_plus );
	buildPlane( m_planes[e_top], _mat, 1, e_minus );
	buildPlane( m_planes[e_near], _mat, 2, e_plus );
	buildPlane( m_planes[e_far], _mat, 2, e_minus );
}
Exemple #3
0
    void hViewFrustum::updateFromOrthoCamera(const hVec3& EyeVec, const hVec3& LookDir, const hVec3& Up, hFloat width, hFloat height, hFloat Near, hFloat Far) {
        hFloat FarH = height;
        hFloat FarW = width;
        hFloat NearH = height;
        hFloat NearW = width;
        hVec3 Right;
        hVec3 D = normalize(LookDir);
        hVec3 EyeFar = EyeVec + (D * Far);
        hVec3 EyeNear = EyeVec + (D * Near);
        Right = cross(Up, D);

        // re-generate our 6 planes
#define ftl ((hUint)Point::FarTopLeft)
#define ftr ((hUint)Point::FarTopRight)
#define fbl ((hUint)Point::FarBottomLeft)
#define fbr ((hUint)Point::FarBottomRight)
#define ntl ((hUint)Point::NearTopLeft) 
#define ntr ((hUint)Point::NearTopRight)
#define nbl ((hUint)Point::NearBottomLeft)
#define nbr ((hUint)Point::NearBottomRight)

        Heart::hVec3* vex = frustumPoints;
        hFloat FarW2 = FarW / 2;
        hFloat FarH2 = FarH / 2;
        hFloat NearH2 = NearH / 2;
        hFloat NearW2 = NearW / 2;

        vex[ftl] = EyeFar + (Up * FarH2) - (Right * FarW2);
        vex[ftr] = EyeFar + (Up * FarH2) + (Right * FarW2);
        vex[fbl] = EyeFar - (Up * FarH2) - (Right * FarW2);
        vex[fbr] = EyeFar - (Up * FarH2) + (Right * FarW2);

        vex[ntl] = EyeNear + (Up * NearH2) - (Right * NearW2);
        vex[ntr] = EyeNear + (Up * NearH2) + (Right * NearW2);
        vex[nbl] = EyeNear - (Up * NearH2) - (Right * NearW2);
        vex[nbr] = EyeNear - (Up * NearH2) + (Right * NearW2);

        near_ = buildPlane(EyeNear, vex[ntr], vex[ntl]);
        far_ = buildPlane(EyeFar, vex[ftl], vex[ftr]);
        top_ = buildPlane(vex[ntr], vex[ftr], vex[ftl]);
        bottom_ = buildPlane(vex[nbl], vex[fbl], vex[fbr]);
        right_ = buildPlane(vex[nbr], vex[fbr], vex[ftr]);
        left_ = buildPlane(vex[ntl], vex[ftl], vex[fbl]);

        viewFrustumAABB_ = hAABB::computeFromPointSet(vex, 8);

#undef ftl
#undef ftr
#undef fbl
#undef fbr
#undef ntl
#undef ntr
#undef nbl
#undef nbr
    }
Exemple #4
0
	void hViewFrustum::updateFromCamera( const hVec3& EyeVec, const hVec3& LookDir, const hVec3& Up, hFloat fov, hFloat Aspect, hFloat Near, hFloat Far) {
		hFloat oNear = Near;

		hFloat FarH = 2.f * tanf( fov / 2.f ) * Far;
		hFloat FarW = FarH * Aspect;
		hFloat NearH = 2.f * tanf( fov / 2.f ) * oNear;
		hFloat NearW = NearH * Aspect;
		hVec3 Right;
		hVec3 D = normalize( LookDir );
		hVec3 EyeFar = EyeVec + ( D * Far );
		hVec3 EyeNear = EyeVec + ( D * Near );
		Right = cross( Up, D );

		// re-generate our 6 planes
#define ftl ((hUint)Point::FarTopLeft)
#define ftr ((hUint)Point::FarTopRight)
#define fbl ((hUint)Point::FarBottomLeft)
#define fbr ((hUint)Point::FarBottomRight)
#define ntl ((hUint)Point::NearTopLeft) 
#define ntr ((hUint)Point::NearTopRight)
#define nbl ((hUint)Point::NearBottomLeft)
#define nbr ((hUint)Point::NearBottomRight)

		Heart::hVec3 vex[ 8 ];
		hFloat FarW2 = FarW / 2;
		hFloat FarH2 = FarH / 2;
		hFloat NearH2 = NearH / 2;
		hFloat NearW2 = NearW / 2;

		vex[ ftl ] = EyeFar + ( Up * FarH2 ) - ( Right * FarW2 );
		vex[ ftr ] = EyeFar + ( Up * FarH2 ) + ( Right * FarW2 );
		vex[ fbl ] = EyeFar - ( Up * FarH2 ) - ( Right * FarW2 );
		vex[ fbr ] = EyeFar - ( Up * FarH2 ) + ( Right * FarW2 );

		vex[ ntl ] = EyeNear + ( Up * NearH2 ) - ( Right * NearW2 );
		vex[ ntr ] = EyeNear + ( Up * NearH2 ) + ( Right * NearW2 );
		vex[ nbl ] = EyeNear - ( Up * NearH2 ) - ( Right * NearW2 );
		vex[ nbr ] = EyeNear - ( Up * NearH2 ) + ( Right * NearW2 );

		for ( hUint32 i = 0; i < 8; ++i )
		{
			frustumPoints[ i ] = vex[ i ];
		}

		//
		{
			near_   = buildPlane( EyeNear, vex[ ntr ], vex[ ntl ] );
			far_    = buildPlane( EyeFar, vex[ ftl ], vex[ ftr ] );
			top_    = buildPlane( EyeVec, vex[ ftr ], vex[ ftl ] );
			bottom_ = buildPlane( EyeVec, vex[ fbl ], vex[ fbr ] );
			right_  = buildPlane( EyeVec, vex[ fbr ], vex[ ftr ] );
			left_   = buildPlane( EyeVec, vex[ ftl ], vex[ fbl ] );
		}

        viewFrustumAABB_ = hAABB::computeFromPointSet( vex, 8 );

	#undef ftl
	#undef ftr
	#undef fbl
	#undef fbr
	#undef ntl
	#undef ntr
	#undef nbl
	#undef nbr

	}