当前位置:网站首页>Opengl模拟现实生活中,球掉到地面上再弹起来的过程,在屏幕上绘制一个球,球从上往下掉,碰到地面,再弹起来。
Opengl模拟现实生活中,球掉到地面上再弹起来的过程,在屏幕上绘制一个球,球从上往下掉,碰到地面,再弹起来。
2022-07-24 05:16:00 【陌小呆^O^】
//模拟现实生活中,球掉到地面上再弹起来的过程,在屏幕上绘制一个球,球从上往下掉,碰到地面,再弹起来。
#define GLUT_DISABLE_ATEXIT_HACK
#include <gl/glut.h>
float y=1.5f;
float dy=-0.4f;
//初始化OpenGL
void DrawCube()
{
//设置清屏颜色为黑色
glClearColor(0.0f,0.0f,0.0f,0.0f);
//清除颜色缓冲区和深度缓冲区
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0f,y,0.0f);
glColor3f(1.0f,0.5f,0.5f);
glutSolidSphere(1.0,50,10);
glPopMatrix();
}
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_FLAT);
}
//主要的绘制过程
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);//清除颜色缓存
glLoadIdentity();
glTranslatef(0,0,-5);
glColor3f(1.0,0,0);
DrawCube();
glFlush();
}
//在窗口改变大小时调用
void reshape(int w, int h){
glViewport(0, 0, w, h);//设置视口
glMatrixMode(GL_PROJECTION);//设置当前为投影变换模式
glLoadIdentity();//用单位矩阵替换当前变换矩阵
gluPerspective(100, (float)w/h, 3, 100.0);//设置正交投影视图体
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}
void TimerFunction(int value)
{
y+=dy;
if(y<=-2||y>=3.5)
dy=-dy;
glutTimerFunc(100,TimerFunction, 1);
// Redraw the scene with new coordinates
glutPostRedisplay();
}
void main( )
{
glutCreateWindow("2");//设置窗口标题
init();//初始化OpenGL
glutDisplayFunc(display);//设置显示回调函数
glutReshapeFunc(reshape);//设置reshape回调函数
glutTimerFunc(100,TimerFunction, 1);
glutMainLoop();//进入主循环
}
边栏推荐
- Skills of BeanShell dealing with JSON
- ros启动非本机节点
- JDBC encapsulates a parent class to reduce code duplication
- C语言入门篇 概述
- Web development
- 使用swagger2markup生成API文档
- c2-随机产生函数种子seed、numpy.random.seed()、tf.random.set_seed学习+转载整理
- 赶紧进来!!轻松掌握C语言“顺序”、“分支”、“循环”三大结构
- 模拟加法 & 结构体基本用法
- Pointer learning diary (IV) use structure and pointer (linked list)
猜你喜欢
随机推荐
C语言入门篇 概述
jdbc的增删改查
Embedded system transplantation [3] - uboot burning and use
Pointer learning diary (V) classic abstract data types and standard function libraries
C#进程运行权限
SSH service
线程的介绍
统计学之样本和总体的关系: 样本成功比例+中心极限定理(样本均值)
scikit-learn笔记
【Pytorch】nn.Module
Detailed explanation of string constant pool and intern() of string
栈与队列的互相实现(C)
Reading excerpts from Liu run's "bottom logic"
T 6-10
T 6-10
Machine vision learning summary
【STL】Map &unordered_map
【sklearn】数据预处理
Create and delete databases using databases
Pointer learning diary (IV) use structure and pointer (linked list)






![Embedded system transplantation [2] - Construction of cross development environment](/img/96/8d209c04e41675fc0efaa872c35615.png)


