Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 旋转使用OpenGL绘制的二维对象_C++_Opengl_Graphics_Rotation - Fatal编程技术网

C++ 旋转使用OpenGL绘制的二维对象

C++ 旋转使用OpenGL绘制的二维对象,c++,opengl,graphics,rotation,C++,Opengl,Graphics,Rotation,我用OpenGL制作了一个奇特的形状,并使用此函数绘制该形状: drawShape(const Point & center, char radius, int points, int rotation) 在函数中,我有代码告诉OpenGL顶点的位置: glBegin(GL_LINE_LOOP); glColor3f(1.0, 1.0, 1.0); glVertex2f(center.getX() + 0.0, center.getY() + 1.0); // more v

我用OpenGL制作了一个奇特的形状,并使用此函数绘制该形状:

drawShape(const Point & center, char radius, int points, int rotation)
在函数中,我有代码告诉OpenGL顶点的位置:

glBegin(GL_LINE_LOOP);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2f(center.getX() + 0.0, center.getY() + 1.0);
  // more vertices
glEnd();

现在,当我添加
glRotatef(rotation,0.0,0.0,1.0)
时,我只希望我绘制的这个形状在屏幕上旋转。但是,如果我将其添加到
glBegin()
上方,它会旋转窗口中的所有内容。如果包含
glPushMatrix()
glPopMatrix()
之间的所有代码,则会围绕窗口中心旋转对象。如何仅旋转我绘制的对象?

通过将
center.getX
等添加到值中,您正在执行OpenGL的工作

你想要的是:

glPushMatrix();
glTranslatef(center.getX(), center.getY(), 0.0f);
glRotatef(rotation, 0.0, 0.0, 1.0);

glBegin(GL_LINE_LOOP);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2f(0.0, 1.0);
  // more vertices
glEnd();

glPopMatrix();

您可能可以通过使用
glScale
矩阵并在
glVertex
调用中假设半径为1.0来应用半径。

您通过将
center.getX
等添加到值中来完成OpenGL的工作

你想要的是:

glPushMatrix();
glTranslatef(center.getX(), center.getY(), 0.0f);
glRotatef(rotation, 0.0, 0.0, 1.0);

glBegin(GL_LINE_LOOP);
  glColor3f(1.0, 1.0, 1.0);
  glVertex2f(0.0, 1.0);
  // more vertices
glEnd();

glPopMatrix();

您可能可以通过使用
glScale
矩阵并在
glVertex
调用中假设半径为1.0来应用半径。

此外,我建议您学习使用顶点数组和顶点缓冲区对象,并取消立即模式(即不再使用glBegin…glEnd)。此外,我建议您学习使用顶点数组和顶点缓冲区对象,并取消立即模式(即不再使用glBegin…glEnd)。