鱼C论坛

 找回密码
 立即注册
查看: 3862|回复: 0

谁能帮忙改一下这个小程序,并加一些函数的注释,谢谢了,十万火急啊

[复制链接]
发表于 2012-12-6 14:59:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
将最后蓝色部分的长度缩减一半,并且将函数功能做上注释


/*
* robot.c
* This program shows how to composite modeling transformations
* to draw translated and rotated hierarchical models.
* Interaction:  pressing the s and e keys (shoulder and elbow)
* alters the rotation of the robot arm.
*/
#include <GL/glut.h>
#include <stdlib.h>
static int shoulder = 0, elbow = 0; hand=0;
void init(void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
    glColor3f(0.0,1.0,0.0);
glBegin(GL_LINES);
  glVertex2f(-3,0);
  glVertex2f(3,0);
  glVertex2f(0,3);
  glVertex2f(0,-3);
glEnd( );

glPushMatrix();
  glTranslatef (-1.0, 0.0, 0.0);
  glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
  glTranslatef (1.0, 0.0, 0.0);
  
  glPushMatrix();
   glScalef (2.0, 0.4, 1.0);
   glColor3f(1.0,1.0,0.0);
   glutWireCube (1.0);
  glPopMatrix();
  glTranslatef (1.0, 0.0, 0.0);
  glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
  glTranslatef (1.0, 0.0, 0.0);
  glPushMatrix();
   glScalef (2.0, 0.4, 1.0);
   glColor3f(1.0,0.0,1.0);
   glutWireCube (1.0);
  glPopMatrix();
  
  glTranslatef (1.0, 0.0, 0.0);
  glRotatef ((GLfloat) hand, 0.0, 0.0, 1.0);
  glTranslatef (1.0, 0.0, 0.0);
  glPushMatrix();
   glScalef (2.0, 0.4, 1.0);
   glColor3f(0.0,0.0,1.0);
   glutWireCube (1.0);
  glPopMatrix();
  
   glPopMatrix();
  
   glutSwapBuffers();
}
void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(100.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef (0.0, 0.0, -5.0);
}
void keyboard (unsigned char key, int x, int y)
{
   switch (key) {
      case 's':
         shoulder = (shoulder + 5) % 360;
         glutPostRedisplay();
         break;
      case 'S':
         shoulder = (shoulder - 5) % 360;
         glutPostRedisplay();
         break;
      case 'e':
         elbow = (elbow + 5) % 360;
         glutPostRedisplay();
         break;
      case 'E':
         elbow = (elbow - 5) % 360;
         glutPostRedisplay();
         break;
      case 'h':
         hand = (hand + 5) % 360;
         glutPostRedisplay();
         break;
      case 'H':
         hand = (hand - 5) % 360;
         glutPostRedisplay();
         break;
      case 27:
         exit(0);
         break;
      default:
         break;
   }
}
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowSize (500, 500);
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutMainLoop();
   return 0;
}

小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-9 18:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表