zoukankan      html  css  js  c++  java
  • OpenGL第十二节:旋转

    LTexture.cpp

    void LTexture::render( GLfloat x, GLfloat y, LFRect* clip, LFRect* stretch, GLfloat degrees )
    {
      if( mTextureID != 0 )
      {
        glLoadIdentity();

        GLfloat texTop = 0.f;
        GLfloat texBottom = (GLfloat)mImageHeight / (GLfloat)mTextureHeight;
        GLfloat texLeft = 0.f;
        GLfloat texRight = (GLfloat)mImageWidth / (GLfloat)mTextureWidth;

        GLfloat quadWidth = mImageWidth;
        GLfloat quadHeight = mImageHeight;

        if( clip != NULL )
        {
          texLeft = clip->x / mTextureWidth;
          texRight = ( clip->x + clip->w ) / mTextureWidth;
          texTop = clip->y / mTextureHeight;
          texBottom = ( clip->y + clip->h ) / mTextureHeight;

          quadWidth = clip->w;
          quadHeight = clip->h;
        }

        if( stretch != NULL )
        {
          quadWidth = stretch->w;
          quadHeight = stretch->h;
        }

        glTranslatef( x + quadWidth / 2.f, y + quadHeight / 2.f, 0.f );//移到绘制区域中心点

        glRotatef( degrees, 0.f, 0.f, 1.f );//旋转

        glBindTexture( GL_TEXTURE_2D, mTextureID );

        glBegin( GL_QUADS );
          glTexCoord2f( texLeft, texTop ); glVertex2f( -quadWidth / 2.f, -quadHeight / 2.f );
          glTexCoord2f( texRight, texTop ); glVertex2f( quadWidth / 2.f, -quadHeight / 2.f );
          glTexCoord2f( texRight, texBottom ); glVertex2f( quadWidth / 2.f, quadHeight / 2.f );
          glTexCoord2f( texLeft, texBottom ); glVertex2f( -quadWidth / 2.f, quadHeight / 2.f );
        glEnd();
      }
    }

    LUtil.cpp

    void update()
    {
      gAngle += 360.f / SCREEN_FPS;//旋转角度

      if( gAngle > 360.f )
      {
        gAngle -= 360.f;
      }
    }

    void render()
    {
      glClear( GL_COLOR_BUFFER_BIT );

      gRotatingTexture.render( ( SCREEN_WIDTH - gRotatingTexture.imageWidth() ) / 2.f, ( SCREEN_HEIGHT - gRotatingTexture.imageHeight() ) / 2.f, NULL, NULL, gAngle );

      glutSwapBuffers();
    }

  • 相关阅读:
    (10)C#静态方法,静态字段,静态类,匿名类
    (9)C#类
    (8)C#字符串
    (7)C#流程控制
    (6)C#方法,作用域,方法重载
    (5)C#运算符
    各个品牌主板快速开机启动
    口袋的天空
    繁忙的都市
    取水
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/7910638.html
Copyright © 2011-2022 走看看