Esempio n. 1
0
void drawSolar() {

//for light
glEnable(GL_LIGHT0);

    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

	glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);



// Draw Sun : color yellow
    glColor3f(1.0f, 1.0f, 0.0f);
	glTranslatef(0.0f ,0.75f, 0.0f);
	glutSolidSphere(3.0f,100,100);
    glEnd();




glRotatef(angle, 0.0f, 1.0f, 0.0f);



//Mercury :  Black Gray
    glColor3f(0.9f,0.9f,0.9f);
	glTranslatef(-14 ,0.60, 0.0f);
	glutSolidSphere(0.75f,60,60);

//Venus : drak yellow
 glColor3f(0.9f, 0.7f, 0.0f);

	glTranslatef(7,0.0f, 4.0f);
	glutSolidSphere(0.60f,40,40);


//Earth : blue
    glColor3f(0.0f, 0.5f, 1.0f);
	glTranslatef(17,0.0f, 8.0f);
	glutSolidSphere(1.5f,40,40);

	//Mars : dark white
   glColor3f(0.9f, 0.9f, 0.9f);
	glTranslatef(12,0.0f, -15.0f);
	glutSolidSphere(0.75f,40,40);


//drak yellow :  Jupiter
	  glColor3f(0.9f, 0.5f, 0.0f);
	glTranslatef(14,0.0f, 10.0f);
	glutSolidSphere(1.9f,40,40);



glEnd();

	angle+=0.1f;
	glutSwapBuffers();
}
Esempio n. 2
0
/*!*****************************************************************************
 *******************************************************************************
\note  myDrawGLElement
\date  August 7, 1992
   
\remarks 

        draws a GL element of a particular length in z direction

 *******************************************************************************
 Function Parameters: [in]=input,[out]=output

 \param[in]     num   : ID number of element (just for info)
 \param[in]     length: length of element
 \param[in]     flag  : draw joint element (yes, not)


 ******************************************************************************/
static void  
myDrawGLElement(int num, double length, int flag)

