#include<gl/glut.h>
#include<gl/GL.h>
#include<gl/GLU.h>
#include<math.h>
#include<iostream>
#define R 100
#define r 50
#define PI 3.1415926
double a1[5], b1[5], a2[5], b2[5];
double Height = 320;
double Width = 400;
void Calculate() {
    int angle = 70;
    for (int i = 0; i < 5; i++) {
        a1[i] = R*cos(angle*PI / 180);
        b1[i] = R*sin(angle*PI / 180);
        a2[i] = r*cos(PI / 5 + angle*PI / 180);
        b2[i] = r*sin(PI / 5 + angle*PI / 180);
        angle += 72;
    }
}
void Init() {
    Calculate();
}
double target = 0.00;
double theta = 0.00;
bool right = true;
bool left = true;
bool top = true;
bool bottom = true;
int count = 0;
double sc = 1;
bool scflg1 =true;
bool scflg2 = true;

void draw() {
    
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(0, 0, 0, 0);
    gluOrtho2D(-450, 450, -300, 300);//左右下上
    //glPushMatrix();
    /*
     glTranslatef(0.0f,-20.0f,-40.0f)表示将当前图形向x轴平移0,向y轴平移-20,向z轴平移-40
     glScaled(10.0f,10.0f,10.0f)表示将当前图形沿x,y,z轴分别放大为原来的10倍
    glRotatef(-80.0f,10.0f,1.0f,0.0f)表示将当前图形沿方向向量(-10,1,0)顺时针旋转80度。
    */
    //glPopMatrix();
        
    //glPushMatrix();
    if (target < Width-60 && right&&target<Height-100) {//平移到最右边
        target += 0.5;
    }
    else if(target>-Width+160 && left&&Height>-Height+150) {//到最右边返回到最左边
        right = false;
        target -= 0.5;
        
    }
    else {
        right = true;
    }
    glTranslated(target, target, 0);

glRotated(theta, 0, 0, 1);
    theta += 0.2;

if ( count <= 150 && scflg1) {
        scflg2 = false;
        sc += 0.001;
        count++;
        if (count == 151) {
            scflg2 = true;
        }
        std::cout << sc << " " << count << std::endl;
    }
    else if (scflg2) {
        scflg1 = false;
        sc -= 0.001;
        count--;
        if (count == -151) {
            scflg1 = true;
        }
    }

glScalef(sc, sc, 1);
    glBegin(GL_LINE_LOOP);
    for (int i = 0;i < 5;i++) {
        glVertex2d(a1[i], b1[i]);
        glVertex2d(a2[i], b2[i]);    
    }
    glEnd();
    //glPopMatrix();
    //glFlush();
    //glutSwapBuffers();

//glLoadIdentity();
    glColor3d(1, 1, 0);
    glFlush();
    glutSwapBuffers();//调换前后缓存
}

void DisPlay()
{   glClearColor(1.0, 1.0, 1.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT);//白色背景
    draw();
}

void main()
{
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowSize(900, 600);
    glutCreateWindow("第四次作业");
    
    Init();
    glutDisplayFunc(DisPlay);
    glutIdleFunc(DisPlay);
    glutMainLoop();
    system("pause");
}

OpenGL画图旋转的更多相关文章

  1. OpenGL中旋转平移缩放等变换的顺序对模型的影响

    l 前提: 0x01. 假设绘制顶点的语句为Draw Array,变换的语句(旋转.平移.缩放)为M,而 M0; M1; M2; Draw Array; 则称对Array先进行M2再进行M1.M0 0 ...

  2. opengl笔记——旋转,一段代码的理解

    重看:opengl笔记——OpenGL好资料备忘 在找到这段代码,对理解opengl旋转很有帮助 ... glPushMatrix(); // initialze ModelView matrix g ...

  3. OPENGL画图类库

    链接  https://www.opengl.org/wiki/Language_bindings http://blog.csdn.net/luozhuang/article/details/421 ...

  4. OpenGL 3D旋转的木箱

    学习自: https://learnopengl-cn.github.io/01%20Getting%20started/08%20Coordinate%20Systems/#3d 0,首先添加glm ...

  5. Android平台下OpenGL初步

    Android OpenGL ES 开发教程 从入门到精通 http://blog.csdn.net/zhoudailiang/article/details/50176143 http://blog ...

  6. Android平台下OpenGL图形编程

    ref: Jayway Team Blog中OpenGL ES简明开发教程https://blog.jayway.com/tag/opengl-es/ OpenGL ES 开发教程http://www ...

  7. [转帖]Android平台下OpenGL初步

    原文请看 Android平台下OpenGL初步 本文只关注于如何一步步实现在Android平台下运用OpenGl. 1.GLSurfaceView GLSurfaceView是Android应用程序中 ...

  8. [置顶] 使用Android OpenGL ES 2.0绘图之五:添加运动

    传送门 ☞ 系统架构设计 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 传送门 ☞ GoF23种设计模式 ☞ 转载请注明 ☞ http://blog.csd ...

  9. HTML5 canvas画图

    HTML5 canvas画图 HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript).不过,<canvas> 元素本身并没有绘制能力(它仅仅是 ...

随机推荐

  1. 固定IP和绑定了MAC,可以在设置无线路由器供笔记本电脑和平板上网吗?

    固定IP和绑定了MAC,可以在设置无线路由器供笔记本电脑和平板上网吗? 这跟我们单位一样.很简单:首先要占一个 IP/MAC ,能上外网的,这首先要有,谁要肯给地址,我们这儿领导才有呢.我是网管,当然 ...

  2. arcgis数据文件使用

    dem数据打开,保存,使用 打开

  3. 在Linux下查看环境变量

    原文地址:http://blog.chinaunix.net/uid-25124785-id-77098.html 有时候在编写makefile的时候,自己都不清楚有些变量是什么,也不清楚如何查看,于 ...

  4. trigger 触发器

    --trigger --在SC表上建了一个触发器,查看inserted和deleted表中内容. create trigger tri_1 on sc for insert,update,delete ...

  5. C#的dictionary使用总结

    Dictionary<string, string>是一个泛型,本身有集合的功能有时候可以把它看成数组. 他的结构是这样的:Dictionary<[key], [value]> ...

  6. geektool--一款很geek的工具

    2016/12/18 今天尝试一款很geek的工具 geektool 听名字就超级geek有木有 get it geektool website 从官网直接下载app,一键傻瓜式安装. use it ...

  7. ECLIPSE里面SVN图标消失,文件状态不显示问题

    ECLIPSE里面SVN状态图标消失,重新启动eclipse,重新导入工程也不能显示SVN状态图标.这多半是由于之前eclipse没有正常关闭引起的. 解决办法2个: 方法一:1. 在Window&g ...

  8. LayoutInflater和inflate()方法的使用方法

    public static LayoutInflaterfrom(Context context) { LayoutInflaterLayoutInflater = (LayoutInflater)c ...

  9. Linux &amp; Mac curl 命令行使用——POST&amp;GET

    http提交一个表单,比較经常使用的是POST模式和GET模式 在curl的命令行下,GET模式什么option都不用.仅仅须要把变量写在url里面就能够了 比方: curl http://www.s ...

  10. HDFS Users Guide--官方文档

    HDFS Users Guide Purpose Overview Prerequisites Web Interface Shell Commands DFSAdmin Command Second ...