对我的多维数据集

时间:2015-07-19 14:09:27

标签: c++ opengl sdl glm-math

我正在努力支持"基本"在openGL多维数据集上旋转转换和缩放。 绘制我的多维数据集的代码如下:

void drawCube(){
    glBegin(GL_QUADS);                // Begin drawing the color cube with 6 quads
      // Top face (y = 1.0f)
      // Define vertices in counter-clockwise (CCW) order with normal pointing out
      glColor3f(0.0f, 1.0f, 0.0f);     // Green
      glVertex3f( 1.0f, 1.0f, -1.0f);
      glVertex3f(-1.0f, 1.0f, -1.0f);
      glVertex3f(-1.0f, 1.0f,  1.0f);
      glVertex3f( 1.0f, 1.0f,  1.0f);

      // Bottom face (y = -1.0f)
      glColor3f(1.0f, 0.5f, 0.0f);     // Orange
      glVertex3f( 1.0f, -1.0f,  1.0f);
      glVertex3f(-1.0f, -1.0f,  1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f( 1.0f, -1.0f, -1.0f);

      // Front face  (z = 1.0f)
      glColor3f(1.0f, 0.0f, 0.0f);     // Red
      glVertex3f( 1.0f,  1.0f, 1.0f);
      glVertex3f(-1.0f,  1.0f, 1.0f);
      glVertex3f(-1.0f, -1.0f, 1.0f);
      glVertex3f( 1.0f, -1.0f, 1.0f);

      // Back face (z = -1.0f)
      glColor3f(1.0f, 1.0f, 0.0f);     // Yellow
      glVertex3f( 1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f,  1.0f, -1.0f);
      glVertex3f( 1.0f,  1.0f, -1.0f);

      // Left face (x = -1.0f)
      glColor3f(0.0f, 0.0f, 1.0f);     // Blue
      glVertex3f(-1.0f,  1.0f,  1.0f);
      glVertex3f(-1.0f,  1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f, -1.0f);
      glVertex3f(-1.0f, -1.0f,  1.0f);

      // Right face (x = 1.0f)
      glColor3f(1.0f, 0.0f, 1.0f);     // Magenta
      glVertex3f(1.0f,  1.0f, -1.0f);
      glVertex3f(1.0f,  1.0f,  1.0f);
      glVertex3f(1.0f, -1.0f,  1.0f);
      glVertex3f(1.0f, -1.0f, -1.0f);
   glEnd();  // End of drawing color-cube
} 
    void display(void)
{

    //Angle of view:40 degrees
    //Near clipping plane distance: 0.5
    //Far clipping plane distance: 20.0

    glMatrixMode(GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    // clear the drawing buffer.
    glClear(GL_COLOR_BUFFER_BIT);
    // clear the identity matrix.
    glMultMatrixf(rM);
    // scaling transfomation 
    glScalef(0.5,0.5,0.5);
    glPushMatrix();
    drawCube();
    glPopMatrix();

    // Flush buffers to screen
    glFlush(); 
    SDL_GL_SwapBuffers();       
    // sawp buffers called because we are using double buffering 

}

我正在使用glm来创建表示旋转平移和缩放应用的变换矩阵。我用鼠标坐标来找到相应的翻译,旋转...... 旋转工作正常,但是当我尝试翻译时,我得到了奇怪的结果。例如,我只能看到立方体的黄色面,根本没有恢复立方体的方法。我尝试打印转换矩阵以检查它是否正确并且似乎更正了。 以下是我获取转换矩阵的方法

rM = translationMatrix * mMatNow * scaleMatrix ;

这是我原来的转换矩阵:

1; 0; 0; 0; 0; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0; 1;

这是快速翻译后的那个:

1; 0; 0; -7; 0; 1; 0; 0; 0; 0; 1; 0; 0; 0; 0; 1;

因此这里是相应的图像: Original Drawing After Translation

0 个答案:

没有答案