bool CCCameraBase::project3D(float x, float y)
{
    if( frameBufferID == -1 )
    {
        CCAppManager::CorrectOrientation( x, y );
    }
	
	x *= viewport[2];
    x += viewport[0];
	y *= viewport[3];
    y += viewport[1];

    if( GluUnProject( x, y, 0.0f, projectionResults.vNear ) &&
        GluUnProject( x, y, 1.0f, projectionResults.vFar ) )
	{
		// Figure out our ray's direction
        projectionResults.vDirection = projectionResults.vFar;
        projectionResults.vDirection.sub( projectionResults.vNear );
        projectionResults.vDirection.unitize();
        
        projectionResults.vLookAt = projectionResults.vNear;
        CCVector3 projectionOffset = CCVector3MulResult( projectionResults.vDirection, projectionResults.vNear.z );
        projectionResults.vLookAt.add( projectionOffset );
		return true;
	}
	
	return false;
}
const bool CCCameraBase::project3D(float x, float y)
{
    gEngine->renderer->correctOrientation( x, y );
	
	x *= viewport[2];
	y *= viewport[3];
    y += viewport[1];

    if( GluUnProject( x, y, 0.0f, projection.vNear ) &&
        GluUnProject( x, y, 1.0f, projection.vFar ) )
	{
		// Figure out our ray's direction
        projection.vDirection = projection.vFar;
        projection.vDirection.sub( projection.vNear );
        projection.vDirection.unitize();
        
        projection.vLookAt = projection.vNear;
        CCVector3 projectionOffset = CCVector3MulResult( projection.vDirection, projection.vNear.z );
        projection.vLookAt.add( projectionOffset );
        
		return true;
	}
	
	return false;
}
void CCCameraBase::project3DZ(CCVector3 *result, float x, float y, float offset)
{
    if( project3D( x, y ) )
    {
        // Cast the ray from our near plane
        if( offset == -1.0f )
        {
            offset = projectionResults.vNear.z / fabsf( projectionResults.vDirection.z );
        }
		
        *result = CCVector3MulResult( projectionResults.vDirection, offset );
        result->add( projectionResults.vNear );
    }
}