Ejemplo n.º 1
0
void Camera::applyViewingTransform() {
	if( mDirtyTransform )
		calculateViewingTransformParameters();

	// Place the camera at mPosition, aim the camera at
	// mLookAt, and twist the camera such that mUpVector is up
	/*
	gluLookAt(	mPosition[0], mPosition[1], mPosition[2],
				mLookAt[0],   mLookAt[1],   mLookAt[2],
				mUpVector[0], mUpVector[1], mUpVector[2]);
				*/
	lookAt(	Vec3f(mPosition[0], mPosition[1], mPosition[2]), 
				Vec3f(mLookAt[0],   mLookAt[1],   mLookAt[2]), 
				Vec3f(mUpVector[0], mUpVector[1], mUpVector[2]));
}
Ejemplo n.º 2
0
void ModelerCamera::dragMouse( int x, int y )
{
	Vec3f mouseDelta   = Vec3f(x,y,0.0f) - mLastMousePosition;
	mLastMousePosition = Vec3f(x,y,0.0f);

	switch(mCurrentMouseAction)
	{
	case kActionTranslate:
		{
			calculateViewingTransformParameters();

			double xTrack =  -mouseDelta[0] * kMouseTranslationXSensitivity;
			double yTrack =  mouseDelta[1] * kMouseTranslationYSensitivity;

			Vec3f transXAxis = mUpVector ^ (mPosition - mLookAt);
			transXAxis /= sqrt((transXAxis*transXAxis));
			Vec3f transYAxis = (mPosition - mLookAt) ^ transXAxis;
			transYAxis /= sqrt((transYAxis*transYAxis));

			setLookAt(getLookAt() + transXAxis*xTrack + transYAxis*yTrack);
			
			break;
		}
	case kActionRotate:
		{
			float dAzimuth		=   -mouseDelta[0] * kMouseRotationSensitivity;
			float dElevation	=   mouseDelta[1] * kMouseRotationSensitivity;
			
			setAzimuth(getAzimuth() + dAzimuth);
			setElevation(getElevation() + dElevation);
			
			break;
		}
	case kActionZoom:
		{
			float dDolly = -mouseDelta[1] * kMouseZoomSensitivity;
			setDolly(getDolly() + dDolly);
			break;
		}
	case kActionTwist:
		// Not implemented
	default:
		break;
	}

}
Ejemplo n.º 3
0
Camera::Camera() 
{
	mAzimuth = mTwist = 0.0f;
	mElevation = 0.7f;
	mDolly = -20.0f;

	mLookAt = Vec3f( 0, 0, 0 );

	mCurrentMouseAction = kActionNone;

	m_bSnapped = false;
	for (int i=AZIMUTH; i<NUM_KEY_CURVES; i++)
		mKeyframes[i] = NULL;

	calculateViewingTransformParameters();

	mNumKeyframes = 0;
}
Ejemplo n.º 4
0
void Camera::applyViewingTransform() {
	if( mDirtyTransform )
		calculateViewingTransformParameters();

	ModelerDrawState *mds = ModelerDrawState::Instance();

	if(mds->m_rayFile)
	{
		fprintf( mds->m_rayFile, "camera {\n\tposition = (%f, %f, %f);\n\tlook_at = (%f, %f, %f);\n\taspectratio = 1\n\tfov = 30; }\n\n",
			mPosition[0], mPosition[1], mPosition[2],
			mLookAt[0], mLookAt[1], mLookAt[2]);

		
	}

	// Place the camera at mPosition, aim the camera at
	// mLookAt, and twist the camera such that mUpVector is up
    /*gluLookAt(	mPosition[0], mPosition[1], mPosition[2],
				mLookAt[0],   mLookAt[1],   mLookAt[2],
				mUpVector[0], mUpVector[1], mUpVector[2]);*/

    // You Will Have to implement this (gluLookAt() ) yourself!
	// what fun that will be!
    Vec3f n = mPosition - mLookAt;
    Vec3f v = mUpVector - ((mUpVector * n) / (n * n)) * n;
    Vec3f u = v ^ n;
    u.normalize();
    v.normalize();
    n.normalize();

    Mat4f mat;
    mat[0][0] = u[0]; mat[0][1] = v[0]; mat[0][2] = n[0];
    mat[1][0] = u[1]; mat[1][1] = v[1]; mat[1][2] = n[1];
    mat[2][0] = u[2]; mat[2][1] = v[2]; mat[2][2] = n[2];
    mat = mat.transpose();
    mat = mat * mat.createTranslation(-mPosition[0], -mPosition[1], -mPosition[2]);
    
    // Transpose the final matrix so that n is in column-major order to match OpenGL.
    mat = mat.transpose();
    glMultMatrixf(mat.n);
}