{
		
		
  static int firsttime = TRUE;
  double width=0.03;
  double head_width = 0.3;
  double hand_width = 0.07;
  double foot_width = 0.1;
  double torso_width = 0.3;
  double belly_width = 0.25;
  double thumb_width = 0.02;
  double shoulder_width  = 0.4;

  static int pelvis,b_tr,b_taa,b_tfe;
  static int l_haa, l_hfe, l_hfr, l_kfe, l_ar, l_afe, l_aaa;
  static int r_haa, r_hfe, r_hfr, r_kfe, r_ar, r_afe, r_aaa;
  static int b_hn, b_ht, b_hr;
  static int head,left_eye,right_eye;
  static int r_sfe, r_saa, r_hr, r_eb, r_wr, r_wfe, r_waa;
  static int l_sfe, l_saa, l_hr, l_eb, l_wr, l_wfe, l_waa;


  GLfloat  gray[4]={(float)0.8,(float)0.8,(float)0.8,(float)opacity};
  GLfloat  green[4]={(float)0.1,(float)0.5,(float)0.5,(float)opacity};
  GLfloat  red[4]={(float)1.0,(float)0.25,(float)0.25,(float)opacity};
  GLfloat  blue[4]={(float)0.1,(float)0.1,(float)1.0,(float)opacity};
  GLfloat  black[4]={(float)0.,(float)0.,(float)0.0,(float)opacity};
  GLfloat  white[4]={(float)1.,(float)1.,(float)1.0,(float)opacity};
  GLfloat  yellow[4]={(float)1.0,(float)0.8,(float)0.7,(float)opacity};

  int      isphere = 10;

  if (solid)
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
  else
    glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

  if (firsttime) {
    firsttime = FALSE;

    char *lab_root;
    char  fname[300];

    lab_root = getenv("LAB_ROOT");

    sprintf(fname,"%s/hermesCore/3D/Pelvis.obj",lab_root);
    pelvis         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/B_TR.obj",lab_root);
    b_tr           = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/B_TAA.obj",lab_root);
    b_taa          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/B_TFE.obj",lab_root);
    b_tfe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HFE.obj",lab_root);
    l_hfe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HAA.obj",lab_root);
    l_haa          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HFR.obj",lab_root);
    l_hfr          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_KFE.obj",lab_root);
    l_kfe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_AR.obj",lab_root);
    l_ar          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_AFE.obj",lab_root);
    l_afe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_AAA.obj",lab_root);
    l_aaa          = displayListFromObjFileFlag(fname,0.0256,FALSE);

    sprintf(fname,"%s/hermesCore/3D/L_HFE.obj",lab_root);
    r_hfe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HAA.obj",lab_root);
    r_haa          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HFR.obj",lab_root);
    r_hfr          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_KFE.obj",lab_root);
    r_kfe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_AR.obj",lab_root);
    r_ar          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_AFE.obj",lab_root);
    r_afe          = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_AAA.obj",lab_root);
    r_aaa          = displayListFromObjFileFlag(fname,0.0256,FALSE);

    sprintf(fname,"%s/hermesCore/3D/B_HN.obj",lab_root);
    b_hn           = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/B_HT.obj",lab_root);
    b_ht           = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/B_HR.obj",lab_root);
    b_hr           = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/humanoidHeadLeftEye.obj",lab_root);
    left_eye         = displayListFromObjFile(fname,0.0256);

    sprintf(fname,"%s/hermesCore/3D/humanoidHeadRightEye.obj",lab_root);
    right_eye         = displayListFromObjFile(fname,0.0256);

    sprintf(fname,"%s/hermesCore/3D/humanoidHead.obj",lab_root);
    head         = displayListFromObjFile(fname,0.0256);

    sprintf(fname,"%s/hermesCore/3D/R_SFE.obj",lab_root);
    r_sfe        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_SAA.obj",lab_root);
    r_saa        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_HR.obj",lab_root);
    r_hr         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_EB.obj",lab_root);
    r_eb         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_WR.obj",lab_root);
    r_wr         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_WFE.obj",lab_root);
    r_wfe        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/R_WAA.obj",lab_root);
    l_waa        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_SFE.obj",lab_root);
    l_sfe        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_SAA.obj",lab_root);
    l_saa        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_HR.obj",lab_root);
    l_hr         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_EB.obj",lab_root);
    l_eb         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_WR.obj",lab_root);
    l_wr         = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_WFE.obj",lab_root);
    l_wfe        = displayListFromObjFileFlag(fname,0.0256,TRUE);

    sprintf(fname,"%s/hermesCore/3D/L_WAA.obj",lab_root);
    r_waa        = displayListFromObjFileFlag(fname,0.0256,TRUE);

  }
	
  if (flag==1 && num != 35 && num != 37) {
    glTranslated(0.0,0.0,length); 

    if (num==999) {/* the base coordinate system */
      glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
      glColor4fv(blue);
    } else if (num > 38) {
      glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
      glColor4fv(gray);
    } else {
      glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
      glColor4fv(green);
    }

    if (num == B_HN || num == B_HT) {
      if (solid)
	glutSolidSphere(0.25*width,isphere,isphere);
      else
	glutWireSphere(0.25*width,isphere,isphere);
    } else {
      if (solid)
	glutSolidSphere(0.25*width,isphere,isphere);
      else
	glutWireSphere(0.25*width,isphere,isphere);
    }
    glTranslated(0.0,0.0,-length);
  }
	

  switch (num) {

  case BASE:
    break;

  case L_SAA:   /* L_SFE */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)135.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(-0.002,-0.005,0.290);
    glCallList(l_sfe);
    break;

  case L_HR:  /* L_SAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)180.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(-0.2,-0.005,0.490);
    glCallList(l_saa);
    break;

  case L_EB: /* L_HR */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(-0.222,-0.005,0.495);
    glCallList(l_hr);
    break;

  case L_WR: /* L_EB */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(-0.223,-0.005,0.240);
    glCallList(l_eb);
    break;

  case L_WFE: /* L_WR */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(-0.223,-0.000,0.2150);
    glCallList(l_wr);
    break;


  case L_WAA: /* L_WFE */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(-0.22,-0.000,-0.017);
    glCallList(l_wfe);
    break;

  case 108:  /* L_WAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.220,-0.020,-0.017);
    glCallList(l_waa);
    break;


  case R_SAA:   /* R_SFE */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)135.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.0,-0.005,0.290);
    glCallList(r_sfe);
    break;

  case R_HR:  /* R_SAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.2,-0.005,0.490);
    glCallList(r_saa);
    break;

  case R_EB: /* R_HR */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.222,-0.005,0.490);
    glCallList(r_hr);
    break;

  case R_WR: /* R_EB */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.223,-0.005,0.2350);
    glCallList(r_eb);
    break;

  case R_WFE: /* R_WR */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)0.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.223,-0.000,0.2150);
    glCallList(r_wr);
    break;


  case R_WAA: /* R_WFE */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(0.22,-0.000,-0.017);
    glCallList(r_wfe);
    break;

  case 115:  /* R_WAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(-0.220,-0.020,-0.017);
    glCallList(r_waa);
    break;

    break;


  case B_TR: /* pelvis */

    glPushMatrix();
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    //glTranslated(0.0,0.0,0.1);
    glCallList(pelvis);
    glPopMatrix();

    // draw IMU
    glTranslated(-IMU_X_OFFSET,IMU_Y_OFFSET,0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    glColor4fv(red);
    glScaled(0.02,0.01,0.04);
    if (solid)
      glutSolidCube(1.0);
    else
      glutWireCube(1.0);


    break;

  case B_TAA: /* B_TR */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    //glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.0,0.0,0.1725);
    glCallList(b_tr);
    break;

  case B_TFE: /* B_TAA */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.0,0.0,0.1725);
    glCallList(b_taa);
    break;

  case B_HN: /* B_TFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(-0.004,-0.005,0.1725); // strange lateral offset ....
    glCallList(b_tfe);

    break;

  case L_HFE: /* L_HAA */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.09,0.0,0.0);
    glCallList(l_haa);
    break;

  case L_HFR: /* L_HFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    //glRotated((GLdouble)90.,(ppGLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.09,0.0,0.0);
    glCallList(l_hfe);
    break;

  case L_KFE: /* L_HFR */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-8.5,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(0.09,-0.06,-0.01);
    glCallList(l_hfr);
    break;

  case L_AR: /* L_KFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.404);
    glCallList(l_kfe);
    break;

  case L_AFE: /* L_AR */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.404);
    glCallList(l_ar);
    break;

  case L_AAA: /* L_AFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.784);
    glCallList(l_afe);
    break;

  case 128: /* L_AAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glScaled(MAG,MAG,1.0);
    glTranslated(0.08,0.0,-0.78);
    glCallList(l_aaa);
    break;

  case R_HFE: /* R_HAA */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.095,0.0,0.0);
    glCallList(r_haa);
    break;

  case R_HFR: /* R_HFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    //glRotated((GLdouble)90.,(ppGLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(0.09,0.0,0.0);
    glCallList(r_hfe);
    break;

  case R_KFE: /* R_HFR */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-8.5,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(0.09,-0.06,-0.01);
    glCallList(r_hfr);
    break;

  case R_AR: /* R_KFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.404);
    glCallList(r_kfe);
    break;

  case R_AFE: /* R_AR */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.404);
    glCallList(r_ar);
    break;

  case R_AAA: /* R_AFE */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glTranslated(0.09,0.0,-0.784);
    glCallList(r_afe);
    break;

  case 135: /* R_AAA */
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    //glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glScaled(MAG,MAG,1.0);
    glTranslated(-.08,0.0,-0.78);
    glCallList(r_aaa);
    break;

  case B_HT: /* B_HN */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)180.,(GLdouble)0.,(GLdouble)1.,(GLdouble)0.);
    glTranslated(-0.004,-0.006,0.56);
    glCallList(b_hn);
    break;

  case B_HR: /* B_HT */

    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    //glRotated((GLdouble)-90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)-90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(-0.004,-0.006,0.56);
    glCallList(b_ht);
    break;


  case 138: /* the head */
    
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
    glColor4fv(white);
    glRotated((GLdouble)90.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(-0.035,-0.04+.12,-0.065);
    glCallList(head);
    break;
    
  case 35: /* dummies */
  case 37: /* dummies */
    break;
   
	
  case 137: /* the right eye */
	
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)180.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(-0.072,-0.0545,0.00);
    glCallList(right_eye);

    glTranslated(0.072,0.0545,-.022);

    glPushMatrix();
    glScaled(0.02,0.02,0.001);
    glColor4fv(black);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, black);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    glTranslated(0.0,0.0,-0.001);
    glPushMatrix();
    glScaled(0.007,0.007,0.001);
    glColor4fv(white);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    glTranslated(0.0,-0.017,0.0);
    glPushMatrix();
    glScaled(0.006,0.006,0.01);
    glColor4fv(gray);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    break;

  case 139: /* the left eye */
	
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    glColor4fv(gray);
    glRotated((GLdouble)90.,(GLdouble)0.,(GLdouble)0.,(GLdouble)1.);
    glRotated((GLdouble)180.,(GLdouble)1.,(GLdouble)0.,(GLdouble)0.);
    glTranslated(0.00,-0.0545,0.0);
    glCallList(left_eye);

    glTranslated(0.0,0.0545,-0.022);

    glPushMatrix();
    glScaled(0.02,0.02,0.001);
    glColor4fv(black);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, black);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    glTranslated(0.0,0.0,-0.001);
    glPushMatrix();
    glScaled(0.007,0.007,0.001);
    glColor4fv(white);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    glTranslated(0.0,-0.017,0.0);
    glPushMatrix();
    glScaled(0.006,0.006,0.01);
    glColor4fv(gray);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
    if (solid)
      glutSolidCylinder(1.0,1.0,isphere*2,1);
    else
      glutWireCylinder(1.0,1.0,isphere*2,1);
    glPopMatrix();

    break;

 case 129: /* dummies of feet */
 case 130:
 case 131:
 case 132:
 case 133:
 case 134:
 case 122:
 case 123:
 case 124:
 case 125:
  case 126:
 case 127:
	
   /*
    glScaled(width/2.,width/2.,length);
    glTranslated(0.0,0.0,0.5);
    glColor4fv(gray);
    if (solid)
      glutSolidCube(1.0);
    else
      glutWireCube(1.0);
   */			
    break;

  case 152:
  case 155:
  case 158:
  case 161:
  case 164:
  case 166:
  case 169:
  case 172:
  case 175:
  case 178:
    glPushMatrix();
    glTranslated(0.0,0.0,length);
    if (solid)
      glutSolidSphere(0.25*width,isphere,isphere);
    else
      glutWireSphere(0.25*width,isphere,isphere);
    glPopMatrix();

  default:
	
    glScaled(width/4,width/4,length);
    glColor4fv(gray);

    if (solid)
      glutSolidCylinder(1.0,1.0,isphere,1);
    else
      glutWireCylinder(1.0,1.0,isphere,1);

  }
}
Esempio n. 3
0
/* Focntion de dessin */
void DrawGLScene()
{
// Effacement du buffer de couleur et de profondeur
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		
  glLoadIdentity();		

// Paramètrage de l'éclairage
  glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
  glLightfv(GL_LIGHT0,GL_POSITION,light_position);


//////////////////////////////////////////////////
// camera

//  gluLookAt(0.0,5.0,30.0,0.0,5.0,0.0,0.0,1.0,0.0); // premère partie : robot seul

  gluLookAt(cam_pos_x,10.0,cam_pos_z,cam_look_x,5.0,cam_look_z,0.0,1.0,0.0); 

//////////////////////////////////////////////////
// Compilation des listes

  Make_CallListes();

//////////////////////////////////////////////////
// sol  

  glPushMatrix();
  ground();
  glPopMatrix();


//////////////////////////////////////////////////
// Bras articulé

	
/*Mettre les degré de liberté au fur et a mesure des objets*/
/*
// base
glTranslatef(base_x,0.0,base_z);
glRotatef(base_rot,0.0,1.0,0.0);
glCallList(OBJET_3);




// segment 1
float first_y = 0.25*5.5;
glTranslatef(0.0,first_y,0.0);
glRotatef(first_x,1.0,0.0,0.0);
glRotatef(first_z,0.0,0.0,1.0);
glCallList(OBJET_4);
glCallList(OBJET_1);

// segment2
float second_y = 0.6*8.0;
glTranslatef(0.0,second_y,0.0);
glRotatef(second_x,1.0,0.0,0.0);
glRotatef(second_z,0.0,0.0,1.0);
glCallList(OBJET_4);
glCallList(OBJET_1);


// segment 3	
glTranslatef(0.0,second_y,0.0);
glRotatef(third_x,1.0,0.0,0.0);
glRotatef(third_z,0.0,0.0,1.0);
glCallList(OBJET_4);
glCallList(OBJET_1);


// pinces 1 & 2
//float finger_x = 45.0;

glTranslatef(0.0,second_y,0.0);
glCallList(OBJET_4);

glPushMatrix();

glRotatef(finger_x,0.0,0.0,1.0);
glCallList(OBJET_2);
glTranslatef(0.0,5.85*0.3,0.0);
glRotatef(-45.0,0.0,0.0,1.0);
glCallList(OBJET_2);

glPopMatrix();


glRotatef(-finger_x,0.0,0.0,1.0);
glCallList(OBJET_2);

glTranslatef(0.0,5.85*0.3,0.0);
glRotatef(45.0,0.0,0.0,1.0);
glCallList(OBJET_2);
*/
//////////////////////////////////////////////////

//////////////////////////////////////////////////
// Robot complet

/////////////////////////////////
// Base
glTranslatef(base_x,0.0,base_z);
glPushMatrix();
glScalef(2.0,2.0,2.0);
glCallList(OBJET_3);
glPopMatrix();


/////////////////////////////////
// Tronc

glTranslatef(0.0,4.0+(2.0*1.375),0.0);
glRotatef(base_rot,0.0,1.0,0.0);
glPushMatrix();
glScalef(3.0,4.0,3.0);
tronc_robot();
glPopMatrix();
//////////////////////////////////////////////////
// bras 1
glPushMatrix();
glTranslatef(-3.0,2.0,0.0);
glRotatef(90.0,0.0,0.0,1.0);
bras_robot();
glPopMatrix();

//////////////////////////////////////////////////

//////////////////////////////////////////////////
// bras 2
glPushMatrix();
glTranslatef(3.0,2.0,0.0);
glRotatef(-90.0,0.0,0.0,1.0);
glScalef(-1.0,1.0,1.0);
bras_robot();
glPopMatrix();
//////////////////////////////////////////////////
//Tête du robot
glTranslatef(0.0,5.0,0.0);
glutSolidSphere(2.5,20,20);

  // Permutation des buffers
   glutSwapBuffers();
   glutPostRedisplay();
}
Esempio n. 4
0
void SceneObject::DrawCoordinate()
{
	GLdouble orig[3];
	int viewport[4];
	double modelview[16], projection[16];

	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
	int width = viewport[2], height = viewport[3];

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	//glFrustum(viewport[0], viewport[2], viewport[1], viewport[3], 0.01, 1000.);
	if (width > height)
		glOrtho(-width / (double)height, width / (double)height, -1., 1., 0.01, 1000);
	else
		glOrtho(-1., 1., -height / (double)width, height / (double)width, 0.01, 1000);

	glDepthMask(GL_FALSE);
	glGetDoublev(GL_PROJECTION_MATRIX, projection);
	gluUnProject(50, 50, 0.0005, modelview, projection, viewport, &orig[0], &orig[1], &orig[2]);

	glPushMatrix();
	glTranslated(orig[0], orig[1], orig[2]);
	glScaled(.1, .1, .1);
	glPushAttrib (GL_TRANSFORM_BIT |GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT);
	glEnable(GL_COLOR_MATERIAL);

	glColor4f(1.0,0.0,1.0,1.0); //purple sphere
	glutSolidSphere(0.3,30,30);

	glColor4f(1.0,0.0,0.0,1.0); //x red
	glPushMatrix();
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glColor4f(0.0,1.0,0.0,1.0); //y green
	glPushMatrix();
	glRotatef(90,0,0,1);
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glColor4f(0.0,0.0,1.0,1.0); //z blue
	glPushMatrix();
	glRotatef(90,0,-1,0);
	glPushMatrix();
	Cylinder(50,1,0.1);
	glPopMatrix();
	glTranslatef(1,0,0);
	Cone(50,0.5,0.3);
	glPopMatrix();

	glPopAttrib();
	glPopMatrix();

	glDepthMask(GL_TRUE);
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
}
Esempio n. 5
0
void init(void) {
    float tmp,xmin,xmax,ymin,ymax,zmin,zmax,a[3],b[3];
    int i,j,k,width,height;
    unsigned char *data;
    float plane_S[] = { 1.0, 0.0, 0.0, 0.0 };
    float plane_T[] = { 0.0, 1.0, 0.0, 0.0 };
    float plane_R[] = { 0.0, 0.0, 1.0, 0.0 };
    float plane_Q[] = { 0.0, 0.0, 0.0, 1.0 };

    glClearDepth(1.0);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glDisable(GL_CULL_FACE);
    
    glEnable(GL_LIGHT0);
    
    modelsize = 0;
    vertexmodel = Load3DS("data/model.3ds",&num_vertexmodel);
    printf("./data/model.3ds %d face\n",num_vertexmodel / 3);
    
    xmin = xmax = ymin = ymax = zmin = zmax = 0;
    
    for(i = 0; i < num_vertexmodel; i++) {
        if(vertexmodel[(i << 3) + 0] < xmin) xmin = vertexmodel[(i << 3) + 0];
        if(vertexmodel[(i << 3) + 0] > xmax) xmax = vertexmodel[(i << 3) + 0];
        if(vertexmodel[(i << 3) + 1] < ymin) ymin = vertexmodel[(i << 3) + 1];
        if(vertexmodel[(i << 3) + 1] > ymax) ymax = vertexmodel[(i << 3) + 1];
        if(vertexmodel[(i << 3) + 2] < zmin) zmin = vertexmodel[(i << 3) + 2];
        if(vertexmodel[(i << 3) + 2] > zmax) zmax = vertexmodel[(i << 3) + 2];
    }
    
    for(i = 0; i < num_vertexmodel; i++) {
        vertexmodel[(i << 3) + 0] -= (xmax + xmin) / 2.0;
        vertexmodel[(i << 3) + 1] -= (ymax + ymin) / 2.0;
        vertexmodel[(i << 3) + 2] -= (zmax + zmin) / 2.0;
    }
    
    for(i = 0; i < num_vertexmodel; i++) {
        tmp = sqrt(vertexmodel[(i << 3) + 0] * vertexmodel[(i << 3) + 0] +
                    vertexmodel[(i << 3) + 1] * vertexmodel[(i << 3) + 1] +
                    vertexmodel[(i << 3) + 2] * vertexmodel[(i << 3) + 2]);
        if(tmp > modelsize) modelsize = tmp;
    }
    
    tmp = MODELSIZE / modelsize;
    modelsize = MODELSIZE;
    for(i = 0; i < num_vertexmodel; i++) {
        vertexmodel[(i << 3) + 0] *= tmp;
        vertexmodel[(i << 3) + 1] *= tmp;
        vertexmodel[(i << 3) + 2] *= tmp;
    }
    
    vertexground = Load3DS("data/ground.3ds",&num_vertexground);
    printf("./data/ground.3ds %d face\n",num_vertexground / 3);
    
    planeground = (float*)malloc(sizeof(float) * 4 * num_vertexground / 3);
    for(i = 0, j = 0, k = 0; i < num_vertexground; i += 3, j += 24, k += 4) {
        VectorSub(&vertexground[j + 8],&vertexground[j],a);
        VectorSub(&vertexground[j + 16],&vertexground[j],b);
        VectorCrossProduct(a,b,&planeground[k]);
        VectorNormalize(&planeground[k],&planeground[k]);
        planeground[k + 3] = -VectorDotProduct(&planeground[k],&vertexground[j]);
    }
    
    glGenTextures(1,&textureground);
    glBindTexture(GL_TEXTURE_2D,textureground);
    if((data = LoadJPEG("data/ground.jpg",&width,&height))) {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }
    
    glGenTextures(1,&texturemodel);
    glBindTexture(GL_TEXTURE_2D,texturemodel);
    if((data = LoadJPEG("data/model.jpg",&width,&height))) {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,4,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }
    
    glGenTextures(1,&textureshadow);
    glBindTexture(GL_TEXTURE_2D,textureshadow);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexImage2D(GL_TEXTURE_2D,0,4,SHADOWSIZE,SHADOWSIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);

    glTexGenfv(GL_S,GL_EYE_PLANE,plane_S);
    glTexGenfv(GL_T,GL_EYE_PLANE,plane_T);
    glTexGenfv(GL_R,GL_EYE_PLANE,plane_R);
    glTexGenfv(GL_Q,GL_EYE_PLANE,plane_Q);

    modellist = glGenLists(1);
    glNewList(modellist,GL_COMPILE);
    glPushMatrix();
    glBegin(GL_TRIANGLES);
    for(i = 0; i < num_vertexmodel; i++) {
        glNormal3fv((float*)&vertexmodel[i << 3] + 3);
        glTexCoord2fv((float*)&vertexmodel[i << 3] + 6);
        glVertex3fv((float*)&vertexmodel[i << 3]);
    }
    glEnd();
    glPopMatrix();
    glEndList();
    
    groundlist = glGenLists(1);
    glNewList(groundlist,GL_COMPILE);
    glBegin(GL_TRIANGLES);
    for(i = 0; i < num_vertexground; i++) {
        glNormal3fv((float*)&vertexground[i << 3] + 3);
        glTexCoord2fv((float*)&vertexground[i << 3] + 6);
        glVertex3fv((float*)&vertexground[i << 3]);
    }
    glEnd();
    glEndList();
    
    lightlist = glGenLists(1);
    glNewList(lightlist,GL_COMPILE);
    glutSolidSphere(0.6,16,16);
    glEndList();
}
Esempio n. 6
0
void LightsMaterials::exampleMaterial()
{
    GLfloat *no_color = black;

    // === CREATE SPHERES WITH DIFFERENT MATERIALS
    // Exemple adapted from the OpenGL Programming Guide (The Red Book)
    // Note that since OpenGL is a state machine, some glMaterial* calls 
    // are only here for clarity.

    glDisable(GL_COLOR_MATERIAL);  // MANDATORY to use glMaterial!!

    // 	glMaterial*(face, pname, param)
    // specifies a light property for a given reflection component
    // with face in: GL_FRONT_AND_BACK (default), GL_FRONT or GL_BACK
    // and pname in: GL_AMBIENT, GL_DIFFUSE, GL_AMBIENT_AND_DIFFUSE, 
    //          GL_SPECULAR, GL_SHININESS, GL_EMISSION, GL_COLOR_INDEXES

    GLfloat mat_ambient[] =       { 0.7f, 0.7f, 0.7f, 1.0f };
    GLfloat mat_ambient_color[] = { 0.8f, 0.8f, 0.2f, 1.0f };
    GLfloat mat_diffuse[] =       { 0.1f, 0.5f, 0.8f, 1.0f };
    GLfloat no_shininess[] =      { 0.0f };
    GLfloat low_shininess[] =     { 5.0f };
    GLfloat high_shininess[] =    { 100.0f };
    GLfloat mat_emission[] =      { 0.3f, 0.2f, 0.2f, 0.0f };

    glPushMatrix();

    glPushMatrix();
    glTranslatef(-3.75F, 3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f,24,24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-1.25, 3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(1.25, 3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(3.75, 3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-3.75, 0.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-1.25f, 0.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(1.25, 0.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(3.75, 0.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-3.75f, -3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-1.25, -3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(1.25, -3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, white);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_color);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(3.75F, -3.0f, 0.0f);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_color);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0f, 24, 24);
    glPopMatrix();

    glPopMatrix();	
}
Esempio n. 7
0
void lights(void){
  if(night){
    ambientColor[0] = 0.2f;
    ambientColor[1] = 0.2f;
    ambientColor[2] = 0.2f;
  }
  else{
    ambientColor[0] = 0.8f;
    ambientColor[1] = 0.8f;
    ambientColor[2] = 0.8f;
  }
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambientColor);
  GLfloat position[] = { mainCamera.x,1.8,mainCamera.z, 1.0};
  GLfloat direction[] = { 0.0, -1.0, 0.0 };
  GLfloat color[] =  {0.0,0.0,0.0,1.0};
  if(distance(ball.x, 0, ball.z, 0,0,15) < distance(mainCamera.x, 0, mainCamera.z, 0, 0, 15)){
    color[1] = 1.0;
  }
  else{
    color[0] = 1.0;
  }

  GLfloat angle = atan(zoneRadius/1.8f) * 180.0f/PI;
  
  glEnable(GL_LIGHT0);
  glLightfv(GL_LIGHT0,GL_POSITION, position);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,color);
  GLfloat Foco_ak = 1.0;
  GLfloat Foco_al = 0.05f;
  GLfloat Foco_aq = 0.0f;
  glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,	Foco_ak);
  glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,		Foco_al);
  glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,	Foco_aq);

  glLightf(GL_LIGHT0,GL_SPOT_CUTOFF, angle);
  glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, direction);
  glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 5.0);
  if(mode == TURNING_MODE){
    glEnable(GL_LIGHT0);
  }
  else{
    glDisable(GL_LIGHT0);
  }
  angle = 180.0f;
  GLfloat position1[4] = {8.0,5.0,-15,1.0f};
  GLfloat color1[3] = {1.0,1.0,1.0};
  GLfloat direction1[4] = {-12.25f,-5.0f,4.0f,1.0f};
  glPushMatrix();
  if(scored){
    glColor3f(0.5,1.0,0.5);
  }else{
    glColor3f(1.0,0.5,0.5);
  }
  glTranslatef(position1[0],position1[1],position1[2]);
  glutSolidSphere(0.5,50,50);
  glPopMatrix();
  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT1,GL_POSITION, position1);
  glLightfv(GL_LIGHT1,GL_DIFFUSE,color1);
  
  glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION,	Foco_ak);
  glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION,		Foco_al);
  glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION,	Foco_aq);
  
  glLightf(GL_LIGHT1,GL_SPOT_CUTOFF, angle);
  glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION, direction1);
  glLightf(GL_LIGHT1,GL_SPOT_EXPONENT, 3.0);

  GLfloat position2[4] = {-8,5.0,-15,1.0f};
  GLfloat color2[3] = {1.0,1.0,1.0};
  GLfloat direction2[4] = {12.75f,-5.0f,4.0f,1.0f};
  glPushMatrix();
  glTranslatef(position2[0],position2[1],position2[2]);
  glutSolidSphere(0.5,50,50);
  glPopMatrix();
  glEnable(GL_LIGHT2);
  glLightfv(GL_LIGHT2,GL_POSITION, position2);
  glLightfv(GL_LIGHT2,GL_DIFFUSE,color2);
  
  glLightf(GL_LIGHT2,GL_CONSTANT_ATTENUATION,	Foco_ak);
  glLightf(GL_LIGHT2,GL_LINEAR_ATTENUATION,		Foco_al);
  glLightf(GL_LIGHT2,GL_QUADRATIC_ATTENUATION,	Foco_aq);
  
  glLightf(GL_LIGHT2,GL_SPOT_CUTOFF, angle);
  glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION, direction2);
  glLightf(GL_LIGHT2,GL_SPOT_EXPONENT, 3.0);
  
  GLfloat position3[4] = {-8,5.0,15,1.0f};
  GLfloat color3[3] = {1.0,1.0,1.0};
  GLfloat direction3[4] = {12.75f,-5.0f,-4.0f,1.0f};
  glPushMatrix();
  glTranslatef(position3[0],position3[1],position3[2]);
  glutSolidSphere(0.5,50,50);
  glPopMatrix();
  glEnable(GL_LIGHT3);
  glLightfv(GL_LIGHT3,GL_POSITION, position3);
  glLightfv(GL_LIGHT3,GL_DIFFUSE,color3);
  
  glLightf(GL_LIGHT3,GL_CONSTANT_ATTENUATION,	Foco_ak);
  glLightf(GL_LIGHT3,GL_LINEAR_ATTENUATION,		Foco_al);
  glLightf(GL_LIGHT3,GL_QUADRATIC_ATTENUATION,	Foco_aq);
  
  glLightf(GL_LIGHT3,GL_SPOT_CUTOFF, angle);
  glLightfv(GL_LIGHT3,GL_SPOT_DIRECTION, direction3);
  glLightf(GL_LIGHT3,GL_SPOT_EXPONENT, 3.0);

  GLfloat position4[4] = {8,5.0,15,1.0f};
  GLfloat color4[3] = {1.0,1.0,1.0};
  GLfloat direction4[4] = {-12.75f,-5.0f,-4.0f,1.0f};
  glPushMatrix();
  glTranslatef(position4[0],position4[1],position4[2]);
  glutSolidSphere(0.5,50,50);
  glPopMatrix();
  glEnable(GL_LIGHT4);
  glLightfv(GL_LIGHT4,GL_POSITION, position4);
  glLightfv(GL_LIGHT4,GL_DIFFUSE,color4);
  
  glLightf(GL_LIGHT4,GL_CONSTANT_ATTENUATION,	Foco_ak);
  glLightf(GL_LIGHT4,GL_LINEAR_ATTENUATION,		Foco_al);
  glLightf(GL_LIGHT4,GL_QUADRATIC_ATTENUATION,	Foco_aq);
  
  glLightf(GL_LIGHT4,GL_SPOT_CUTOFF, angle);
  glLightfv(GL_LIGHT4,GL_SPOT_DIRECTION, direction4);
  glLightf(GL_LIGHT4,GL_SPOT_EXPONENT, 3.0);
  if(night){
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT2);
    glEnable(GL_LIGHT3);
    glEnable(GL_LIGHT4);
  } else {
    glDisable(GL_LIGHT1);
    glDisable(GL_LIGHT2);
    glDisable(GL_LIGHT3);
    glDisable(GL_LIGHT4);
  }
}
Esempio n. 8
0
void MetaballEnemy::render()
{	
	glColor4f(0.5, 0.5, 0.5, 1.0);
	
	glMaterialfv(GL_FRONT, GL_AMBIENT, centerMaterialAmbient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, centerMaterialDiffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, centerMaterialSpecular);
    glMaterialfv(GL_FRONT, GL_SHININESS, &centerShininess);
	
	glPushMatrix();
	glTranslatef(center.x, center.y, center.z);
	glutSolidSphere(CENTER_SPHERE_RADIUS * this->radius, CENTER_SPHERE_SLICES, CENTER_SPHERE_STACKS);
	glPopMatrix();
	
	glColor4f(0.5, 0.5, 0.5, 1.0);
	
	glMaterialfv(GL_FRONT, GL_AMBIENT, blobMaterialAmbient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, blobMaterialDiffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, blobMaterialSpecular);
    glMaterialfv(GL_FRONT, GL_SHININESS, &blobShininess);
	
	glBegin(GL_TRIANGLES);
	
	memset(added, 0, addedSize3D * sizeof(added[0]));
	
	int curNeighborIndex = 0;
	int endNeighborIndex = 0;
	
	memset(fieldStrengths, 0, strengthSize3D * sizeof(fieldStrengths[0]));
	
	for (int i = 0; i < numBlobs; i++) {
		BallBlob curBlob = blobs[i];
		
		Index blobCubePosition = getCubePosition(curBlob.center);
		
		bool isComputed = false;
		bool found = false;
		
		for(;blobCubePosition.x < DEFAULT_NUM_CUBES_PER_DIMENSION; blobCubePosition.x++)
		{
			if (wasAdded(blobCubePosition))
			{
				isComputed = true;
				found = true;
				break;
			}
			else
			{
				if (renderCube(blobCubePosition))
				{
					found = true;
					break;
				}
			}
		}
		
		if (!isComputed)
		{
			
			addNeighbors(blobCubePosition, endNeighborIndex);
			
			while (curNeighborIndex < endNeighborIndex)
			{
				if (renderCube(neighbors[curNeighborIndex]))
				{
					addNeighbors(neighbors[curNeighborIndex], endNeighborIndex);
				}
				
				curNeighborIndex++;
			}
		}
	}
	
	glEnd();
}
Esempio n. 9
0
void display()
{
    // update the simulation
    if (!bPause)
    {
        psystem->setIterations(iterations);
        psystem->setDamping(damping);
        psystem->setGravity(-gravity);
        psystem->setCollideSpring(collideSpring);
        psystem->setCollideDamping(collideDamping);
        psystem->setCollideShear(collideShear);
        psystem->setCollideAttraction(collideAttraction);

        psystem->update(timestep); 
        renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles());
    }

    // render
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  

    // view transform
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    for (int c = 0; c < 3; ++c)
    {
        camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
        camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
    }
    glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
    glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
    glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);

    glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

    // cube
    glColor3f(1.0, 1.0, 1.0);
    glutWireCube(2.0);

    // collider
    glPushMatrix();
    float4 p = psystem->getColliderPos();
    glTranslatef(p.x, p.y, p.z);
    glColor3f(1.0, 0.0, 0.0);
    glutSolidSphere(psystem->getColliderRadius(), 20, 10);
    glPopMatrix();

    if (displayEnabled)
    {
        renderer->display(displayMode);
    }

    if (displaySliders) {
        glDisable(GL_DEPTH_TEST);
        glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
        glEnable(GL_BLEND);
        params->Render(0, 0);
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
    }

	psystem->debugDraw();

	glDisable(GL_DEPTH_TEST);
	float offsX = 10.f;
	float offsY = 10.f;
	renderer->showProfileInfo(offsX, offsY, 20.f);
	glEnable(GL_DEPTH_TEST);


    glutSwapBuffers();

	{
		 char fps[256];
		 //float ifps = 1.f / (cutGetAverageTimerValue(timer) / 1000.f);
		 switch (psystem->getSimulationMode())
		 {
		 case ParticleSystem::SIMULATION_CUDA:
			 {
				sprintf(fps, "CUDA particles (%d particles)", numParticles);  
				break;
			 }
		case ParticleSystem::SIMULATION_BULLET_CPU:
			 {
				 sprintf(fps, "Bullet btCudaBroadphase (%d btSphereShapes)", numParticles);  
				 break;
			 }
		 default:
			 {
				 sprintf(fps, "Unknown simulation mode");  
			 }
		 }
		 glutSetWindowTitle(fps);
	}

    glutReportErrors();

}
Esempio n. 10
0
void display() {
    // test the perlin noise
    glClear(GL_COLOR_BUFFER_BIT);
    
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    {
        float mat[16];
        cameraRotation.toMatrix(mat);
        glMultMatrixf(mat);
        
        if (display_vortons) {
            /*glEnable(GL_LIGHT0);
             glEnable(GL_LIGHTING);*/
            for (vorton &v : vortons) {
                //glBegin(GL_POINTS);
                //glVertex3f(v.mPos[0], v.mPos[1], v.mPos[2]);
                glColor3f(0.0,0.5,0.5);
                glPushMatrix();
                glTranslatef(v.mPos[0], v.mPos[1], v.mPos[2]);
                glutSolidSphere(.03, 8,8);
                glPopMatrix();
                glBegin(GL_LINES);
                {
                    glColor3f(1.0, 0.0, 0.0);
                    glVertex3f(v.mPos[0], v.mPos[1], v.mPos[2]);
                    glVertex3f(v.mPos[0]+v.mVel[0]*0.1,
                               v.mPos[1]+v.mVel[1]*0.1,
                               v.mPos[2]+v.mVel[2]*0.1);
                    glColor3f(0.0, 1.0, 0.0);
                    glVertex3f(v.mPos[0], v.mPos[1], v.mPos[2]);
                    glVertex3f(v.mPos[0]+v.mVorticity[0]*0.1,
                               v.mPos[1]+v.mVorticity[1]*0.1,
                               v.mPos[2]+v.mVorticity[2]*0.1);
                }
                glEnd();
            }
        }
        
        glDisable(GL_LIGHTING);
        glEnable(GL_POINT_SMOOTH);
        glEnable (GL_BLEND);
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glPointSize(3);
        for (particle &p : tracers) {
            float col = (200-p.mLife)/200.0;
            glColor4f(col, col, col, (1-col)*0.05);
            if (particle_lines) {
                glBegin(GL_LINES);
                glVertex3f(p.mPos[0], p.mPos[1], p.mPos[2]);
                glVertex3f(p.mPos[0]-p.mVel[0]*gTimeStep,
                           p.mPos[1]-p.mVel[1]*gTimeStep,
                           p.mPos[2]-p.mVel[2]*gTimeStep);
                glEnd();
            } else {
                glBegin(GL_POINTS);
                glVertex3f(p.mPos[0], p.mPos[1], p.mPos[2]);
                glEnd();
            }
        }
    }
    glPopMatrix();
    
    if (show_info)
        print_info();
    
    glutSwapBuffers();
}
Esempio n. 11
0
void GESphere::drawVisual(vector_t unit_size)
{
  glColor3ub(RED(bg_color), GREEN(bg_color), BLUE(bg_color));
  glutSolidSphere(radius * min_dimension(unit_size), 100, 100);
}
Esempio n. 12
0
void display(void)
{
    GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
    GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
    GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
    GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat no_shininess[] = { 0.0 };
    GLfloat low_shininess[] = { 5.0 };
    GLfloat high_shininess[] = { 100.0 };
    GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0};

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/*  draw sphere in first row, first column
 *  diffuse reflection only; no ambient or specular
 */
    glPushMatrix();
    glTranslatef (-3.75, 3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in first row, second column
 *  diffuse and specular reflection; low shininess; no ambient
 */
    glPushMatrix();
    glTranslatef (-1.25, 3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in first row, third column
 *  diffuse and specular reflection; high shininess; no ambient
 */
    glPushMatrix();
    glTranslatef (1.25, 3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in first row, fourth column
 *  diffuse reflection; emission; no ambient or specular reflection
 */
    glPushMatrix();
    glTranslatef (3.75, 3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in second row, first column
 *  ambient and diffuse reflection; no specular
 */
    glPushMatrix();
    glTranslatef (-3.75, 0.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in second row, second column
 *  ambient, diffuse and specular reflection; low shininess
 */
    glPushMatrix();
    glTranslatef (-1.25, 0.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in second row, third column
 *  ambient, diffuse and specular reflection; high shininess
 */
    glPushMatrix();
    glTranslatef (1.25, 0.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in second row, fourth column
 *  ambient and diffuse reflection; emission; no specular
 */
    glPushMatrix();
    glTranslatef (3.75, 0.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in third row, first column
 *  colored ambient and diffuse reflection; no specular
 */
    glPushMatrix();
    glTranslatef (-3.75, -3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in third row, second column
 *  colored ambient, diffuse and specular reflection; low shininess
 */
    glPushMatrix();
    glTranslatef (-1.25, -3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in third row, third column
 *  colored ambient, diffuse and specular reflection; high shininess
 */
    glPushMatrix();
    glTranslatef (1.25, -3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

/*  draw sphere in third row, fourth column
 *  colored ambient and diffuse reflection; emission; no specular
 */
    glPushMatrix();
    glTranslatef (3.75, -3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
    glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    glutSolidSphere(1.0, 16, 16);
    glPopMatrix();

    glFlush();
}
Esempio n. 13
0
void display(){
  int i;
  double angle, Y, Z, NY, NZ;

/* vectors are defined to be used to specify material lighting properties */ 
  GLfloat mat_specular1[] = { 1.0, 0.0, 0.0, 1.0 };
  GLfloat mat_shininess1[] = { 50.0 };
  GLfloat mat_diffuse1[] = {0.9, 0.0, 0.0};
  GLfloat mat_specular2[] = { 0.0, 1.0, 0.0, 1.0 };
  GLfloat mat_shininess2[] = { 50.0 };
  GLfloat mat_diffuse2[] = {0.0, 0.9, 0.0};

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/* material lighting properties are specified for the box */
  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular1);
  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess1);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse1);

/* preceding each vertex definition is a normal vector definition, which 
 * is the specification of a normal direction to the surface at that vertex.
 * This is required as lighting has been enabled. Normal vectors are
 * used by OpenGL to calculate how the light striking an object is
 * reflected to a viewer. 
 * In this example, we use the co-ordinates of a vertex itself
 * to define its normal vector - this is simply the outward pointing
 * vector from the origin to the vertex, a reasonable choice in this case.
 */
  glBegin(GL_QUADS);
  for (i = 0; i < 5; ++i){
    glNormal3fv(&vdata[tindices[i][0]][0]);  
    glVertex3fv(&vdata[tindices[i][0]][0]);
    glNormal3fv(&vdata[tindices[i][1]][0]);  
    glVertex3fv(&vdata[tindices[i][1]][0]);
    glNormal3fv(&vdata[tindices[i][2]][0]);  
    glVertex3fv(&vdata[tindices[i][2]][0]);
    glNormal3fv(&vdata[tindices[i][3]][0]);
    glVertex3fv(&vdata[tindices[i][3]][0]);  
}
  glEnd();
  
  angle = ((float)Step/120) * PI;
  Y = 1 + 2 * sin(angle);
  Z = -1 + 2 * cos(angle);
  NY = cos(angle);
  NZ = -sin(angle);
  
  glBegin(GL_QUADS);
    glNormal3f (0, NY, NZ);
    glVertex3f (1.0, Y, Z);
    glNormal3f (0, NY, NZ);
    glVertex3f (1.0, 1.0, -1.0);
    glNormal3f (0, NY, NZ);
    glVertex3f (-1.0, 1.0, -1.0);
    glNormal3f (0, NY, NZ);
    glVertex3f (-1.0, Y, Z);
  glEnd();
     
  glBegin(GL_POLYGON);
    for (i = 0; i < 4; i++) {
      glNormal3fv(&rdata[rindex[i]][0]);
      glVertex3fv(&rdata[rindex[i]][0]);
    }
  glEnd();
 
  /* material lighting properties are specified for the sphere */
  
  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular2);
  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess2);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse2);
  glRotatef(90, 0.0, 1.0, 0.0);
  glTranslatef(0.0, 0.0, 0.5); 
  glutSolidTeapot(0.5);
  glTranslatef(0.0, 0.0, -0.5);
  glRotatef(-90, 0.0, 1.0, 0.0);
  glTranslatef(-0.5, 0.0, 0.0);
  glutSolidSphere (0.5, 10.0, 8.0);
  glTranslatef(0.5, 0.0, 0.0);
  
  glutSwapBuffers();
}
Esempio n. 14
0
void Sphere::DoRender() const
{
	glutSolidSphere(GetRadius(), 20, 20);
}
Esempio n. 15
0
void draw()
{
	/**
	* Draws the 3D scene within the view volume
	*/
	int i,j;
	nfood=0;
	
	prevFrameTime = curFrameTime;
	curFrameTime = glutGet(GLUT_ELAPSED_TIME);								//Determines the time gap between two continuous frame to enable frame independent animation
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW); 											//Switch to the drawing perspective
	
	glLoadIdentity(); 														//Reset the drawing perspective
	glPushMatrix();
	camera();
	//glTranslatef(0.0f,0.0f,-100.0f);
	GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 };
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	
	//Set material for pac and draw the pac
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat mat_shininess[] = {50.0};
	
	glTranslatef(-gridWidthby2, -gridHeightby2,-100.0f);
	
	glPushMatrix();
	glTranslatef(-gridCellSide/2,-gridCellSide/2,-gridCellSide/2);
	glColor4f(0.3,0.34,0.32,1.0);
	glBegin(GL_QUADS);
		glVertex3f(-gridCellSide,-gridCellSide,0);
		glVertex3f(-gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,gridHeightby2*2+gridCellSide,0);
		glVertex3f(gridWidthby2*2+gridCellSide,0-gridCellSide,0);
	glEnd();
	glPopMatrix();
	glPushMatrix();
	
	/*
	In the following lines of code, we translate the PAC, and rotate it according to the direction of the PAC
	*/
	glTranslatef(pacx,pacy,0);

	if(!minionEnabled){
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
		glColor4f(0.75f,0.75f,0.0f,1.0f);
		glutSolidSphere(PACSIZE,50,50);
	}
	else{
		glDisable(GL_COLOR_MATERIAL);
		glRotatef(90.0f,1.0,0.0,0.0);
		if(pacCurDir == GLUT_KEY_LEFT) {
			if(pacAngle <= 270 - angleChange || pacAngle >= 270 + angleChange){
				if(pacAngle<=90 || pacAngle>270){
					pacAngle-=angleChange;
					if(pacAngle<0)
						pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_RIGHT){
			if(pacAngle <= 90 - angleChange || pacAngle >= 90 + angleChange){
				if(pacAngle<90 || pacAngle>=270){
					pacAngle = (pacAngle+angleChange)%360;
				}
				else
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_UP){
			if(pacAngle <= 180 - angleChange || pacAngle >= 180 + angleChange){
				if(pacAngle<=359 && pacAngle>180){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		else if(pacCurDir == GLUT_KEY_DOWN){
			if(pacAngle <= 0 - angleChange || pacAngle >= 0 + angleChange){
				if(pacAngle<=180 && pacAngle>0){
					pacAngle = (pacAngle-angleChange);
					if(pacAngle<0)
							pacAngle+=360;
				}
				else
					pacAngle = (pacAngle+angleChange)%360;
			}
			glRotatef((float)pacAngle,0.0,1.0,0.0);
		}
		minion.draw();	//Draws the minion
		glEnable(GL_COLOR_MATERIAL);
	}								
	glPopMatrix();
	
	//Drawing ghosts
	if(!paused)
		blinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(blinky.color);
	glTranslatef(blinky.getX(),blinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-blinky.getX(),-blinky.getY(),0.0f);
	
	if(!paused)
		inky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(inky.color);
	glTranslatef(inky.getX(),inky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-inky.getX(),-inky.getY(),0.0f);

	if(!paused)
		pinky.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(pinky.color);
	glTranslatef(pinky.getX(),pinky.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-pinky.getX(),-pinky.getY(),0.0f);

	if(!paused)
		clyde.move();
	if(Ghost::getGhostMode() == 2)
		glColor4f(0.0,0.0,1.0,0.8);
	else
		glColor4fv(clyde.color);
	glTranslatef(clyde.getX(),clyde.getY(),0.0f);
	glutSolidSphere(PACSIZE,5,5);
	glTranslatef(-clyde.getX(),-clyde.getY(),0.0f);

	GLfloat mat_specular2[] = {0.2,0.2,0.2,0.7};
	mat_shininess[0] = 100.0;
	GLfloat mat_diffuse[] = {0.2,0.17,0.73,1.0};
	GLfloat mat_ambient[] = {0.1,0.07,0.63,1.0};
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular2);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);

	//Drawing the maze
	GLfloat mazeColor[] = {0.05f,0.07f,0.53f,1.0f};
	for(i=0;i<31;i++){
        
        for(j=0;j<28;j++){
            if(maze[i][j]==1){
                glColor4fv(mazeColor);
                glutSolidCube(gridCellSide);
            }
            else if(maze[i][j]==2){
                glColor4f(1.0f,0.8f,0.85f,0.9f);
                glutSolidSphere(0.5,10,10);
                nfood++;
            }
            else if(maze[i][j]==3){
                glColor4f(0.6f,1.0f,0.7f,0.75f);
                glutSolidSphere(1.2,20,20);
                nfood++;
            }
            glTranslatef(gridCellSide,0.0f,0.0f);
        }
        glTranslatef(-28*gridCellSide,gridCellSide,0.0f);
    }
    glPopMatrix();
    //staticElementsDraw();
    text();
	glutSwapBuffers(); //Send scene to the screen to be shown
}
Esempio n. 16
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   int i,j;
   const double len=2.0;  //  Length of axes
   //  Light position and colors
   float Ambient[]  = {0.3,0.3,0.3,1.0};
   float Diffuse[]  = {1.0,1.0,1.0,1.0};
   float Position[] = {Cos(zh),Ylight,Sin(zh),1.0};

   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);

   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Perspective - set eye position
   if (proj)
   {
      double Ex = -2*dim*Sin(th)*Cos(ph);
      double Ey = +2*dim        *Sin(ph);
      double Ez = +2*dim*Cos(th)*Cos(ph);
      gluLookAt(Ex,Ey,Ez , 0,0,0 , 0,Cos(ph),0);
   }
   //  Orthogonal - set world orientation
   else
   {
      glRotatef(ph,1,0,0);
      glRotatef(th,0,1,0);
   }

   //  Draw light position as sphere (still no lighting here)
   glColor3f(1,1,1);
   glPushMatrix();
   glTranslated(Position[0],Position[1],Position[2]);
   glutSolidSphere(0.03,10,10);
   glPopMatrix();
   //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  glColor sets ambient and diffuse color materials
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL);
   //  Enable light 0
   glEnable(GL_LIGHT0);
   //  Set ambient, diffuse, specular components and position of light 0
   glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient);
   glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse);
   glLightfv(GL_LIGHT0,GL_POSITION,Position);

   //  Draw floor
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_POLYGON_OFFSET_FILL);
   glPolygonOffset(1,1);
   glColor3f(1,1,1);
   glNormal3f(0,1,0);
   for (j=-Dfloor;j<Dfloor;j++)
   {
      glBegin(GL_QUAD_STRIP);
      for (i=-Dfloor;i<=Dfloor;i++)
      {
         glTexCoord2f(i,j); glVertex3f(i,Yfloor,j);
         glTexCoord2f(i,j+1); glVertex3f(i,Yfloor,j+1);
      }
      glEnd();
   }
   glDisable(GL_POLYGON_OFFSET_FILL);
   glDisable(GL_TEXTURE_2D);

   //  Draw scene
   glColor3f(1,1,0);
   scene();

   //  Save what is glEnabled
   glPushAttrib(GL_ENABLE_BIT);
   //  Draw shadow
   switch (mode)
   {
      //  No shadow
      case 0:
         break;
      //  Draw flattened scene
      case 1:
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Transformation with lighting disabled
      case 2:
         glDisable(GL_LIGHTING);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Set shadow color
      case 3:
         glDisable(GL_LIGHTING);
         glColor3f(0.3,0.3,0.3);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows
      case 4:
         glDisable(GL_LIGHTING);
         //  Blended color
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         break;
      //  Blended shadows Z-buffer masked
      case 5:
         glDisable(GL_LIGHTING);
         //  Draw blended 
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.4);
         //  Make Z-buffer read-only
         glDepthMask(0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer read-write
         glDepthMask(1);
         break;
      //  Blended with stencil buffer
      case 6:
         glDisable(GL_LIGHTING);
         //  Enable stencil operations
         glEnable(GL_STENCIL_TEST);

         /*
          *  Step 1:  Set stencil buffer to 1 where there are shadows
          */
         //  Existing value of stencil buffer doesn't matter
         glStencilFunc(GL_ALWAYS,1,0xFFFFFFFF);
         //  Set the value to 1 (REF=1 in StencilFunc)
         //  only if Z-buffer would allow write
         glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
         //  Make Z-buffer and color buffer read-only
         glDepthMask(0);
         glColorMask(0,0,0,0);
         //  Draw flattened scene
         glPushMatrix();
         ShadowProjection(Position,E,N);
         scene();
         glPopMatrix();
         //  Make Z-buffer and color buffer read-write
         glDepthMask(1);
         glColorMask(1,1,1,1);

         /*
          *  Step 2:  Draw shadow masked by stencil buffer
          */
         //  Set the stencil test draw where stencil buffer is > 0
         glStencilFunc(GL_LESS,0,0xFFFFFFFF);
         //  Make the stencil buffer read-only
         glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
         //  Enable blending
         glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
         glColor4f(0,0,0,0.5);
         //  Draw the shadow over the entire floor
         glBegin(GL_QUADS);
         glVertex3f(-Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,-Dfloor);
         glVertex3f(+Dfloor,Yfloor,+Dfloor);
         glVertex3f(-Dfloor,Yfloor,+Dfloor);
         glEnd();
         break;
      default:
         break;
   }    
   //  Undo glEnables
   glPopAttrib();
   
   //  Draw axes - no lighting from here on
   glDisable(GL_LIGHTING);
   glColor3f(1,1,1);
   if (axes)
   {
      glBegin(GL_LINES);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(len,0.0,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,len,0.0);
      glVertex3d(0.0,0.0,0.0);
      glVertex3d(0.0,0.0,len);
      glEnd();
      //  Label axes
      glRasterPos3d(len,0.0,0.0);
      Print("X");
      glRasterPos3d(0.0,len,0.0);
      Print("Y");
      glRasterPos3d(0.0,0.0,len);
      Print("Z");
   }
   //  Display parameters
   glWindowPos2i(5,5);
   Print("Angle=%d,%d  Dim=%.1f Projection=%s Light Elevation=%.1f",
     th,ph,dim,proj?"Perpective":"Orthogonal",Ylight);
   glWindowPos2i(5,25);
   Print(text[mode]);
   //  Render the scene and make it visible
   ErrCheck("display");
   glFlush();
   glutSwapBuffers();
}
Esempio n. 17
0
void World::Draw()
{
	static GLUquadricObj *quadObj = gluNewQuadric();

    float white[4] = {1.0,1.0,1.0,1.0};
    float grey[4] = {0.8,0.8,0.8,1.0};
    float black[4] = {0.0,0.0,0.0,1.0};
	float red[4] = {1.0,0.0,0.0,1.0};
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grey);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black);
    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black);

    for (unsigned int i = 0; i < m_shapes.size(); i++)
    {
        vec3 pos = m_shapes[i]->pos;
        if (m_shapes[i]->GetType() == SPHERE)
        {
            Sphere* c = (Sphere*) m_shapes[i];
            glPushMatrix();
            glTranslatef(pos[0], pos[1], pos[2]);
	        glutSolidSphere(c->r, 20, 20);   
            glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == CUBE)
        {
            Cube* c = (Cube*) m_shapes[i];
            glPushMatrix();
            glTranslatef(pos[0], pos[1], pos[2]);
            glScalef(c->hx*2, c->hy*2, c->hz*2);
	        glutSolidCube(1.0);   
            glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == CYLINDER)
        {
            Cylinder* c = (Cylinder*) m_shapes[i];
            vec3 forward = c->end - c->start;
            double height = forward.Length();
            double radius = c->r;

            forward.Normalize();

            vec3 left = vec3(0,1,0)^forward;
            vec3 up;
            if (left.Length() < 0.0001)
            {
                up = forward^vec3(1,0,0);
                left = up^forward;
            }
            else
            {
                up = forward^left;
            }

            float m[16];
            m[0] = left[0]; m[4] = up[0]; m[8] = forward[0];  m[12] = 0; 
            m[1] = left[1]; m[5] = up[1]; m[9] = forward[1];  m[13] = 0; 
            m[2] = left[2]; m[6] = up[2]; m[10] = forward[2]; m[14] = 0; 
            m[3] = 0.0;  m[7] = 0.0;  m[11] = 0.0;  m[15] = 1.0;

	        glPushMatrix();
			glTranslated(c->start[0], c->start[1], c->start[2]);
            glMultMatrixf(m); 
	        gluQuadricDrawStyle(quadObj, GLU_FILL);
	        gluQuadricNormals(quadObj, GLU_SMOOTH);
	        gluCylinder(quadObj, radius, radius, height, 12, 12);            
			//endCaps
			glPushMatrix();
			gluDisk(quadObj, 0, radius, 12, 12);
			glTranslated(0, 0, height);
			gluDisk(quadObj, 0, radius, 12, 12);
			glPopMatrix();
			glPopMatrix();
        }
        else if (m_shapes[i]->GetType() == GROUND)
        {
            glBegin(GL_QUADS);
                glNormal3d(0,1,0);
                glVertex3f(100, 0.0, -100.0);
                glVertex3f(100, 0.0, 100.0);
                glVertex3f(-100, 0.0, 100);
                glVertex3f(-100, 0.0, -100);
            glEnd();
        }
    }
}
Esempio n. 18
0
	//sfera
	static void drawSolidSphere(float radius,int slices, int stacks) { glutSolidSphere(radius,slices,stacks);}
