简体   繁体   中英

How to move a 2d object in 3d space in OpenGL

Basically I create a 2d object in 3d space in OpenGL in C++. The way it's created it lies in y axis. How do I move it so it'll lie in x axis? I tried glRotatef and glTranslatef but it doesn't work. Anyone can help?

Update: I am actually making a solar system. The planets lie in x axis. But every time I try to draw the orbit for them by calling the following function, the circle always appear in y axis. I want it to be in x axis to coincide with the planet. 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. spirit: you first define the camera, then you go up to the objects in their local space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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