示例#1
0
// This routine assumes that srcRect maps into dstArea
// and trims both the dst and the src proportionally to accommodate any clipping
void getClippedScaledRects( const Area &srcSurfaceBounds, const Rectf &srcRect, const Area &dstSurfaceBounds, const Area &dstArea, Rectf *resultSrcRect, Area *resultDstArea )
{
	// clip the destination, create newSrcRect from mapping
	Area clippedDst = dstArea.getClipBy( dstSurfaceBounds );
	Rectf newSrcRect = RectMapping( Rectf( dstArea ), srcRect ).map( Rectf( clippedDst ) );

	// clip the src, create newDstRect from mapping
	newSrcRect.clipBy( Rectf( srcSurfaceBounds ) );
	Rectf newDstRect = RectMapping( srcRect, Rectf( dstArea ) ).map( Rectf( newSrcRect ) );

	// discretize and clip the destinaton
	// the discretization is done to minimize the area
	*resultDstArea = newDstRect.getInteriorArea();
	resultDstArea->clipBy( dstSurfaceBounds );
	
	// now map the discretized, clipped destination back once more to get the final source
	*resultSrcRect = RectMapping( Rectf( dstArea ), srcRect ).map( Rectf( *resultDstArea ) );
	
	// this is not kosher, but sometimes we need to fudge things on the src to keep it in bounds
	resultSrcRect->clipBy( Rectf( srcSurfaceBounds ) );
}
示例#2
0
void KinectUser::setBounds( const Rectf &rect )
{
	mOutputRect = rect;

	Rectf kRect( 0, 0, 640, 480 ); // kinect image rect
	Rectf dRect = kRect.getCenteredFit( mOutputRect, true );
	if ( mOutputRect.getAspectRatio() > dRect.getAspectRatio() )
		dRect.scaleCentered( mOutputRect.getWidth() / dRect.getWidth() );
	else
		dRect.scaleCentered( mOutputRect.getHeight() / dRect.getHeight() );

	mOutputMapping = RectMapping( kRect, dRect, true );
}