Esempio n. 19
0
void EnemyFlameMan :: FlameMan(){
	glPushMatrix();//Cabeça
	glTranslated( 300,100,0 );
	glScalef(1,1,0);
	glColor3f(0,0,0);
	glutSolidSphere(5,20,6);





	glBegin(GL_LINES);
	glColor3f(1,0,0);
	glLineWidth(3.0f);

	glVertex3f(-2,-1,0);//boca
	glVertex3f(-4,-1,0);//boca

	glVertex3f(-2,-1,0);//boca
	glVertex3f(-1.5,-2,0);//boca

	glColor3f(0,0,0);
	glVertex3f(0,0,0);//corpo
	glVertex3f(0,-20,0);//corpo

	glVertex3f(0,-20,0); //perna esquerda
	glVertex3f(-3,-30,0);//perna esquerda

	glVertex3f(0,-20,0);//perna direita
	glVertex3f(3,-30,0);//perna direita

	glVertex3f(0,-5,0);//braço direito
	glVertex3f(3,-15,0);//braço direito

	glVertex3f(0,-5,0);//braço esquerdo
	glVertex3f(-3,-15,0);//braço esquerdo

	glVertex3f(-3,-15,0);//braço esquerdo
	glVertex3f(-10,-15,0);//braço esquerdo

	glVertex3f(3,-15,0);//braço direito
	glVertex3f(-4,-17,0);//braço direito


	glEnd();

	glLineWidth(3.0f);
	glBegin(GL_LINES);
	glColor3f(1,0,0);
	glVertex3f(0,-16,0);//arma
	glVertex3f(-15,-16,0);//arma
	glColor3f(1,1,0);
	glVertex3f(-2,-16,0);//arma
	glVertex3f(-2,-20,0);//arma
	glEnd();

	glLineWidth(4.0f);
	glBegin(GL_LINES);

	glColor3f(1,1,1);
	glVertex3f(-10,-31,0);//base do snowboard
	glVertex3f(12,-31,0);//base do snowboard

	glVertex3f(12,-31,0);//curva do snowboard
	glVertex3f(14,-29,0);//curva do snowboard

	glVertex3f(-10,-31,0);//curva do snowboard
	glVertex3f(-12,-29,0);//curva do snowboard

	glEnd();

	glTranslated( -1.5,2,0 );
	glScalef(0.5,0.5,0);
	glColor3f(1,0,0);
	glutSolidSphere(2,20,3);

	glPopMatrix();

}
Esempio n. 20
0
void INode::renderTree(Context& ctx) const {
  for (size_t i = 0; i < _states.size(); i++) {
    // start point
    vec3 startpoint = ctx.getCurrentOrigin();

    // calculate end point of joint
    vec3 endpoint = _states[i]->getEndpoint(ctx);

    // draw the link
    //glBegin(GL_LINES);
    //  glColor3d(1.0, 1.0, 1.0);
    //  glVertex3d(startpoint[0], startpoint[1], startpoint[2]);
    //  glVertex3d(endpoint[0], endpoint[1], endpoint[2]);
    //glEnd();

    // calculate orthonormal basis for cylinder on joint
    vec3 u, v, n;
    _states[i]->getBasis(ctx, u, v, n);

    // check if basis is really orthonormal
    assert(double_equals(dot(u, v), 0));
    assert(double_equals(dot(u, n), 0));
    assert(double_equals(dot(v, n), 0));

    assert(double_equals(norm(u, 2), 1));
    assert(double_equals(norm(v, 2), 1));
    assert(double_equals(norm(n, 2), 1));

    //cout << "pos:" << endl << pos << endl;

    //cout << "u:" << endl << u << endl;
    //cout << "v:" << endl << v << endl;
    //cout << "n:" << endl << n << endl;

    vec3 x = makeVec3(1, 0, 0); 
    vec3 y = makeVec3(0, 1, 0);
    vec3 z = makeVec3(0, 0, 1);

    double ux = dot(x, u);
    double uy = dot(y, u);
    double uz = dot(z, u);

    double vx = dot(x, v);
    double vy = dot(y, v);
    double vz = dot(z, v);

    double nx = dot(x, n);
    double ny = dot(y, n);
    double nz = dot(z, n);

    // change of orthonormal basis from uvn -> xyz
    GLdouble m[16];
    m[0]  = ux;
    m[1]  = uy;
    m[2]  = uz;
    m[3]  = 0;
    
    m[4]  = vx; 
    m[5]  = vy;
    m[6]  = vz;
    m[7]  = 0;

    m[8]  = nx;
    m[9]  = ny;
    m[10] = nz;
    m[11] = 0;

    m[12] = 0; m[13] = 0; m[14] = 0; m[15] = 1;

    mat44 A; 
    A << ux << vx << nx << 0 << endr 
      << uy << vy << ny << 0 << endr
      << uz << vz << nz << 0 << endr 
      << 0  << 0  << 0  << 1 << endr;

    //if (!double_equals(det(A), 1))
    //  cout << "A is: " << endl << A << endl;

    //cout << "det(A): " << det(A) << endl;
    const double dA = det(A);
    if (!double_equals(dA, 1)) {
      cerr << "ERROR: det(A) = " << dA << endl; 
      throw runtime_error("determinant not 1 for rotation matrix");
    }


    //cout << "--" << endl;
    //for (int iii = 0; iii < 16; iii++) {
    //  cout << m[iii] << endl;
    //}
    //cout << "--" << endl;

    if (isRootNode())
      glColor3d(0.0, 0.0, 0.8);
    else if (isFixed())
      glColor3d(0.0, 1.0, 1.0); 
    else
      glColor3d(0.0, 0.0, 1.0);

    glPushMatrix();
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      if (isRootNode())
        glutSolidSphere(0.1, 20, 20);
      else
        glutSolidSphere(0.08, 20, 20);
    glPopMatrix();

    GLUquadricObj *quadric = gluNewQuadric();

    glPushMatrix();
      glColor3d(0.0, 1.0, 0.0);
      glTranslated(startpoint[0], startpoint[1], startpoint[2]);
      glMultMatrixd(m);
      gluCylinder(quadric, 0.05, 0.05, _states[i]->getLength(), 32, 32);
    glPopMatrix();

    gluDeleteQuadric(quadric);

    // recurse into child
    _states[i]->pushContext(ctx);
      _kids[i]->renderTree(ctx);
    ctx.popContext();
  }
}
Esempio n. 21
0
static void renderSphere(GLfloat x, GLfloat y, GLfloat z) {
    glPushMatrix();
    glTranslatef(x,y,z);
    glutSolidSphere(0.4, 16, 16);
    glPopMatrix();
};
Esempio n. 22
0
void display(){
	if (display_pause) return;
#ifdef TREE
	if (display_tree){
		tree_update();
#ifdef GRAVITY_TREE
		tree_update_gravity_data();
#endif
	}
#endif
	if (display_clear){
	        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	}
	if (!display_wire) {
	if (display_spheres){
		glDisable(GL_BLEND);                    
		glDepthMask(GL_TRUE);
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		GLfloat lightpos[] = {0, boxsize_max, boxsize_max, 0.f};
		glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
	}else{
		glEnable(GL_BLEND);                    
		glDepthMask(GL_FALSE);
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_LIGHTING);
		glDisable(GL_LIGHT0);
	}
	}
	glEnable(GL_POINT_SMOOTH);
	glVertexPointer(3, GL_DOUBLE, sizeof(struct particle), particles);
	int _N_active = (N_active==-1)?N:N_active;
	if (display_reference>=0){
		glTranslatef(-particles[display_reference].x,-particles[display_reference].y,-particles[display_reference].z);
	}
	glRotatef(display_rotate_x,1,0,0);
	glRotatef(display_rotate_z,0,0,1);
	for (int i=-display_ghostboxes*nghostx;i<=display_ghostboxes*nghostx;i++){
	for (int j=-display_ghostboxes*nghosty;j<=display_ghostboxes*nghosty;j++){
	for (int k=-display_ghostboxes*nghostz;k<=display_ghostboxes*nghostz;k++){
		struct ghostbox gb = boundaries_get_ghostbox(i,j,k);
		glTranslatef(gb.shiftx,gb.shifty,gb.shiftz);
		if (!(!display_clear&&display_wire)){
			if (display_spheres){
				// Drawing Spheres
				glColor4f(1.0,1.0,1.0,1.0);
#ifndef COLLISIONS_NONE
				for (int i=0;i<N;i++){
					struct particle p = particles[i];
					glTranslatef(p.x,p.y,p.z);
					glScalef(p.r,p.r,p.r);
#ifdef _APPLE
					glCallList(display_dlist_sphere);
#else //_APPLE
					glutSolidSphere(1,40,10);
#endif //_APPLE
					glScalef(1./p.r,1./p.r,1./p.r);
					glTranslatef(-p.x,-p.y,-p.z);
				}
#endif // COLLISIONS_NONE
			}else{
				// Drawing Points
				glEnableClientState(GL_VERTEX_ARRAY);
				glPointSize(3.);
				glColor4f(1.0,1.0,1.0,0.5);
				glDrawArrays(GL_POINTS, _N_active, N-_N_active);
				glColor4f(1.0,1.0,0.0,0.9);
				glPointSize(5.);
				glDrawArrays(GL_POINTS, 0, _N_active);
				glDisableClientState(GL_VERTEX_ARRAY);
			}
		}
		// Drawing wires
		if (display_wire){
#ifndef INTEGRATOR_SEI
			double radius = 0;
			struct particle com = particles[0];
			for (int i=1;i<N;i++){
				struct particle p = particles[i];
				if (N_active>0){
					// Different colors for active/test particles
					if (i>=N_active){
						glColor4f(0.9,1.0,0.9,0.9);
					}else{
						glColor4f(1.0,0.9,0.0,0.9);
					}
				}else{
					// Alternating colors
					if (i%2 == 1){
						glColor4f(0.0,1.0,0.0,0.9);
					}else{
						glColor4f(0.0,0.0,1.0,0.9);
					}
				}
				struct orbit o = tools_p2orbit(p,com);
				glPushMatrix();
				
				glTranslatef(com.x,com.y,com.z);
				glRotatef(o.Omega/DEG2RAD,0,0,1);
				glRotatef(o.inc/DEG2RAD,1,0,0);
				glRotatef(o.omega/DEG2RAD,0,0,1);
				
				glBegin(GL_LINE_LOOP);
				for (double trueAnom=0; trueAnom < 2.*M_PI; trueAnom+=M_PI/100.) {
					//convert degrees into radians
					radius = o.a * (1. - o.e*o.e) / (1. + o.e*cos(trueAnom));
					glVertex3f(radius*cos(trueAnom),radius*sin(trueAnom),0);
				}
				glEnd();
				glPopMatrix();
				com = tools_get_center_of_mass(p,com);
			}
#else 	// INTEGRATOR_SEI
			for (int i=1;i<N;i++){
				struct particle p = particles[i];
				glBegin(GL_LINE_LOOP);
				for (double _t=-100.*dt;_t<=100.*dt;_t+=20.*dt){
					double frac = 1.-fabs(_t/(120.*dt));
					glColor4f(1.0,(_t+100.*dt)/(200.*dt),0.0,frac);
					glVertex3f(p.x+p.vx*_t, p.y+p.vy*_t, p.z+p.vz*_t);
				}
				glEnd();
			}

#endif 	// INTEGRATOR_SEI
		}
		// Drawing Tree
		glColor4f(1.0,0.0,0.0,0.4);
#ifdef TREE
		if (display_tree){
			glColor4f(1.0,0.0,0.0,0.4);
			display_entire_tree();
		}
#endif // TREE
		glTranslatef(-gb.shiftx,-gb.shifty,-gb.shiftz);
	}
	}
	}
	glColor4f(1.0,0.0,0.0,0.4);
	glScalef(boxsize_x,boxsize_y,boxsize_z);
	glutWireCube(1);
	glScalef(1./boxsize_x,1./boxsize_y,1./boxsize_z);
	glRotatef(-display_rotate_z,0,0,1);
	glRotatef(-display_rotate_x,1,0,0);
	if (display_reference>=0){
		glTranslatef(particles[display_reference].x,particles[display_reference].y,particles[display_reference].z);
	}
	glutSwapBuffers();
}
void __stdcall SolidSphere(GLdouble radius)
{
	glutSolidSphere(radius, SLICES, STACKS);
}
Esempio n. 24
0
void
draw_scene(void)
{
    // clear the draw buffer
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    if (show_raytraced)
    {
        if (needs_rerender)
        {
            // clear the framebuffer
            memset(framebuffer, 255, 3*framebuffer_width*framebuffer_height);

            // trace a new picture
            ray_trace();

            needs_rerender = 0;
        }

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        // Draw the framebuffer using a textured quad

        glOrtho(0, framebuffer_width, 0, framebuffer_height, -1, 1);

        glDisable(GL_LIGHTING);
        glDisable(GL_CULL_FACE);

        glEnable(GL_TEXTURE_2D);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
            framebuffer_width, framebuffer_height,
            0, GL_RGB, GL_UNSIGNED_BYTE, framebuffer);

        glColor3f(1, 1, 1);
        glBegin(GL_QUADS);
            glTexCoord2i(0, 0);
            glVertex2i(0, framebuffer_height);

            glTexCoord2i(0, 1);
            glVertex2i(0, 0);

            glTexCoord2i(1, 1);
            glVertex2i(framebuffer_width, 0);

            glTexCoord2i(1, 0);
            glVertex2i(framebuffer_width, framebuffer_height);
        glEnd();
    }
    else
    {
        // Draw scene using OpenGL

        //glutSetWindowTitle("OpenGL view");

        glMatrixMode(GL_PROJECTION);

        glLoadIdentity();
        gluPerspective(VFOV, 1.0*framebuffer_width/framebuffer_height, 0.1, 1000.0);

        glMatrixMode(GL_MODELVIEW);

        setup_camera();

        glEnable(GL_LIGHTING);
        glEnable(GL_CULL_FACE);
        glDisable(GL_TEXTURE_2D);

        // Try to set up the lighting to match the scene

        GLfloat v[4];

        v[0] = scene_ambient_light;
        v[1] = scene_ambient_light;
        v[2] = scene_ambient_light;
        v[3] = 1.0;
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, v);

        for (int l = 0; l < scene_num_lights; l++)
        {
            glEnable(GL_LIGHT0 + l);

            v[0] = scene_lights[l].position.x;
            v[1] = scene_lights[l].position.y;
            v[2] = scene_lights[l].position.z;
            v[3] = 1.0; // we want a positional light source
            glLightfv(GL_LIGHT0 + l, GL_POSITION, v);

            v[0] = v[1] = v[2] = v[3] = 0.0;
            glLightfv(GL_LIGHT0 + l, GL_AMBIENT, v);
            glLightfv(GL_LIGHT0 + l, GL_SPECULAR, v);

            v[0] = v[1] = v[2] = scene_lights[l].intensity;
            v[3] = 1.0;
            glLightfv(GL_LIGHT0 + l, GL_DIFFUSE, v);
        }

        GLfloat one[] = { 1.0, 1.0, 1.0, 1.0 };
        GLfloat zero[] = { 0.0, 0.0, 0.0, 1.0 };

        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, zero);
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, zero);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, one);

		// Draw the triangles in the scene

        triangle    tri;
        int         p, q, r;

        glBegin(GL_TRIANGLES);

        for (int t = 0; t < scene_num_triangles; t++)
        {
            tri = scene_triangles[t];
            p = tri.v[0];
            q = tri.v[1];
            r = tri.v[2];

            glNormal3f(tri.vn[0].x, tri.vn[0].y, tri.vn[0].z);
            glVertex3f(scene_vertices[p].x, scene_vertices[p].y, scene_vertices[p].z);
            glNormal3f(tri.vn[1].x, tri.vn[1].y, tri.vn[1].z);
            glVertex3f(scene_vertices[q].x, scene_vertices[q].y, scene_vertices[q].z);
            glNormal3f(tri.vn[2].x, tri.vn[2].y, tri.vn[2].z);
            glVertex3f(scene_vertices[r].x, scene_vertices[r].y, scene_vertices[r].z);
        }

        glEnd();

        if (show_normals)
        {
            // Draw vertex normals as red lines
            glDisable(GL_LIGHTING);
            glColor3f(1, 0, 0);
            glBegin(GL_LINES);

            vec3    n;
            for (int t = 0; t < scene_num_triangles; t++)
            {
                tri = scene_triangles[t];

                for (int vi = 0; vi < 3; vi++)
                {
                    p = tri.v[vi];
                    n = scene_vertices[p];
                    glVertex3f(n.x, n.y, n.z);
                    n = v3_add(n, v3_multiply(tri.vn[vi], 0.05));
                    glVertex3f(n.x, n.y, n.z);
                }
            }

            glEnd();

            glEnable(GL_LIGHTING);
        }

		// Draw the spheres in the scene

        for (int s = 0; s < scene_num_spheres; s++)
        {
            glPushMatrix();
            glTranslatef(scene_spheres[s].center.x, scene_spheres[s].center.y, scene_spheres[s].center.z);
            glutSolidSphere(scene_spheres[s].radius, 12, 12);
            glPopMatrix();
        }

        // Show BVH node bboxes

        if (show_bvh)
        {
            glDisable(GL_LIGHTING);
            if (draw_bvh_mode == 0)
                draw_bvh_leaf_nodes(bvh_root);
            else
                draw_bvh_inner_nodes(1, bvh_root);
        }

		/*
		// Draw some axes

		glDisable(GL_LIGHTING);

		glBegin(GL_LINES);
			glColor3f(1, 0, 0);
			glVertex3f(0, 0, 0);
			glVertex3f(10, 0, 0);
			glColor3f(0, 1, 0);
			glVertex3f(0, 0, 0);
			glVertex3f(0, 10, 0);
			glColor3f(0, 0, 1);
			glVertex3f(0, 0, 0);
			glVertex3f(0, 0, 10);
		glEnd();
		*/
    }

    // finally, swap the draw buffers to make the triangles appear on screen
    glutSwapBuffers();
}
Esempio n. 25
0
void WorldMove(Bullet * bullets,char ** map,Turret * turrets,float xpos,float ypos,float zpos,int *hp)
{	

					const GLfloat blue[4] = { .3f, .3f, 1.f, 1.f };
					const GLfloat white[4] = { 1.f, 1.f, 1.f, 1.f };
					const GLfloat green[4] = { 0, 204, 0, 1.f };
					const GLfloat red[4] = { 204,0 , 0, 1.f };
int i,j,k;



		//Draw turrets
		for (i=0;i<100;i++)
		{
			if (turrets[i].existing==1)
			{
					
					glPushMatrix();
				
					
					glTranslated(turrets[i].xpos,turrets[i].ypos,turrets[i].zpos);
					
					//Target player
					float x,z,c,angle;
					
					x=xpos-turrets[i].xpos;
					z=zpos-turrets[i].zpos;
					c=sqrt(pow(x,2)+pow(z,2));
					angle=asin(x/c)/3.14*180;
					if (angle<0) angle=-angle;
				
				
					
					if ((x>=0) && (z>=0)) angle=180-angle;
					if ((x<0) && (z>=0)) angle=180+angle;
					if ((x<0) && (z<0)) angle=360-angle;
					turrets[i].yrot=180;
					turrets[i].yrot-=angle;
					
					
					//End targeting					


	
				
					glMaterialfv( GL_FRONT, GL_DIFFUSE,blue );
					
					glutSolidCube(1.4);
					
					
					
					glTranslated(0,1,0);
		
					glutSolidSphere(1.2,10,10);	
					glPushMatrix();
					glRotatef(turrets[i].yrot,0,1.0,0.0);
					glMaterialfv( GL_FRONT, GL_DIFFUSE, green );
					glutSolidCone(0.6,2.3,10,10);
					glPopMatrix();
					glPopMatrix();
					glMaterialfv( GL_FRONT, GL_DIFFUSE, white );
			}
		}

	
	//Draw bullets
	for (i=0;i<1000;i++)
	{
		if (bullets[i].fired==1)
		{
				    //Check for collisions with closest cubes and destroy bullet if collides
				    for (j=(int)((int)(bullets[i].zpos+75)/3.3);j<=(int)((int)(bullets[i].zpos+75)/3.3)+1;j++)
		        	    {	
				
					for (k=(int)((int)(bullets[i].xpos+75)/3.3);k<=(int)((int)(bullets[i].xpos+75)/3.3)+1;k++)
					{	
						
						if (map[j][k]==1)
						{
							if (sqrt(pow(k*3.3-75-bullets[i].xpos,2)+pow(0-bullets[i].ypos,2)+pow(j*3.3-75-bullets[i].zpos,2))<=2.3) //if distance to cube is lesser than 2.3
							{
								bullets[i].fired=0;
							}
						}
					}
				    }

				   //Check for collisions with player and if collides substract hp and destroy bullet
				   if ((bullets[i].player==0) && (sqrt(pow(xpos-bullets[i].xpos,2)+pow(ypos-bullets[i].ypos,2)+pow(zpos-bullets[i].zpos,2))<=1.0)) //if distance to player is lesser than 1.0
							{
							
								(*hp)--;
								bullets[i].fired=0;
							}

				    //Check for collisions with turrets and destroy turret and bullet if collides
				    for (j=0;j<100;j++)
				    {
					if (turrets[j].existing==1)
					{
				
						if (sqrt(pow(turrets[j].xpos-bullets[i].xpos,2)+pow(turrets[j].ypos-bullets[i].ypos,2)+pow(turrets[j].zpos-bullets[i].zpos,2))<=2.0) //if distance to turret is lesser than 2.5
							{
								turrets[j].existing=0;
								bullets[i].fired=0;
							}
					}					
				    }

				    //Move bullet
		   		    float xrotrad, yrotrad;
				    yrotrad = ( bullets[i].yrot / 180 * 3.141592654f);
		       		    xrotrad = ( bullets[i].xrot / 180 * 3.141592654f);
			            bullets[i].xpos += sin(yrotrad)*2;
	 		       	    bullets[i].zpos -= cos(yrotrad)*2;
				    bullets[i].ypos -= sin(xrotrad)*2;

					//Translate and draw bullet
					glPushMatrix();
					glTranslated(bullets[i].xpos,bullets[i].ypos,bullets[i].zpos);
					glMaterialfv( GL_FRONT, GL_DIFFUSE, red );
					glutSolidSphere(0.1,10,10);
					glMaterialfv( GL_FRONT, GL_DIFFUSE, white );
					glPopMatrix();
		}
					
	}
}
Esempio n. 26
0
void display(void){//Crea la nave
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	GLfloat mat_ambient[] = { 0.7f, 0.0f, 0.0f, 0.5f };
	GLfloat mat_diffuse[] = { 0.1f, 0.5f, 0.8f, 0.5f };
	GLfloat mat_specular[] = { 0.2f, 0.2f, 0.2f, 0.5f };
	GLfloat mat_shininess[] = { 100.0f };

	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	
    glPushMatrix ();
      
      glutSolidSphere (0.75, 20, 20);

	  glPushMatrix ();
         glTranslatef (0.0, 0.0, 3.0);
		 glutSolidSphere(.65,8,8);
      glPopMatrix ();

	  glRotatef (20.0, 1.0, 0.0, 0.0);

      glPushMatrix ();
         glRotatef (90.0, 0.0, 1.0, 0.0);
		 glTranslatef (0.0,0.0,0.7);
         glutSolidTorus (0.1,0.3, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glRotatef (90.0, 0.0, 1.0, 0.0);
		 glTranslatef (0.0,0.0,-0.7);
         glutSolidTorus (0.1,0.3, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (2.0,0.0,0.0);
		 glScalef (0.2,2.5,1.0);
         glutSolidIcosahedron ();
      glPopMatrix ();

      glPushMatrix ();
         glTranslatef (2.0, 0.0, 0.0); 
		 glScalef(0.3,1.0,1.0);
         glRotatef (-90.0, 0.0, 1.0, 0.0);
         glutSolidCone (1.0, 2.0, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (1.0,0.0, 0.0); 
		 glScalef (1.5,.4,0.6);
         glutSolidCube (1.0);
      glPopMatrix ();
	
 	  glPushMatrix ();
         glTranslatef (-2.0,0.0,0.0);
		 glScalef (0.2,2.5,1.0);
         glutSolidIcosahedron ();
      glPopMatrix ();

      glPushMatrix ();
         glTranslatef (-2.0, 0.0, 0.0); 
		 glScalef(0.3,1.0,1.0);
         glRotatef (90.0, 0.0, 1.0, 0.0);
         glutSolidCone (1.0, 2.0, 15, 15);
      glPopMatrix ();

	  glPushMatrix ();
         glTranslatef (-1.0,0.0, 0.0); 
		 glScalef (1.5,.4,0.6);
         glutSolidCube (1.0);
      glPopMatrix ();

    glPopMatrix ();
    glFlush();
}
Esempio n. 27
0
 /*调用GLUT函数,绘制一个球*/
 void display ( void )
 {
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glutSolidSphere (1.0, 40, 50);
     glFlush ();
 }
Esempio n. 28
0
/**
 *  For debug purposes only: render all shapes in this simulator.
 */
void OdeSimulator::renderGeoms() const
{
#ifndef DEDICATED_SERVER    
#ifdef ENABLE_DEV_FEATURES
    
    const static GLfloat category_color[][4] = { {1.0, 0.0, 1.0, 1.0 },   // CCC_STATIC     : Magenta
                                                 {0.0, 1.0, 1.0, 1.0 },   // CCC_PROXY      : Cyan
                                                 {1.0, 1.0, 0.0, 1.0 },   // CCC_CONTROLLED : Yellow
                                                 {0.0, 1.0, 0.0, 1.0 } }; // CCCC_BEACON    : Green
    const static unsigned num_category_colors = sizeof(category_color) / 4 / sizeof(GLfloat);

    const static GLfloat disabled_color[] = { 0.2, 0.2, 0.2, 1.0 };
    const static GLfloat new_cat_color[]  = { 1.0, 0.5, 0.0, 1.0 };
    const static GLfloat center_color[]   = { 1.0, 1.0, 1.0, 1.0 };
    const static GLfloat cog_color[]      = { 1.0, 0.0, 0.0, 1.0 };

    ADD_STATIC_CONSOLE_VAR(bool, render_sensors, false);
    
    for (std::list<OdeRigidBody*>::const_iterator it=body_.begin();
         it != body_.end();
         ++it)
    {
        const OdeRigidBody * cur_body = *it;
            
        glPushMatrix();
        
        // First render the center of the rigid body.
        Matrix trans = cur_body->getTransform();
        glMultMatrixf((GLfloat*)&trans._11);
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, center_color);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, center_color);
        glutSolidSphere(CENTER_COG_RENDER_RADIUS, 10, 10);

        // Geoms are relative to the object's COG. Render cog.
        Matrix cog_offset(true);
        cog_offset.getTranslation() = cur_body->getCog();
        glMultMatrixf((GLfloat*)&cog_offset._11);
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, cog_color);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, cog_color);
        glutSolidSphere(CENTER_COG_RENDER_RADIUS, 10, 10);

        glPopMatrix();


        // Enable wireframe if body is sleeping
        glPushAttrib(GL_POLYGON_BIT | GL_LINE_BIT);
        if (cur_body->isSleeping())
        {
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            glLineWidth(2);
        }
        
        for (std::vector<OdeGeom*>::const_iterator it2 = cur_body->getGeoms().begin();
             it2 != cur_body->getGeoms().end();
             ++it2)
        {
            const OdeGeom * cur_geom = *it2;

            if (!render_sensors && cur_geom->isSensor()) continue;

            const GLfloat * color;
            if (!cur_geom->isEnabled())
            {
                color = disabled_color;
            } else
            {
                if (cur_geom->getCategory() < num_category_colors)
                {
                    color = category_color[cur_geom->getCategory()];
                } else
                {
                    color = new_cat_color;
                }
            }
            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);


            
            glPushMatrix();
            Matrix offset = cur_geom->getTransform();
            glMultMatrixf((GLfloat*)&offset._11);

            cur_geom->render();

            glPopMatrix();
        }

        glPopAttrib();
    }
