当前位置:网站首页>OpenGL simulates the process of a ball falling to the ground and bouncing up in real life. Draw a ball on the screen, and the ball will fall from top to bottom, hit the ground and bounce up again.
OpenGL simulates the process of a ball falling to the ground and bouncing up in real life. Draw a ball on the screen, and the ball will fall from top to bottom, hit the ground and bounce up again.
2022-07-24 05:31:00 【Mo xiaodai ^o^】
// Simulate real life , The process of the ball falling to the ground and bouncing up , Draw a ball on the screen , The ball fell from the top , Hit the ground , Play again .
#define GLUT_DISABLE_ATEXIT_HACK
#include <gl/glut.h>
float y=1.5f;
float dy=-0.4f;
// initialization OpenGL
void DrawCube()
{
// Set the clear screen color to black
glClearColor(0.0f,0.0f,0.0f,0.0f);
// Clear color buffer and depth buffer
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);
}
// The main drawing process
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);// Clear color cache
glLoadIdentity();
glTranslatef(0,0,-5);
glColor3f(1.0,0,0);
DrawCube();
glFlush();
}
// Call when the window changes size
void reshape(int w, int h){
glViewport(0, 0, w, h);// Set up the viewport
glMatrixMode(GL_PROJECTION);// Set the current projection transformation mode
glLoadIdentity();// Replace the current transformation matrix with the identity matrix
gluPerspective(100, (float)w/h, 3, 100.0);// Set the orthographic projection body
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");// Set the window title
init();// initialization OpenGL
glutDisplayFunc(display);// Set display callback function
glutReshapeFunc(reshape);// Set up reshape Callback function
glutTimerFunc(100,TimerFunction, 1);
glutMainLoop();// Enter the main loop
}
边栏推荐
- special effects - 鼠标点击,出现随机设置的文字
- 关键字_01return
- Learn AI linear regression from Li Mu. The code implementation from scratch is super detailed
- 9.使用网格技术,在屏幕上绘制一个五角形。
- Redis的使用
- Sorting out some common server instructions and some binding instructions in csgo
- mapboxgl + geoserver 配置本地地图教程
- special effects - 鼠标移动,出现星星拖尾
- special effects - 鼠标移动,出现泡泡拖尾
- T 11-20
猜你喜欢
随机推荐
函数多种类型
Summary of data types
关于作为行业人从业人员的一点思考
Promise_async与await
VS 调试
JS - 数值处理(取整、四舍五入、随机数等)
c语言中的变量与常量
力扣、牛客网->链表相关题目(篇一)(c语言)
Pure white tutorial using Druid database connection pool in idea
输入若干数据,找出最大值输出。(键盘和文件读取)
谈谈对未来的想法
按钮 渐变
special effects - 蜘蛛网背景特效
深度剖析数据在内存中的存储
Install pytoch+anaconda+cuda+cudnn
T 11-20
模板数据的二次加工
ros启动非本机节点
Scikit learn notes
px和em和rem区别









