OpenGL画图旋转
#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画图旋转的更多相关文章
- OpenGL中旋转平移缩放等变换的顺序对模型的影响
l 前提: 0x01. 假设绘制顶点的语句为Draw Array,变换的语句(旋转.平移.缩放)为M,而 M0; M1; M2; Draw Array; 则称对Array先进行M2再进行M1.M0 0 ...
- opengl笔记——旋转,一段代码的理解
重看:opengl笔记——OpenGL好资料备忘 在找到这段代码,对理解opengl旋转很有帮助 ... glPushMatrix(); // initialze ModelView matrix g ...
- OPENGL画图类库
链接 https://www.opengl.org/wiki/Language_bindings http://blog.csdn.net/luozhuang/article/details/421 ...
- OpenGL 3D旋转的木箱
学习自: https://learnopengl-cn.github.io/01%20Getting%20started/08%20Coordinate%20Systems/#3d 0,首先添加glm ...
- Android平台下OpenGL初步
Android OpenGL ES 开发教程 从入门到精通 http://blog.csdn.net/zhoudailiang/article/details/50176143 http://blog ...
- Android平台下OpenGL图形编程
ref: Jayway Team Blog中OpenGL ES简明开发教程https://blog.jayway.com/tag/opengl-es/ OpenGL ES 开发教程http://www ...
- [转帖]Android平台下OpenGL初步
原文请看 Android平台下OpenGL初步 本文只关注于如何一步步实现在Android平台下运用OpenGl. 1.GLSurfaceView GLSurfaceView是Android应用程序中 ...
- [置顶] 使用Android OpenGL ES 2.0绘图之五:添加运动
传送门 ☞ 系统架构设计 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 传送门 ☞ GoF23种设计模式 ☞ 转载请注明 ☞ http://blog.csd ...
- HTML5 canvas画图
HTML5 canvas画图 HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript).不过,<canvas> 元素本身并没有绘制能力(它仅仅是 ...
随机推荐
- 「Poetize9」升降梯口
3056: 升降梯口 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 43 Solved: 42[Submit][Status] Description ...
- 基于物联网操作系统HelloX的智慧家庭体系架构
基于物联网操作系统HelloX的智慧家庭体系架构 智慧家庭是物联网的一个分支应用,是一个被广泛认同的巨大IT市场空间.目前市场上已经有很多针对智慧家庭的产品或解决方案,但与移动互联网不同,智慧家庭至今 ...
- 【模拟】Codeforces 691C Exponential notation
题目链接: http://codeforces.com/problemset/problem/691/C 题目大意: 输入一个数,把它表示成a·10b形式(aEb).输出aEb,1<=a< ...
- 【模拟】Codeforces 710C Magic Odd Square
题目链接: http://codeforces.com/problemset/problem/710/C 题目大意: 构造一个N*N的幻方.任意可行解. 幻方就是每一行,每一列,两条对角线的和都相等. ...
- UVa1349 Optimal Bus Route Design(二分图最佳完美匹配)
UVA - 1349 Optimal Bus Route Design Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- mac下的改装人生——第一次拆卸mbp,加入内存
这是我第一次拆我的mbp哈,心情无比激动. 在家门口电脑维修店的老板那里借来了螺丝刀.回家以后立刻开始了改装行动 我的MC700后盖是可以全部打开的,总共大概是10个螺丝的样子,上面靠右边的三颗是长螺 ...
- 第k大值01背包问题
http://acm.hdu.edu.cn/showproblem.php?pid=2639 /* 第一行输入t 代表t组测试数据 第二行 输入物品个数 背包容量 要求的第k大值 物品的价值 物品的重 ...
- 【BZOJ4327】JSOI2012 玄武密码 AC自动机
[BZOJ4327]JSOI2012 玄武密码 Description 在美丽的玄武湖畔,鸡鸣寺边,鸡笼山前,有一块富饶而秀美的土地,人们唤作进香河.相传一日,一缕紫气从天而至,只一瞬间便消失在了进香 ...
- C# 对JS编码/解码进行转换
public static class Extension { #region [编码/解码统一转换] /// <summary> /// /// </summary> /// ...
- android中Canvas使用drawBitmap绘制图片
1.主要的绘制图片方法 //Bitmap:图片对象,left:偏移左边的位置,top: 偏移顶部的位置 drawBitmap(Bitmap bitmap, float left, float ...