Beispiel #1
0
/////////////////////////////////////////////////////////
// Rotate a frame around it's local Y axis
void gltRotateFrameLocalY(GLTFrame *pFrame, GLfloat fAngle)
    {
    GLTMatrix mRotation;
    GLTVector3 vNewForward;
    
    gltRotationMatrix((float)gltDegToRad(fAngle), 0.0f, 1.0f, 0.0f, mRotation);
    gltRotationMatrix(fAngle, pFrame->vUp[0], pFrame->vUp[1], pFrame->vUp[2], mRotation);

    gltRotateVector(pFrame->vForward, mRotation, vNewForward);
    memcpy(pFrame->vForward, vNewForward, sizeof(GLTVector3));
    }
Beispiel #2
0
//////////////////////////////////////////////////////////
//  Rotate a frame around it's local X axis
void gltRotateFrameLocalX(GLTFrame *pFrame, GLfloat fAngle)
    {
	GLTMatrix mRotation;
    GLTVector3 vNewForward;
    
//    gltRotationMatrix((float)gltDegToRad(fAngle), 1.0f, 0.0f, 0.0f, mRotation);
    gltRotationMatrix(fAngle, 1, 0, 0, mRotation);

    gltRotateVector(pFrame->vForward, mRotation, vNewForward);
    memcpy(pFrame->vForward, vNewForward, sizeof(GLTVector3));

   /* GLTMatrix mRotation;
    GLTVector3 vCross;
    GLTVector3 vNewVect;

    gltVectorCrossProduct(pFrame->vUp, pFrame->vForward, vCross);
    gltRotationMatrix(fAngle, vCross[0], vCross[1], vCross[2], mRotation);

    
    // Inline 3x3 matrix multiply for rotation only
    vNewVect[0] = mRotation[0] * pFrame->vForward[0] + mRotation[4] * pFrame->vForward[1] + mRotation[8] *  pFrame->vForward[2];	
    vNewVect[1] = mRotation[1] * pFrame->vForward[0] + mRotation[5] * pFrame->vForward[1] + mRotation[9] *  pFrame->vForward[2];	
    vNewVect[2] = mRotation[2] * pFrame->vForward[0] + mRotation[6] * pFrame->vForward[1] + mRotation[10] * pFrame->vForward[2];	
    memcpy(pFrame->vForward, vNewVect, sizeof(GLfloat)*3);

    // Update pointing up vector
    /*vNewVect[0] = mRotation[0] * pFrame->vUp[0] + mRotation[4] * pFrame->vUp[1] + mRotation[8] *  pFrame->vUp[2];	
    vNewVect[1] = mRotation[1] * pFrame->vUp[0] + mRotation[5] * pFrame->vUp[1] + mRotation[9] *  pFrame->vUp[2];	
    vNewVect[2] = mRotation[2] * pFrame->vUp[0] + mRotation[6] * pFrame->vUp[1] + mRotation[10] * pFrame->vUp[2];	
    memcpy(pFrame->vUp, vNewVect, sizeof(GLfloat) * 3);*/
	}
Beispiel #3
0
/////////////////////////////////////////////////////////////
// Rotate a frame around it's local Z axis
void gltRotateFrameLocalZ(GLTFrame *pFrame, GLfloat fAngle)
    {
    GLTMatrix mRotation;

    // Only the up vector needs to be rotated
    gltRotationMatrix(fAngle, pFrame->vForward[0], pFrame->vForward[1], pFrame->vForward[2], mRotation);

    GLTVector3 vNewVect;
    vNewVect[0] = mRotation[0] * pFrame->vUp[0] + mRotation[4] * pFrame->vUp[1] + mRotation[8] *  pFrame->vUp[2];	
    vNewVect[1] = mRotation[1] * pFrame->vUp[0] + mRotation[5] * pFrame->vUp[1] + mRotation[9] *  pFrame->vUp[2];	
    vNewVect[2] = mRotation[2] * pFrame->vUp[0] + mRotation[6] * pFrame->vUp[1] + mRotation[10] * pFrame->vUp[2];	
    memcpy(pFrame->vUp, vNewVect, sizeof(GLfloat) * 3);
    }
Beispiel #4
0
//////////////////////////////////////////////////////////
//  Rotate a frame around it's local X axis
void gltRotateFrameLocalX(GLTFrame *pFrame, GLfloat fAngle)
    {
    GLTMatrix mRotation;
    GLTVector3 vCross;
    
    gltVectorCrossProduct(vCross, pFrame->vUp, pFrame->vForward);
    gltRotationMatrix(fAngle, vCross[0], vCross[1], vCross[2], mRotation);

    GLTVector3 vNewVect;
    // Inline 3x3 matrix multiply for rotation only
    vNewVect[0] = mRotation[0] * pFrame->vForward[0] + mRotation[4] * pFrame->vForward[1] + mRotation[8] *  pFrame->vForward[2];	
    vNewVect[1] = mRotation[1] * pFrame->vForward[0] + mRotation[5] * pFrame->vForward[1] + mRotation[9] *  pFrame->vForward[2];	
    vNewVect[2] = mRotation[2] * pFrame->vForward[0] + mRotation[6] * pFrame->vForward[1] + mRotation[10] * pFrame->vForward[2];	
    memcpy(pFrame->vForward, vNewVect, sizeof(GLfloat)*3);

    // Update pointing up vector
    vNewVect[0] = mRotation[0] * pFrame->vUp[0] + mRotation[4] * pFrame->vUp[1] + mRotation[8] *  pFrame->vUp[2];	
    vNewVect[1] = mRotation[1] * pFrame->vUp[0] + mRotation[5] * pFrame->vUp[1] + mRotation[9] *  pFrame->vUp[2];	
    vNewVect[2] = mRotation[2] * pFrame->vUp[0] + mRotation[6] * pFrame->vUp[1] + mRotation[10] * pFrame->vUp[2];	
    memcpy(pFrame->vUp, vNewVect, sizeof(GLfloat) * 3);
    }
Beispiel #5
0
// Called to draw scene
void RenderScene(void)
    {
 //   GLTMatrix   transformationMatrix;   // Storeage for rotation matrix
  GLTMatrix rotationMatrix, translationMatrix, transformationMatrix;

    static GLfloat yRot = 0.0f;         // Rotation angle for animation
    yRot += 0.5f;
        
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
    // Build a rotation matrix
    gltRotationMatrix(gltDegToRad(yRot), 0.0f, 1.0f, 0.0f, transformationMatrix);
    transformationMatrix[12] = 0.0f;
    transformationMatrix[13] = 0.0f;
    transformationMatrix[14] = -2.5f;
        
    glLoadMatrixf(transformationMatrix);

    gltDrawTorus(0.35f, 0.15f, 40, 20);
    
    // Do the buffer Swap
    glutSwapBuffers();
    }