#endif
#endif
}
Esempio n. 29
0
/* display */
void Display(void)
{
  if (solid) {
    glEnable(GL_LIGHTING);   // Draw polygon interiors with lighting enabled.
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);  // Draw polygon interiors.

    glEnable(GL_POLYGON_OFFSET_FILL);  // Turn on offset for filled polygons.
    glPolygonOffset(1, 1);     // Set polygon offset amount.

  } else {
    glDisable(GL_LIGHTING);  // Draw polygon outlines with lighting disabled.
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);  // Draw polygon outlines.

    glColor4f(1.0, 1.0, .5, 1); // Draw the outlines in black.
  }
  //clean the scene
  glClearColor(0.1, 0.1, 0.1, 1.0); //set background
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  //set matrix mode to GL_MODELVIEW
  glMatrixMode(GL_MODELVIEW);
  glLightfv(GL_LIGHT0, GL_POSITION, light_position);

  glColor4f(1.0f, 0.4f, 0.0f, 1.0f);



  glPushMatrix();
  glRotatef(rotation_x, 0.0, 1.0, 0.0);
  glRotatef(rotation_y, 1.0, 0.0, 0.0);
  if (drawFloor_b) {
    drawFloor(7.0f, 7.0f, 0.8f);
  }
  if (test_light) {
    glutSolidSphere(3.0, 16, 16);
  }
  if (ellipsoid) {
    glBegin(GL_POINTS);
    glColor4f(1.0, 1, 0, 1);
    glVertex3fv(eye);
    glEnd();
    displayElipsoidDemo();
  }

  if (refraction) {
    refractionPlaneDome();
  }

  if (surfaceRenderDemo) {
    eye[1] += moveright;
    displayElipsoidDemo();
    //   GLfloat a[3]={1,1,0}, b[3]={0,1,2}, c[3]={0,1,0};
//    drawSurfaceRenderWithTexture(a,b,c,eye,0);
    glBindTexture ( GL_TEXTURE_2D, texture_id[current_texture] );
    glBegin ( GL_QUADS);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( floor_d, floor_l,  -floor_d);
    glTexCoord2f(0.0f, 1.0f); glVertex3f( -floor_d, floor_l,  -floor_d);
    glTexCoord2f(0.0f, 0.0f); glVertex3f( -floor_d,  floor_l,  floor_d);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( floor_d,  floor_l, floor_d);
    glEnd();
    glutPostRedisplay();

    // glBegin ( GL_TRIANGLES);
    // glTexCoord2f(1.0f, .5f); glVertex3f( floor_d, floor_l-3,  -floor_d);
    // glTexCoord2f(.7f, .5f); glVertex3f( -floor_d, floor_l-3,  -floor_d);

    // glTexCoord2f(1.0f, 0.0f); glVertex3f( floor_d,  floor_l-3, floor_d);
    // glEnd();

    // glutSwapBuffers();
  }
  /** #p: ray plane basic refraction demo */
  if (rayplane) {
    glPushMatrix();
    //glLoadIdentity();
    glScalef(1.0f, 1.0f, 1.0f);
    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
    glutWireSphere(R, 20, 20);
    drawDemoRaySemisphere();
    glPopMatrix();
  } /** #p ends */

  /** #o circle plane basic refraction demo*/
  if (circleplane) {
    glPushMatrix();
    //glLoadIdentity();
    glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
    glutWireSphere(R, 20, 20);
    drawDemoCircleSemisphere(numberOfDots);
    glPopMatrix();
  }

  glPopMatrix();


  glutSwapBuffers();
};
Esempio n. 30
0
/* Focntion de dessin */
void DrawGLScene()
{
    // Effacement du buffer de couleur et de profondeur
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(cam_pos_x,50.0,cam_pos_z,cam_look_x,5.0,cam_look_z,0.0,1.0,0.0);

    ////////////////////////////////////////////////////////////
    // Affichage des sphères

    SetMaterial(mat_specularGREEN, mat_ambientGREEN, mat_diffuseGREEN, mat_shininessGREEN);
    int i,j ; // variables d'incrémentation

    for (i = 0; i < N_S ; i++){
        glPushMatrix();

        if (i == 0){
            SetMaterial(mat_specularYELLOW, mat_ambientYELLOW, mat_diffuseYELLOW, mat_shininessYELLOW);
        }

        if (i == 1){
            SetMaterial(mat_specularGRAY, mat_ambientGRAY, mat_diffuseGRAY, mat_shininessGRAY);
        }

        if (i == 2){
            SetMaterial(mat_specularRED, mat_ambientRED, mat_diffuseRED, mat_shininessRED);
        }

        glTranslatef(sphere_p[0][i], sphere_p[1][i], sphere_p[2][i]);
        glutSolidSphere (R, 50, 50);
        glPopMatrix();
    }

    // Dessin de la table
    SetMaterial(mat_specularTAB, mat_ambientTAB, mat_diffuseTAB, mat_shininessTAB);

    glPushMatrix();

    Draw3DTable();
    glPopMatrix();

    // Dessin de la grille
    glPushMatrix();
    Draw3DSGrid();
    glPopMatrix();

    // Dessin de la queue
    glPushMatrix();
    glTranslatef(queue_p[0] , queue_p[1], queue_p[2]);
    glRotatef(QueueRot,0.0,1.0,0.0);
    GLUquadricObj *p;
    p = gluNewQuadric();
    gluCylinder(p, 0.09, 0.09,20.0, 30, 30);
    glPopMatrix();
    glPopMatrix();

    // Affichage de la puissance de frappe de la queue
    char strMsg[45] = {0};
    char strMsgArg[] = "%";

    Pourcentage = (Puiss_incr / Puissance_max) * 100.0;

    glPushMatrix();
    glLoadIdentity();
    glRasterPos3f(-0.4f,-0.4f,-1.);
    sprintf ( strMsg, "Puissance de la queue  %d %s", Pourcentage, strMsgArg);
    unsigned int k;
    for ( k=0;k<strlen(strMsg);k++)
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,*(strMsg+k));

    glPopMatrix();


////////////////////////////////////////////////////////////

// Permutation des buffers
   glutPostRedisplay();
   glutSwapBuffers();
}