openGL画运动的自行车
来源:互联网 发布:始作俑者其无后乎 甄嬛 编辑:程序博客网 时间:2024/04/30 06:51
#include <windows.h>
#include <gl/glut.h>
GLuint Wheel1;//前
GLuint Wheel2;//中
GLuint Wheel3;//后
GLuint Frame;
GLuint Frame1;//转动的踏板 前
GLuint Frame2;//转动的踏板 后
static GLfloat spin = 0.0;
void spinDisplay(void)
{
spin = spin + 0.3;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void Initial(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
Wheel1 = glGenLists(1); //前轮
glNewList(Wheel1, GL_COMPILE);
glColor3f(0.0, 0.0, 0.0);
glutSolidTorus(0.8, 20.0, 15, 50); //线条粗细,半径,
glutSolidTorus(0.8, 5.0, 15, 50);
glutSolidTorus(0.8, 1.0, 15, 50);
glBegin(GL_LINES); //前轮连杆
glVertex2i(0,0);
glVertex2i(0,20);
glEnd();
glEndList();
Wheel2 = glGenLists(1); //后齿轮
glNewList(Wheel2, GL_COMPILE);
glColor3f(0.0, 0.0, 0.0);
glutSolidTorus(0.8, 20.0, 15, 50);
glutSolidTorus(0.8, 5.0, 15, 50);
glutSolidTorus(0.8, 1.0, 15, 50);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(0,20);
glEnd();
glEndList();
Wheel3 = glGenLists(1); //中间齿轮
glNewList(Wheel3, GL_COMPILE);
glColor3f(0.0, 1.0, 0.0);
glutSolidTorus(0.6, 7.0, 15, 50);
glEndList();
Frame = glGenLists(1);
glNewList(Frame, GL_COMPILE); //自行车框架
glColor3f(1.0, 0.5, 0.0);
glLineWidth(5);
glTranslatef(-20.0, 20.0, 0.0);
glBegin(GL_LINES); //三角形支架
glVertex2i(-10,5);
glVertex2i(50,5);
glEnd();
glBegin(GL_LINES);
glVertex2i(-10,5);
glVertex2i(20,-35);
glEnd();
glBegin(GL_LINES);
glVertex2i(20,-35);
glVertex2i(50,5);
glEnd();
glBegin(GL_LINES); //前轮连杆
glVertex2i(-6,20);
glVertex2i(-20,-35);
glEnd();
glBegin(GL_LINES); //车把
glVertex2i(-15,21);
glVertex2i(3,19);
glEnd();
glBegin(GL_LINES);
glVertex2i(-15,21);
glVertex2i(-8,25);
glEnd();
glBegin(GL_LINES);
glVertex2i(3,19);
glVertex2i(9,23);
glEnd();
glBegin(GL_LINES); //后轮连杆
glVertex2i(50,5);
glVertex2i(64,-35);
glEnd();
glBegin(GL_LINES);
glVertex2i(50,5);
glVertex2i(50,6 );
glEnd();
glColor3f(0.5, 0.5, 0.5);
glLineWidth(2);
glBegin(GL_LINES); //链条(上)
glVertex2i(20,-28);
glVertex2i(64,-30);
glEnd();
glBegin(GL_LINES); //链条 (下)
glVertex2i(20,-42);
glVertex2i(64,-40);
glEnd();
glColor3f(1.0, 0.5, 0.5);
glLineWidth(3);
glBegin(GL_LINE_LOOP); //车座
glVertex2i(45,10);
glVertex2i(44,9);
glVertex2i(44,8);
glVertex2i(55,5);
glVertex2i(55,6);
glVertex2i(55,7);
glVertex2i(54,12);
glVertex2i(53,13);
glEnd();
glEndList();
Frame1 = glGenLists(1);//前踏板
glNewList(Frame1, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(5,-10);
glEnd();
glBegin(GL_LINES);
glVertex2i(5,-10);
glVertex2i(2,-13);
glEnd();
glEndList();
Frame2 = glGenLists(1);//后踏板
glNewList(Frame2, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(-5,10);
glEnd();
glBegin(GL_LINES);
glVertex2i(-5,10);
glVertex2i(-2,13);
glEnd();
glEndList();
}
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (-70.0f, 70.0f, -70.0f, 70.0f);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//后踏板
glTranslatef(20.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Frame2);
glPopMatrix();
glPushMatrix();//前轮
glTranslatef(-20.0, -35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel1);
glPopMatrix();
glPushMatrix();//后轮
glTranslatef(64.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel2);
glPopMatrix();
glPushMatrix();//中间齿轮
glTranslatef(18.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel3);
glPopMatrix();
glPushMatrix();//前踏板
glTranslatef(20.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Frame1);
glPopMatrix();
//支架显示列表 不动
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, 0.0);
glCallList(Frame);
glFlush();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(200,200);
glutCreateWindow("自行车");
glutIdleFunc(spinDisplay);
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize);
Initial();
glutMainLoop();
return 0;
}
#include <gl/glut.h>
GLuint Wheel1;//前
GLuint Wheel2;//中
GLuint Wheel3;//后
GLuint Frame;
GLuint Frame1;//转动的踏板 前
GLuint Frame2;//转动的踏板 后
static GLfloat spin = 0.0;
void spinDisplay(void)
{
spin = spin + 0.3;
if (spin > 360.0)
spin = spin - 360.0;
glutPostRedisplay();
}
void Initial(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
Wheel1 = glGenLists(1); //前轮
glNewList(Wheel1, GL_COMPILE);
glColor3f(0.0, 0.0, 0.0);
glutSolidTorus(0.8, 20.0, 15, 50); //线条粗细,半径,
glutSolidTorus(0.8, 5.0, 15, 50);
glutSolidTorus(0.8, 1.0, 15, 50);
glBegin(GL_LINES); //前轮连杆
glVertex2i(0,0);
glVertex2i(0,20);
glEnd();
glEndList();
Wheel2 = glGenLists(1); //后齿轮
glNewList(Wheel2, GL_COMPILE);
glColor3f(0.0, 0.0, 0.0);
glutSolidTorus(0.8, 20.0, 15, 50);
glutSolidTorus(0.8, 5.0, 15, 50);
glutSolidTorus(0.8, 1.0, 15, 50);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(0,20);
glEnd();
glEndList();
Wheel3 = glGenLists(1); //中间齿轮
glNewList(Wheel3, GL_COMPILE);
glColor3f(0.0, 1.0, 0.0);
glutSolidTorus(0.6, 7.0, 15, 50);
glEndList();
Frame = glGenLists(1);
glNewList(Frame, GL_COMPILE); //自行车框架
glColor3f(1.0, 0.5, 0.0);
glLineWidth(5);
glTranslatef(-20.0, 20.0, 0.0);
glBegin(GL_LINES); //三角形支架
glVertex2i(-10,5);
glVertex2i(50,5);
glEnd();
glBegin(GL_LINES);
glVertex2i(-10,5);
glVertex2i(20,-35);
glEnd();
glBegin(GL_LINES);
glVertex2i(20,-35);
glVertex2i(50,5);
glEnd();
glBegin(GL_LINES); //前轮连杆
glVertex2i(-6,20);
glVertex2i(-20,-35);
glEnd();
glBegin(GL_LINES); //车把
glVertex2i(-15,21);
glVertex2i(3,19);
glEnd();
glBegin(GL_LINES);
glVertex2i(-15,21);
glVertex2i(-8,25);
glEnd();
glBegin(GL_LINES);
glVertex2i(3,19);
glVertex2i(9,23);
glEnd();
glBegin(GL_LINES); //后轮连杆
glVertex2i(50,5);
glVertex2i(64,-35);
glEnd();
glBegin(GL_LINES);
glVertex2i(50,5);
glVertex2i(50,6 );
glEnd();
glColor3f(0.5, 0.5, 0.5);
glLineWidth(2);
glBegin(GL_LINES); //链条(上)
glVertex2i(20,-28);
glVertex2i(64,-30);
glEnd();
glBegin(GL_LINES); //链条 (下)
glVertex2i(20,-42);
glVertex2i(64,-40);
glEnd();
glColor3f(1.0, 0.5, 0.5);
glLineWidth(3);
glBegin(GL_LINE_LOOP); //车座
glVertex2i(45,10);
glVertex2i(44,9);
glVertex2i(44,8);
glVertex2i(55,5);
glVertex2i(55,6);
glVertex2i(55,7);
glVertex2i(54,12);
glVertex2i(53,13);
glEnd();
glEndList();
Frame1 = glGenLists(1);//前踏板
glNewList(Frame1, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(5,-10);
glEnd();
glBegin(GL_LINES);
glVertex2i(5,-10);
glVertex2i(2,-13);
glEnd();
glEndList();
Frame2 = glGenLists(1);//后踏板
glNewList(Frame2, GL_COMPILE);
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_LINES);
glVertex2i(0,0);
glVertex2i(-5,10);
glEnd();
glBegin(GL_LINES);
glVertex2i(-5,10);
glVertex2i(-2,13);
glEnd();
glEndList();
}
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (-70.0f, 70.0f, -70.0f, 70.0f);
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();//后踏板
glTranslatef(20.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Frame2);
glPopMatrix();
glPushMatrix();//前轮
glTranslatef(-20.0, -35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel1);
glPopMatrix();
glPushMatrix();//后轮
glTranslatef(64.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel2);
glPopMatrix();
glPushMatrix();//中间齿轮
glTranslatef(18.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Wheel3);
glPopMatrix();
glPushMatrix();//前踏板
glTranslatef(20.0,-35.0, 0.0);
glRotatef(spin, 0.0, 0.0, 1.0);
glCallList(Frame1);
glPopMatrix();
//支架显示列表 不动
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, 0.0);
glCallList(Frame);
glFlush();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutInitWindowPosition(200,200);
glutCreateWindow("自行车");
glutIdleFunc(spinDisplay);
glutDisplayFunc(Display);
glutReshapeFunc(ChangeSize);
Initial();
glutMainLoop();
return 0;
}
0 0
- openGL画运动的自行车
- 自行车运动的好处
- MATLAB-运动的自行车
- 自行车运动FAQ(针对国内对自行车运动认识的误区)
- 行者无疆——自行车,危险的运动
- 使用opengl画的一个运动的机器人
- OpenGL超级宝典之chapter 2 运动的图形(move)
- 祭奠:我的自行车!
- 由自行车想到的......
- 骑自行车的注意事项
- 会飞的自行车
- 远逝的自行车
- 可折叠成小托车的自行车
- 趴着骑的自行车
- 自行车
- 自行车
- 自行车
- 自行车
- Sliding menu 框架的应用
- iOS开发-自动布局之autoresizingMask使用详解(Storyboard&Code)
- c++实验3-个人所得税计算器
- laravel 学习笔记1
- Java中的字符串类
- openGL画运动的自行车
- $(document).ready()方法, onload事件 , $(window).load()方法
- error C4335: 检测到 Mac 文件格式: 请将源文件转换为 DOS 格式或 UNIX 格式f
- 读取文件夹所有文件并保存文件名至指定文件
- 事务的一些基本概念
- Side Menu侧边栏动画效果
- 主讲spring mvc 在web.xml中的配置
- Appliation Loader上传App 莫名其妙的错误 The CFBundleExecutable of two bundles may not point to the same file.
- C语言实现推箱子小游戏