Ejemplo n.º 1
0
void display1()
{	
  glutSetWindow(id1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
         
  /*$$$
    [Frus-left, f, -1.0, -5.0, 5.0, c],
    [Frus-right, f, 1.0, -5.0, 5.0, c],
    [Frus-bottom, f, -1.0, -5.0, 5.0, c],
    [Frus-top, f, 1.0, -5.0, 5.0, n],
    [Frus-near, f, 2.0, 0.1, 20.0, c],
    [Frus-far, f, 20.0, 0.1, 30.0, c]
    $$$*/
  glFrustum(JPOT$1, JPOT$2, JPOT$3, JPOT$4, JPOT$5, JPOT$6);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(2, 4, 10, 0 , 0 , 0, 0, 1, 0);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);	
  
  drawtable();
  drawaxes();
  drawpot();

  glTranslatef(2, 0,- 10);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff_red);
  glutSolidSphere(1.0, 40, 40);

  glFlush();
}
Ejemplo n.º 2
0
void display2()
{	
  glutSetWindow(id2);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();  
       
  /*$$$
    [Orth-left, f, -5.0, -10.0, 10.0, n],
    [Orth-right, f, 5.0, -10.0, 10.0, c],
    [Orth-bottom, f, -5.0, -10.0, 10.0, c],
    [Orth-top, f, 5.0, -10.0, 10.0, n],
    [Orth-near, f, 2.0, -10.0, 10.0, c],
    [Orth-far, f, 20.0, 10.0, 30.0, c]
    $$$*/
  glOrtho(JPOT$7, JPOT$8, JPOT$9, JPOT$10, JPOT$11, JPOT$12);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(2, 4, 10, 0 , 0 , 0, 0, 1, 0);
  glLightfv(GL_LIGHT0, GL_POSITION, light0_position);	
  
  drawtable();
  drawaxes();
  drawpot();

  glTranslatef(2, 0,- 10);
  glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff_red);
  glutSolidSphere(1.0, 40, 40);

  glFlush();
}
Ejemplo n.º 3
0
static void display(void)
{
  /* World-space positions for light and eye. */
  const float eyePosition[4] = { camera[0], camera[1], camera[2], 1 };
  const float lightPosition[4] = { 0,100,0, 1 };

  float translateMatrix[16], rotateMatrix[16],
        modelMatrix[16], invModelMatrix[16], viewMatrix[16],
        modelViewMatrix[16], modelViewProjMatrix[16];
  float objSpaceEyePosition[4], objSpaceLightPosition[4];

  buildLookAtMatrix(eyePosition[0], eyePosition[1], eyePosition[2],
                    0, 0, 0,
                    0, 1, 0,
                    viewMatrix);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  cgGLBindProgram(myCgVertexProgram);
  checkForCgError("binding vertex program");

  cgGLEnableProfile(myCgVertexProfile);
  checkForCgError("enabling vertex profile");

  cgGLBindProgram(myCgFragmentProgram);
  checkForCgError("binding fragment program");

  cgGLEnableProfile(myCgFragmentProfile);
  checkForCgError("enabling fragment profile");
  

  /*** Render able ***/

   
  setTableMaterial();

  /* modelView = rotateMatrix * translateMatrix */
  makeRotateMatrix(0, 1, 1, 1, rotateMatrix);
  makeTranslateMatrix(0, 0 , 0, translateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
  drawtable();
  
  collision();

  /*** Render White Ball ***/
  setBallMaterial(w.r, w.g, w.b);
  
  if (w.xspeed>0) { w.xspeed=w.xspeed-friction; if (w.xspeed<=0){ w.xspeed=0;}else w.x=w.x+(w.xspeed);}
  else if(w.xspeed<0){ w.xspeed=w.xspeed+friction; if (w.xspeed>=0) {w.xspeed=0;}else w.x=w.x+(w.xspeed);}
	else  { w.xspeed = 0; 
			}
	if (w.zspeed>0) {w.zspeed=w.zspeed-friction; if (w.zspeed<=0) {w.zspeed=0;}else w.z=w.z+(w.zspeed);}
	else if (w.zspeed<0){ w.zspeed=w.zspeed+friction; if (w.zspeed>=0) {w.zspeed=0;}else w.z=w.z+(w.zspeed);}
	else { w.zspeed=0;
	}
  if (w.xspeed==0 && w.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
 
  board();
  
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(w.x, w.y, w.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutWireSphere(4, 30, 30);

  /*** Render Red Ball ***/
  setBallMaterial(r.r,r.g,r.b);

  collision();
  //checkzerospeed();
  if (r.xspeed>0){r.xspeed=r.xspeed-friction; if (r.xspeed<=0) { r.xspeed=0;}else r.x=r.x+(r.xspeed);}
  else if(r.xspeed<0){r.xspeed=r.xspeed+friction; if (r.xspeed>=0) {r.xspeed=0;}else r.x=r.x+(r.xspeed);}
	else  { r.xspeed = 0;
			}
	if (r.zspeed>0){r.zspeed=r.zspeed-friction; if (r.zspeed<=0){ r.zspeed=0;}else r.z=r.z+(r.zspeed);}
	else if (r.zspeed<0){r.zspeed=r.zspeed+friction; if (r.zspeed>=0) { r.zspeed=0;}else r.z=r.z+(r.zspeed);}
	else r.zspeed=0;

	if (r.xspeed==0 && r.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
  redboard();
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(r.x, r.y, r.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutSolidSphere(4, 30, 30); 

 /*** Render Black Ball ***/
  setBallMaterial(b.r,b.g,b.b);

  collision();
 
  if (b.xspeed>0){b.xspeed=b.xspeed-friction; if (b.xspeed<=0) {b.xspeed=0;}else  b.x=b.x+(b.xspeed);}
  else if(b.xspeed<0){b.xspeed=b.xspeed+friction; if (b.xspeed>=0) { b.xspeed=0;}else  b.x=b.x+(b.xspeed);}
	else  { b.xspeed = 0;
			}
	if (b.zspeed>0){b.zspeed=b.zspeed-friction; if (b.zspeed<=0){ b.zspeed=0;}else b.z=b.z+(b.zspeed);}
	else if (b.zspeed<0){b.zspeed=b.zspeed+friction; if (b.zspeed>=0) { b.zspeed=0;}else b.z=b.z+(b.zspeed);}
	else b.zspeed=0;

 if (b.xspeed==0 && b.zspeed==0)
 {b.flag=1;
 w.flag=1;
 r.flag=1;
glutPostRedisplay(); 
 }
  blackboard();
 
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(b.x, b.y, b.z, translateMatrix);
  makeRotateMatrix(90, 1, 0, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);

  glutSolidSphere(4, 30, 30);

    /*** Render Stick***/
  if (enablestick)
  
  { //printf("stick enabled");
  setStickMaterial();
  /* modelView = viewMatrix * translateMatrix */
  makeTranslateMatrix(w.x,0,w.z, translateMatrix);
  makeRotateMatrix(stickangle, 0, 1, 0, rotateMatrix);
  multMatrix(modelMatrix, translateMatrix, rotateMatrix);

  /* invModelMatrix = inverse(modelMatrix) */
  invertMatrix(invModelMatrix, modelMatrix);

  /* Transform world-space eye and light positions to sphere's object-space. */
  transform(objSpaceEyePosition, invModelMatrix, eyePosition);
  cgSetParameter3fv(myCgFragmentParam_eyePosition, objSpaceEyePosition);
  transform(objSpaceLightPosition, invModelMatrix, lightPosition);
  cgSetParameter3fv(myCgFragmentParam_lightPosition, objSpaceLightPosition);

  /* modelViewMatrix = viewMatrix * modelMatrix */
  multMatrix(modelViewMatrix, viewMatrix, modelMatrix);

  /* modelViewProj = projectionMatrix * modelViewMatrix */
  multMatrix(modelViewProjMatrix, myProjectionMatrix, modelViewMatrix);

  /* Set matrix parameter with row-major matrix. */
  cgSetMatrixParameterfr(myCgVertexParam_modelViewProj, modelViewProjMatrix);
drawstick();
  
/*  glBegin(GL_LINES);
  glVertex3f(0,0,0);
  glVertex3f(0,20,84);
  glEnd();
 */
  }

  glutSwapBuffers();
}