可旋转三维机器人机械手臂

  • j0_300183
    了解作者
  • 2.2KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-21 02:43
    上传日期
机器人手臂,底盘、上臂和下臂均采用圆柱体 设计合适的交互手段控制三个部件的独立旋转。
robot.rar
  • robot.c
    7.3KB
内容介绍
#include <GL/glut.h> #define BASE_HEIGHT 1.5 #define BASE_BOTTOM_RADIUS 1.0 #define BASE_UP_RADIUS 0.6 #define LOWER_ARM_HEIGHT 3.0 #define LOWER_ARM_RADIUS 0.5 #define UPPER_ARM_HEIGHT 3.5 #define UPPER_ARM_RADIUS 0.3 #define LOWER_JOINT_RADIUS 0.6 #define UPPER_JOINT_RADIUS 0.5 typedef float point[3]; static GLfloat theta[] = {0.0,0.0,0.0}; static GLfloat theta1[] = {0.0,0.0,0.0}; static GLfloat theta2[] = {0.0,0.0,0.0}; static GLint axis = 0; GLUquadricObj *p1; /* pointer to quadric object */ GLUquadricObj *p2; /* pointer to quadric object */ GLUquadricObj *p3; /* pointer to quadric object */ GLUquadricObj *m1; /* pointer to quadric object */ GLUquadricObj *m2; /* pointer to quadric object */ static float light_ambient[] = {0.1,0.1,0.1,1.0}; static float light_diffuse[] = {0.5,1.0,1.0,1.0}; static float light_position[] = {90.0,90.0,150.0,0.0}; static float light_specular[] = {1.0,1.0,1.0,1.0}; static float front_mat_shininess[] = {60.0}; static float front_mat_specular[] = {0.2,0.2,0.2,1.0}; static float front_mat_diffuse[] = {0.5,0.5,0.28,1.0}; static float back_mat_shininess[] = {60.0}; static float back_mat_specular[] = {0.5,0.5,0.2,1.0}; static float back_mat_diffuse[] = {1.0,0.9,0.2,1.0}; static float Imodel_ambient[] = {1.0,1.0,1.0,1.0}; static float Imodel_twoside[] = {GL_TRUE}; static float Imodel_oneside[] = {GL_FALSE}; /* Define the three parts */ /* Note use of push/pop to return modelview matrix to its state before functions were entered and use rotation, translation, and scaling to create instances of symbols (cube and cylinder */ void base() { glPushMatrix(); /* rotate cylinder to align with y axis */ //glColor3f(1.0, 0.0, 0.0); glRotatef(-90.0, 1.0, 0.0, 0.0); /* cyliner aligned with z axis, render with 5 slices for base and 5 along length */ gluCylinder(p1, BASE_BOTTOM_RADIUS, BASE_UP_RADIUS, BASE_HEIGHT, 120, 120); glPopMatrix(); } void upper_arm() { glPushMatrix(); glColor3f(0.0, 1.0, 0.0); glRotatef(-90.0, 1.0, 0.0, 0.0); gluCylinder(p2, UPPER_ARM_RADIUS, UPPER_ARM_RADIUS, UPPER_ARM_HEIGHT, 120, 120); glPopMatrix(); } void lower_arm() { glColor3f(0.0, 0.0, 1.0); glPushMatrix(); glRotatef(-90.0, 1.0, 0.0, 0.0); gluCylinder(p2, LOWER_ARM_RADIUS, LOWER_ARM_RADIUS, LOWER_ARM_HEIGHT, 120, 120); glPopMatrix(); } void lower_joint() { glColor3f(0.0, 0.0, 1.0); glPushMatrix(); glRotatef(-90.0, 1.0, 0.0, 0.0); gluSphere(m1,LOWER_JOINT_RADIUS,120.0,120.0); glPopMatrix(); } void upper_joint() { glColor3f(0.0, 1.0, 0.0); glPushMatrix(); glRotatef(-90.0, 1.0, 0.0, 0.0); gluSphere(m2,UPPER_JOINT_RADIUS,120.0,120.0); glPopMatrix(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glRotatef(theta[0], 0.0, 1.0, 0.0); glRotatef(theta1[0], 0.0, 0.0, 1.0); glRotatef(theta2[0], 1.0, 0.0, 0.0); base(); glTranslatef(0.0, BASE_HEIGHT, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta1[1], 0.0, 0.0, 1.0); glRotatef(theta2[1], 1.0, 0.0, 0.0); lower_joint(); glTranslatef(0.0, LOWER_JOINT_RADIUS, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta1[1], 0.0, 0.0, 1.0); glRotatef(theta2[1], 1.0, 0.0, 0.0); lower_arm(); glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0); glRotatef(theta[2], 0.0, 1.0, 0.0); glRotatef(theta1[2], 0.0, 0.0, 1.0); glRotatef(theta2[2], 1.0, 0.0, 0.0); upper_joint(); glTranslatef(0.0, UPPER_JOINT_RADIUS, 0.0); glRotatef(theta[2], 0.0, 1.0, 0.0); glRotatef(theta1[2], 0.0, 0.0, 1.0); glRotatef(theta2[2], 1.0, 0.0, 0.0); upper_arm(); glFlush(); glutSwapBuffers(); } void keys(unsigned char key, int x, int y) { /* Use x, X, y, Y, z, and Z keys to move viewer */ if(key == 'y'||key == 'Y') { theta[axis] += 1.0; if( theta[axis] > 360.0 ) theta[axis] -= 360.0; } if(key == 'Z'||key == 'z') { theta1[axis] += 1.0; if( theta1[axis] < 360.0 ) theta1[axis] -= 360.0; } if(key=='x'||key=='X') { theta2[axis]+=1.0; if( theta2[axis] < 360.0 ) theta2[axis] -= 360.0; if( theta2[axis] < 360.0 ) theta2[axis] -= 360.0; } display(); } void menu(int id) { /* menu selects which angle to change or whether to quit */ if(id == 1 ) axis=0; if(id == 2) axis=1; if(id == 3 ) axis=2; if(id ==4 ) { exit(0); gluDeleteQuadric(p1); gluDeleteQuadric(p2); gluDeleteQuadric(p3); gluDeleteQuadric(m1); gluDeleteQuadric(m2); } } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho(-10.0, 10.0, -10.0 * (GLfloat) h / (GLfloat) w, 15.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0); else glOrtho(-10.0 * (GLfloat) w / (GLfloat) h, 10.0 * (GLfloat) w / (GLfloat) h, -10.0, 15.0, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myinit() { /*设置背景色*/ glClearColor(0.0,0.0,0.0,0.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); /*设置光照*/ glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); /*设置材质*/ glMaterialfv(GL_FRONT,GL_DIFFUSE,front_mat_diffuse); glMaterialfv(GL_FRONT,GL_SPECULAR,front_mat_specular); glMaterialfv(GL_FRONT,GL_SHININESS,front_mat_shininess); glMaterialfv(GL_BACK,GL_DIFFUSE,back_mat_diffuse); glMaterialfv(GL_BACK,GL_SPECULAR,back_mat_specular); glMaterialfv(GL_BACK,GL_SHININESS,back_mat_shininess); /*设置光照模型参数*/ glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Imodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,Imodel_twoside); /*激活关照*/ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glShadeModel(GL_SMOOTH); p1=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(p1,GLU_FILL); gluQuadricNormals(p1,GL_FLAT); gluQuadricOrientation(p1,GLU_INSIDE); gluQuadricTexture(p1,GL_TRUE); p2=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(p2,GLU_FILL); gluQuadricNormals(p2,GL_FLAT); gluQuadricOrientation(p2,GLU_INSIDE); gluQuadricTexture(p2,GL_TRUE); p3=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(p3,GLU_FILL); gluQuadricNormals(p3,GL_FLAT); gluQuadricOrientation(p3,GLU_INSIDE); gluQuadricTexture(p3,GL_TRUE); m1=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(m1,GLU_FILL); gluQuadricNormals(m1,GL_FLAT); gluQuadricOrientation(m1,GLU_INSIDE); gluQuadricTexture(m1,GL_TRUE); m2=gluNewQuadric(); /* allocate quadric object */ gluQuadricDrawStyle(m2,GLU_FILL); gluQuadricNormals(m2,GL_FLAT); gluQuadricOrientation(m2,GLU_INSIDE); gluQuadricTexture(m2,GL_TRUE); } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutCreateWindow("robot"); myinit(); glutReshapeFunc(myReshape); glutDisplayFunc(display); glutKeyboardFunc(keys); glutCreateMenu(menu); glutAddMenuEntry("base", 1); glutAddMenuEntry("lower arm", 2); glutAddMenuEntry("upper arm", 3); glutAddMenuEntry("quit", 4); glutAttachMenu(GLUT_LEFT_BUTTON); glutMainLoop(); }
评论
    相关推荐
    • 拖放交互
      拖放交互
    • 交互设计必备交互文档
      产品设计必备交互文档,产品需求必备模板,
    • vcflash交互
      vcflash交互参考,让vc界面更漂亮
    • 人机交互课件
      重庆大学人机交互课程课件 人机交互、人机互动(英文:Human–Computer Interaction或Human–Machine Interaction,简称HCI或HMI),是一门研究系统与用户之间的交互关系的学问。系统可以是各种各样的机器,也可以是...
    • 人机交互体感交互
      kinect人机交互体感交互游戏图片翻页
    • 交互工具啊
      交互工具啊
    • 交互式绘图
      实现的是鼠标交互式绘制直线,矩形,文本及不规则图形和图形的区域填充。
    • VirTools交互
      绝对是初学者的好的作品 含有源文件.nmo 知识点有摄像机,数组,按钮等