Exemplo n.º 1
0
//----------------------------------------------------------------//
USRect MOAIScissorRect::GetScissorRect ( const USMatrix4x4& worldToWndMtx ) const {

	USVec3D vtx3D [ 4 ];

	vtx3D [ 0 ].mX = this->mRect.mXMin;
	vtx3D [ 0 ].mY = this->mRect.mYMin;
	vtx3D [ 0 ].mZ = 0.0f;

	vtx3D [ 1 ].mX = this->mRect.mXMin;
	vtx3D [ 1 ].mY = this->mRect.mYMax;
	vtx3D [ 1 ].mZ = 0.0f;
	
	vtx3D [ 2 ].mX = this->mRect.mXMax;
	vtx3D [ 2 ].mY = this->mRect.mYMax;
	vtx3D [ 2 ].mZ = 0.0f;

	vtx3D [ 3 ].mX = this->mRect.mXMax;
	vtx3D [ 3 ].mY = this->mRect.mYMin;
	vtx3D [ 3 ].mZ = 0.0f;

	USMatrix4x4 mtx;
	
	mtx.Init ( this->GetLocalToWorldMtx ());
	mtx.Append ( worldToWndMtx );
	
	mtx.Project ( vtx3D [ 0 ]);
	mtx.Project ( vtx3D [ 1 ]);
	mtx.Project ( vtx3D [ 2 ]);
	mtx.Project ( vtx3D [ 3 ]);
	
	USRect scissorRect;

	scissorRect.Init ( vtx3D [ 0 ]);
	scissorRect.Grow ( vtx3D [ 1 ]);
	scissorRect.Grow ( vtx3D [ 2 ]);
	scissorRect.Grow ( vtx3D [ 3 ]);

	if ( this->mScissorRect ) {
		USRect parentRect = this->mScissorRect->GetScissorRect ( worldToWndMtx );
		parentRect.Clip ( scissorRect );
	}

	return scissorRect;
}
Exemplo n.º 2
0
//----------------------------------------------------------------//
void USFrustum::Init ( const USMatrix4x4& mtx ) {

	// set up the homogenous coordinates of the canonical view volume
	USVec3D nlt ( -1.0f, 1.0f, -1.0f );
	USVec3D nrt ( 1.0f, 1.0f, -1.0f );
	USVec3D nrb ( 1.0f, -1.0f, -1.0f );
	USVec3D nlb ( -1.0f, -1.0f, -1.0f );

	USVec3D flt ( -1.0f, 1.0f, 1.0f );
	USVec3D frt ( 1.0f, 1.0f, 1.0f );
	USVec3D frb ( 1.0f, -1.0f, 1.0f );
	USVec3D flb ( -1.0f, -1.0f, 1.0f );

	// compute the corners of the frustum
	mtx.Project ( nlt );
	mtx.Project ( nrt );
	mtx.Project ( nrb );
	mtx.Project ( nlb );
	
	mtx.Project ( flt );
	mtx.Project ( frt );
	mtx.Project ( frb );
	mtx.Project ( flb );

	this->mPoints [ NEAR_LT_POINT ].Init ( nlt.mX, nlt.mY, nlt.mZ );
	this->mPoints [ NEAR_RT_POINT ].Init ( nrt.mX, nrt.mY, nrt.mZ );
	this->mPoints [ NEAR_RB_POINT ].Init ( nrb.mX, nrb.mY, nrb.mZ );
	this->mPoints [ NEAR_LB_POINT ].Init ( nlb.mX, nlb.mY, nlb.mZ );
	
	this->mPoints [ FAR_LT_POINT ].Init ( flt.mX, flt.mY, flt.mZ );
	this->mPoints [ FAR_RT_POINT ].Init ( frt.mX, frt.mY, frt.mZ );
	this->mPoints [ FAR_RB_POINT ].Init ( frb.mX, frb.mY, frb.mZ );
	this->mPoints [ FAR_LB_POINT ].Init ( flb.mX, flb.mY, flb.mZ );

	// Compute the frustum's axis-aligned bounding box
	this->mAABB.Init ( nlt );
	this->mAABB.Grow ( nrt );
	this->mAABB.Grow ( nrb );
	this->mAABB.Grow ( nlb );
	
	this->mAABB.Grow ( flt );
	this->mAABB.Grow ( frt );
	this->mAABB.Grow ( frb );
	this->mAABB.Grow ( flb );
	
	// intialize the planes
	this->mPlanes [ LEFT_PLANE ].Init ( nlt, flt, flb );
	this->mPlanes [ RIGHT_PLANE ].Init ( nrb, frb, frt );
	
	this->mPlanes [ TOP_PLANE ].Init ( nrt, frt, flt );
	this->mPlanes [ BOTTOM_PLANE ].Init ( nlb, flb, frb );
	
	this->mPlanes [ NEAR_PLANE ].Init ( nrt, nlt, nlb );
	this->mPlanes [ FAR_PLANE ].Init ( flt, frt, frb );
	
	USVec3D center;
	mtx.GetTranslation ( center );
	
	for ( u32 i = 0; i < TOTAL_PLANES; ++i ) {
		if ( USDist::VecToPlane ( center, this->mPlanes [ i ]) > 0.0f ) {
			this->mPlanes [ i ].Flip ();
		}
	}
	
	double frustArea = _frustArea ( *this );
	double boxArea = this->mAABB.Area ();
	
	this->mUsePlanes = (( float )( frustArea / boxArea )) < MIN_FILL_RATIO;
}