⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 models.c

📁 嵌入式GUI OpenGL源代码。OpenGL是嵌入式开发中常用的一种GUI系统。
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************/
void store_uarm_SL(void)
{
  glPushMatrix();
  glScalef(ARM_GIRTH, UPPER_ARM_SIZE, ARM_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void store_larm_SL(void)
{
  glPushMatrix();
  glScalef(ARM_GIRTH, LOWER_ARM_SIZE, ARM_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void DrawTheGuy_SL(void)
{
  GLfloat head_diffuse[] =  { 0.7, 0.7, 0.0, 1.0 };
  GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  GLfloat leg_diffuse[] =   { 0.7, 0.0, 0.7, 1.0 };
  GLfloat arm_diffuse[] =   { 0.7, 0.4, 0.4, 1.0 };

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  draw_head_SL();

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  draw_torso_SL();

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  draw_leg_SL(0);
  draw_leg_SL(1);

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  draw_arm_SL(0);
  draw_arm_SL(1);

}

/**********************************************************/
void draw_head_SL(void)
{
  glPushMatrix();
  glCallList(body_lists);
  glPopMatrix();
}

/**********************************************************/
void draw_torso_SL(void)
{
  glPushMatrix();
  glCallList(body_lists+1);
  glPopMatrix();
}

/**********************************************************/
void draw_leg_SL(int which)
{
  glPushMatrix();
  if (which == 0)
    glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  /* Upper leg: rotates about the x axis only */
  glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists+2);
  glPopMatrix();

  /* Lower leg: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE)/2.0, 0.0);
  glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists+3);
  glPopMatrix();

  /* Foot: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LEG_GIRTH)/2.0, 0.0);
  glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists+4);
  glPopMatrix();

  glPopMatrix();
}
 
/*********************************************************************/
void draw_arm_SL(int which)
{
  int arm_which;

  if (which == 1)
    arm_which = 1;
  else arm_which = 0;

  glPushMatrix();
  glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  if (which == 0)
    glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  /* Upper leg: rotates about the x axis only */
  glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists+5);
  glPopMatrix();

  /* Lower leg: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_ARM_SIZE+LOWER_ARM_SIZE)/2.0, 0.0);
  glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists+6);
  glPopMatrix();

  glPopMatrix();
}
 


GLUquadricObj *quadObj2;
GLuint body_lists2;

/**************************************************************/
void StoreTheGuy_SL2(void)
{
  quadObj2 = gluNewQuadric();

  body_lists2 = glGenLists(NUM_BODY_PARTS);

  glNewList(body_lists2, GL_COMPILE);
  store_head_SL2();
  glEndList();

  glNewList(body_lists2+1, GL_COMPILE);
  store_torso_SL2();
  glEndList();

  glNewList(body_lists2+2, GL_COMPILE);
  store_uleg_SL2();
  glEndList();

  glNewList(body_lists2+3, GL_COMPILE);
  store_lleg_SL2();
  glEndList();

  glNewList(body_lists2+4, GL_COMPILE);
  store_foot_SL2();
  glEndList();

  glNewList(body_lists2+5, GL_COMPILE);
  store_uarm_SL2();
  glEndList();

  glNewList(body_lists2+6, GL_COMPILE);
  store_larm_SL2();
  glEndList();

}

/**********************************************************/
void store_head_SL2(void)
{ 
  glPushMatrix();
  glTranslatef(0.0, TORSO_HEIGHT+HEAD_SIZE, 0.0);
  glScalef(HEAD_SIZE, HEAD_SIZE, UPPER_LEG_GIRTH);
  glutSolidSphere(1.0, SLICES, STACKS);
  glPopMatrix();
}

/**********************************************************/
void store_torso_SL2(void)
{
  glPushMatrix();
  glScalef(TORSO_WIDTH, TORSO_HEIGHT, UPPER_LEG_GIRTH);
  glRotatef(-90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, TORSO_TAPER, 1.0, 1.0, SLICES, STACKS);
  glPopMatrix();
}

/**************************************************************/
void store_uleg_SL2(void)
{
  glPushMatrix();
  glTranslatef(0.0, -(HIP_JOINT_SIZE+UPPER_LEG_SIZE), 0.0);
  glutSolidSphere(KNEE_JOINT_SIZE, SLICES, STACKS);
  glPopMatrix();
  glTranslatef(0.0, -HIP_JOINT_SIZE, 0.0);
  glutSolidSphere(HIP_JOINT_SIZE, SLICES, STACKS);
  glPushMatrix();
  glScalef(UPPER_LEG_GIRTH, UPPER_LEG_SIZE, UPPER_LEG_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, 1.0, UPPER_LEG_TAPER, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void store_lleg_SL2(void)
{
  glPushMatrix();
  glScalef(LOWER_LEG_GIRTH, LOWER_LEG_SIZE, LOWER_LEG_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, 1.0, LOWER_LEG_TAPER, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void store_foot_SL2(void)
{
  glPushMatrix();
  glTranslatef(0.0, 0.0, -FOOT_SIZE/2.0);
  glScalef(LOWER_LEG_GIRTH, LOWER_LEG_GIRTH, FOOT_SIZE);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, 1.0, 1.0, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void store_uarm_SL2(void)
{
  glPushMatrix();
  glTranslatef(0.0, -(SHOULDER_JOINT_SIZE+UPPER_ARM_SIZE), 0.0);
  glutSolidSphere(ELBOW_JOINT_SIZE, SLICES, STACKS);
  glPopMatrix();
  glTranslatef(0.0, -SHOULDER_JOINT_SIZE, 0.0);
  glutSolidSphere(SHOULDER_JOINT_SIZE, SLICES, STACKS);
  glPushMatrix();
  glScalef(UPPER_ARM_GIRTH, UPPER_ARM_SIZE, UPPER_ARM_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, 1.0, UPPER_ARM_TAPER, 1.0, SLICES, STACKS);
  glPopMatrix();
}
  
/**************************************************************/
void store_larm_SL2(void)
{
  glPushMatrix();
  glScalef(LOWER_ARM_GIRTH, LOWER_ARM_SIZE, LOWER_ARM_GIRTH);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  gluCylinder(quadObj2, 1.0, LOWER_ARM_TAPER, 1.0, SLICES, STACKS);
  glPopMatrix();
}

/**************************************************************/
void DrawTheGuy_SL2(void)
{
  GLfloat head_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  GLfloat leg_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  GLfloat arm_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  draw_head_SL2();

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  draw_torso_SL2();

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  draw_leg_SL2(0);
  draw_leg_SL2(1);

  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  draw_arm_SL2(0);
  draw_arm_SL2(1);
 
}

/**********************************************************/
void draw_head_SL2(void)
{
  glPushMatrix();
  glCallList(body_lists2);
  glPopMatrix();
}

/**********************************************************/
void draw_torso_SL2(void)
{
  glPushMatrix();
  glCallList(body_lists2+1);
  glPopMatrix();
}

/**********************************************************/
void draw_leg_SL2(int which)
{
  glPushMatrix();
  if (which == 0)
    glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  /* UPPER leg: rotates about the x axis only */
  glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists2+2);
  glPopMatrix();

  /* LOWER leg: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_LEG_SIZE+KNEE_JOINT_SIZE), 0.0);
  glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists2+3);
  glPopMatrix();

  /* Foot: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LOWER_LEG_GIRTH)/2.0, 0.0);
  glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists2+4);
  glPopMatrix();

  glPopMatrix();
}
 
/*********************************************************************/
void draw_arm_SL2(int which)
{
  int arm_which;

  if (which == 1)
    arm_which = 1;
  else arm_which = 0;

  glPushMatrix();
  glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  if (which == 0)
    glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  /* UPPER leg: rotates about the x axis only */
  glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists2+5);
  glPopMatrix();

  /* LOWER leg: rotates about the x axis only */
  glTranslatef(0.0, -(UPPER_ARM_SIZE+ELBOW_JOINT_SIZE), 0.0);
  glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  glPushMatrix();
  glCallList(body_lists2+6);
  glPopMatrix();

  glPopMatrix();
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -