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> 元素本身并没有绘制能力(它仅仅是 ...
随机推荐
- 安装配置MongoDB
1.下载mongodb https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.8.tgz 2.解压 tar zxf mongodb-lin ...
- webserver/CGI
来自:http://blog.sina.com.cn/s/blog_466c6640010000nj.html 1. TUX2. lighttpd,thttpd,shttpd 3. 几种web s ...
- 【动态规划】【KMP】HDU 5763 Another Meaning
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5763 题目大意: T组数据,给两个字符串s1,s2(len<=100000),s2可以被解读成 ...
- poj1065
题目大意: 木棍(好吧,承认确实做过这个题,嘎嘎) 有一堆木棍大约有n根,木棍的长度和重量都预先知道,这些木棍会在一个木工机械上一个接一个的处理,这需要一些时间,称为设置时间,为机械准备处理一根木头, ...
- poj2299
好吧,看到这个图片就知道是干什么的了,求逆序数- - 可以用线段树,貌似还可以用归并排序,这题应该是考的归并排序,毕竟是递归分治- - 基本上都忘了,再写一写试试吧. AC ///////////// ...
- the identity used to sign the executable is no longer valid.解决方法
the identity used to sign the executable is no longer valid.解决方法 一.重新下载Provisioning Profile 1.到devel ...
- ural 1136. Parliament
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1136 题目描述:给定一个按照(左子树-右子树-根)(即先序)遍历序列的树,求其按照 右子 ...
- Away3D 4.1.4 中实现骨骼绑定
骨骼的绑定归根结底就是将目标骨骼的位置以及旋转数据,同步给要绑定的显示对象. 先来看BindingTag.as package away3d.entities { import away3d. ...
- lucene4.0与之前版本的一些改变
最近在用lucene4.0,因为之前也没用过lucene其它版本,所以也不是很熟悉.但每次上网查资料代码的时候,总发现网友们贴的代码都是之前的版本的.当我拷贝过来的时候总会出问题,去查API的时候,总 ...
- SQL Server通过整理索引碎片和重建索引提高速度
本文章转载:http://database.51cto.com/art/201108/282408.htm SQL Server数据库中,当索引碎片太多时,就会拖慢数据库查询的速度.这时我们可以通过整 ...