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();
    }

  • 相关阅读:
    POJ 1469 COURSES 二分图最大匹配
    POJ 1325 Machine Schedule 二分图最大匹配
    USACO Humble Numbers DP?
    SGU 194 Reactor Cooling 带容量上下限制的网络流
    POJ 3084 Panic Room 求最小割
    ZOJ 2587 Unique Attack 判断最小割是否唯一
    Poj 1815 Friendship 枚举+求最小割
    POJ 3308 Paratroopers 最小点权覆盖 求最小割
    1227. Rally Championship
    Etaoin Shrdlu
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/7910638.html
Copyright © 2011-2022 走看看