コード例 #1
0
ファイル: MooseOrientable.cpp プロジェクト: moose3d/moose
void
Moose::Spatial::COrientable::RotateLocal( float fRightAngle, float fUpAngle, float fForwardAngle )
{


  /* Get the Rotations from LOCAL axis */
  CQuaternion qOne; qOne.CreateFromAxisAngle( m_vRight[0],
					      m_vRight[1],
					      m_vRight[2], 
					      fRightAngle );
  
  CQuaternion qTwo; qTwo.CreateFromAxisAngle( m_vUpward[0], 
					      m_vUpward[1],
					      m_vUpward[2],
					      fUpAngle );
  qOne = qTwo * qOne;
  qTwo.CreateFromAxisAngle( m_vForward[0], 
			    m_vForward[1],
			    m_vForward[2],
			    fForwardAngle );
  qOne = qTwo * qOne;
  /* Apply the combined rotation to each vector */
  RotateAllDirections(qOne);

  m_qRotation = qOne * m_qRotation;
  SetRotationChanged(1);
}
コード例 #2
0
ファイル: MooseOrientable.cpp プロジェクト: moose3d/moose
void
Moose::Spatial::COrientable::Rotate( float fXAngle, float fYAngle, float fZAngle )
{

  // get rotations
  CQuaternion qOne; qOne.CreateFromAxisAngle( 1.0, 0.0, 0.0, fXAngle );
  CQuaternion qTwo; qTwo.CreateFromAxisAngle( 0.0, 1.0, 0.0, fYAngle );
  qOne = qTwo * qOne;
  qTwo.CreateFromAxisAngle( 0.0, 0.0, 1.0, fZAngle );

  qOne = qTwo * qOne;
  
  RotateAllDirections(qOne);
  m_qRotation = qOne * m_qRotation;
  SetRotationChanged(1);
}
コード例 #3
0
ファイル: MooseOrientable.cpp プロジェクト: moose3d/moose
void
Moose::Spatial::COrientable::RotateAroundZ( float degrees ) 
{

  CQuaternion q; q.CreateFromAxisAngle( 0.0f, 0.0f, 1.0f, degrees );
  m_qRotation = q * m_qRotation;
  RotateAllDirections( q );
  SetRotationChanged(1);

}
コード例 #4
0
ファイル: MooseOrientable.cpp プロジェクト: moose3d/moose
void
Moose::Spatial::COrientable::RotateAroundForward( float fDegrees ) 
{
  
  /* get rotations using local m_vForward */
  CQuaternion q; q.CreateFromAxisAngle( m_vForward[0], m_vForward[1],
					m_vForward[2], fDegrees );
  m_qRotation = q * m_qRotation;
  RotateVector(q,m_vRight);
  RotateVector(q,m_vUpward);
  SetRotationChanged(1);
    m_vRight.Normalize();
    m_vUpward.Normalize();
}
コード例 #5
0
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

		// 	    Position          View	     Up Vector
	gluLookAt(0, 1, 2,  0, 0, 0,   0, 1, 0);			// This determines where the camera's position and view is

	// This sets our line width to %250, since 1 is %100 for normal line width
	glLineWidth(2.5f);

	// Turn off lighting so our line isn't effected by it
	glDisable(GL_LIGHTING);

	// Create a static variable to hold the increasing rotation
	static float rotation = 0;

	// Create a 4x4 matrix to be used to convert a quaternion to a matrix
	float matrix[16];

	// Create a quaternion to rotate the line segment around the y-axis
	CQuaternion qRotationY;
	
	// Now we need to assign a rotation to our quaternion.  Since a quaternion
	// isn't intuitive to us, we want to assign a rotation by an axis and angle.
	// This means, we give it an axis and an angle to rotate around that axis.
	// This is what glRotatef() takes as well.

	// Assign the y-axis and the current rotation to our quaternion.  This will then
	// be converted to (x, y, z and w).  At first you might think of the x, y, z and
	// w as the axis and angle, but it's not really.  It's a 4D spherical rotation.
	qRotationY.CreateFromAxisAngle(0, 1, 0, rotation);

	// Once we have our desired rotation stored in a quaternion, in order for us to
	// do anything useful with it, we need to convert it to a matrix.  This matrix
	// will then be multiplied by our current model view matrix, which performs the rotation.

	// Pass in our local matrix and store the rotation 
	// matrix to be applied to our current matrix.
	qRotationY.CreateMatrix(matrix);

	// To apply our rotation, we multiply the new quaternion matrix by the current matrix.
	glMultMatrixf(matrix);

	// After applying the rotation, we now want to draw the line segment

	glBegin (GL_LINES);									// This is our BEGIN to draw
		glColor3ub(255, 255, 0);						// Make the Left vertex YELLOW
		glVertex3f(g_vLine[0].x, g_vLine[0].y, g_vLine[0].z);

		glColor3ub(255, 0, 0);							// Make the Right vertex RED
		glVertex3f(g_vLine[1].x, g_vLine[1].y, g_vLine[1].z);
	glEnd();											// This is the END of drawing

	// Turn lighting back on for the sphere
	glEnable(GL_LIGHTING);								

	// Instead of calculating the sphere ourselves, we are going to use quadrics.
	// Check out the tutorial on quadrics if this is confusing for you.

	// Allocate a quadric object to use as a sphere
	GLUquadricObj *pObj = gluNewQuadric();				// Get a Quadric off the stack

	// Here we create a quaternion that will be used to rotate the sphere around the line
	CQuaternion qSphereRotation;

	// Set the rotation of this quaternion to rotate around the x-axis with a faster rotation
	qSphereRotation.CreateFromAxisAngle(1, 0, 0, rotation * 8);

	// Once more, fill the matrix with the quaternion rotation matrix
	qSphereRotation.CreateMatrix(matrix);

	// Apply this matrix to our current matrix, which happens to still have the original
	// rotation that was applied from the line segment.  This is how we get the sphere
	// to rotate around the line, wherever it goes.
	glMultMatrixf(matrix);

	// Turn the sphere green
	glColor3ub(0, 255, 0);

	// Move the sphere to it's current position.  This can be changed by the arrow keys.
	// The higher the y position of the sphere, the large the radius of rotation the sphere
	// has around the line.
	glTranslatef(g_vPosition.x, g_vPosition.y, g_vPosition.z);

	// Draw the quadric as a sphere with the radius of .05 and a 15 by 15 detail.
	// To increase the detail of the sphere, just increase the 2 last parameters.
	gluSphere(pObj, .05f, 15, 15);

	// Free the Quadric
	gluDeleteQuadric(pObj);								

	// Increase the rotation degree
	rotation++;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
}