旋转形状变得旋转和平移 [英] rotate shape become rotate and translating

查看:253
本文介绍了旋转形状变得旋转和平移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新上用openGL,现在我想我旋转作出的正方形,但是当我旋转,广场不仅旋转,而且还走动,同时旋转。我想我在旋转犯了一个错误和翻译的过程,但找不到解决方案

 无效drawSquare(双X,双Y,INT NUM)
{
  双xLength = 0.6;
  双yLength = 0.6;    的for(int i = 0; I<民;我++)
    {
       glLoadIdentity();
       glPushMatrix();
       的glTranslatef(0,0,0.0);
       glRotatef(angleCW,0.0,0.0,1.0F);       在glBegin(GL_QUADS);       如果(我%2 == 0)
       {
         glColor3f(gCurrentRed,gCurrentGreen,gCurrentBlue);       }
       其他
       {
         glColor3f(0.0,0.0,0.0);
       }
       glVertex3f(X,Y,0);
       glVertex3f(X + xLength,Y,0);
       glVertex3f(X + xLength,Y + yLength,0);
       glVertex3f(X,Y + yLength,0);
       xLength - = 0.1;
       yLength - = 0.1;
       X + = 0.05;
       Y + = 0.05;
       glEnd();
       glPopMatrix();
     }
}


解决方案

您四边形要围绕原点(0,0,0)旋转。如果在你的股四头肌中间不是那么它要的的就像是翻译了。也许你可以把它翻译这样一个中心的四边形,旋转,然后将其转换回

编辑:

请参阅@ datenwolf的评论为例,在那里他:


  1. 创建了0,0,0四为中心

  2. 旋转四

  3. 转化四到它的位置

I'm new on using openGL, and now I'm trying to rotate the square i made, but when I rotate it, the square doesn't only rotate, but also moving around while rotating. I think I made a mistake on the rotate and translate process, but cannot find the the solution

void drawSquare(double x,double y, int num)
{
  double xLength = 0.6;
  double yLength = 0.6;

    for(int i=0;i<num;i++)
    {
       glLoadIdentity();
       glPushMatrix();      
       glTranslatef(0, 0, 0.0f);
       glRotatef(angleCW, 0.0f, 0.0f,1.0f);

       glBegin( GL_QUADS );

       if(i%2==0)
       {
         glColor3f(gCurrentRed,gCurrentGreen,gCurrentBlue);

       }
       else
       {
         glColor3f(0.0f,0.0f,0.0f);
       }
       glVertex3f(x,y,0);
       glVertex3f(x+xLength,y,0);
       glVertex3f(x+xLength,y+yLength,0);
       glVertex3f(x,y+yLength,0);
       xLength -=0.1;
       yLength -=0.1;
       x += 0.05;
       y += 0.05;
       glEnd();
       glPopMatrix();
     }
}

解决方案

Your quads are going to rotate around the origin (0,0,0). If that's not in the middle of your quads then it is going to look like it is translating too. Maybe you can translate it so the quads a centered, rotate it, and then translate it back

Edit:

See @datenwolf's comment for an example where he:

  1. creates the quad with 0,0,0 as the center
  2. rotates the quad
  3. translates the quad to its position

这篇关于旋转形状变得旋转和平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