简体   繁体   English

如何在OpenGL中的3D空间中移动2D对象

[英]How to move a 2d object in 3d space in OpenGL

Basically I create a 2d object in 3d space in OpenGL in C++. 基本上,我在C ++中的OpenGL中在3d空间中创建2d对象。 The way it's created it lies in y axis. 它的创建方式位于y轴上。 How do I move it so it'll lie in x axis? 我如何移动它使其位于x轴上? I tried glRotatef and glTranslatef but it doesn't work. 我尝试了glRotatef和glTranslatef,但是它不起作用。 Anyone can help? 有人可以帮忙吗?

Update: I am actually making a solar system. 更新:我实际上是在制作太阳系。 The planets lie in x axis. 行星位于x轴上。 But every time I try to draw the orbit for them by calling the following function, the circle always appear in y axis. 但是每次我尝试通过调用以下函数为它们绘制轨道时,圆总是出现在y轴上。 I want it to be in x axis to coincide with the planet. 我希望它在x轴上与地球重合。 I hope that clears things up. 我希望这可以解决问题。

void drawOrbit(float radius)
{
   glBegin(GL_POLYGON_BIT);

   glRotatef(90,1, 1.2, 1.0);
   for (int i=0; i<360; i++)
   {
      float degInRad = i*DEG2RAD;
      glVertex3f(radius * cos(degInRad), radius * sin(degInRad), 0.0);
      glVertex3f(cos(degInRad)*radius,sin(degInRad)*radius, 0.1);

   }

 glScalef(0.5, 0.5, 0.5);
    glTranslatef(-1.2, 1.2, 1.2);
    glRotatef(60, 1.0, 1.2, 1.0);

   glEnd();
}

All scale/translate/rotate operations have to be done before glBegin, in reverse order. 必须在glBegin之前以相反的顺序完成所有缩放/平移/旋转操作。 spirit: you first define the camera, then you go up to the objects in their local space. 精神:首先定义摄像机,然后转到其局部空间中的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM