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

  • 相关阅读:
    mysql_pw 指令 数据库创建过程
    node.js+mysql环境搭建
    MySQL 学习
    express 应用创建及app.js详解
    .NET MD5加密解密代码
    Axure 部件的交互样式
    easyUI -messager -消息框
    Window01
    linkbutton
    easyUi-datagrid 真分页 + 工具栏添加控件
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/7910638.html
Copyright © 2011-2022 走看看