Пример #1
0
CameraPersp	CameraPersp::getFrameSphere( const Sphere &worldSpaceSphere, int maxIterations ) const
{
	CameraPersp result = *this;
	result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * getCenterOfInterest() );
	
	float minDistance = 0.01f, maxDistance = 100000.0f;
	float curDistance = getCenterOfInterest();
	for( int i = 0; i < maxIterations; ++i ) {
		float curRadius = result.getScreenRadius( worldSpaceSphere, 2.0f, 2.0f );
		if( curRadius < 1.0f ) { // we should get closer
			maxDistance = curDistance;
			curDistance = ( curDistance + minDistance ) * 0.5f;
		}
		else { // we should get farther
			minDistance = curDistance;
			curDistance = ( curDistance + maxDistance ) * 0.5f;			
		}
		result.setEyePoint( worldSpaceSphere.getCenter() - result.mViewDirection * curDistance );
	}
	
	result.setCenterOfInterest( result.getEyePoint().distance( worldSpaceSphere.getCenter() ) );
	return result;
}
Пример #2
0
void Camera::use() {
	if (inUse) disable();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (mode == CAM_PERSPECTIVE) {
        float x = tan(fov/2) * znear;
        // l,r,b,t are specified on the near plane.
        //        L   R   bottom    top       near   far
        glFrustum(-x, x, -x/aspect, x/aspect, znear, zfar);
    } else {
        double x = orthoWidth / 2;
        double y = x / aspect;
        glOrtho(-x, x, -y, y, znear, zfar);
    }
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
    Vec3d at = getCenterOfInterest();
	//gluLookAt(position.x, position.y, position.z, at.x, at.y, at.z, up.x, up.y, up.z);
    glMultMatrix(getMatrix());
    
	inUse = true;
}