Пример #1
0
int main()
{
	//init vertex
	Vector3f v1 = Vector3f(0.3, 0.3, 0.3);
	Vector3f v2 = Vector3f(0.3, 0.3, 0.6);
	//print Vertex
	puts("Init Vertex");
	PrintVertex(v1); PrintVertex(v2);
	//set Camera
	myLookAt(Vector3f(0.0, 0.0, 2.0), Vector3f(0.0, 0.0, 0.0), Vector3f(0.0, 1.0, 0.0));
	
	//set Ortho
	myOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
	//print Vertex
	puts("Ortho");
	PrintVertex(DrawVertex(v1)); PrintVertex(DrawVertex(v2));
	
	//set Frustum
	myFrustum(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
	//print Vertex
	puts("Frustum");
	PrintVertex(DrawVertex(v1)); PrintVertex(DrawVertex(v2));

	getchar();
	return 0;
}
Пример #2
0
Файл: main.c Проект: MR-KO/GAGT
void DrawGLScene()
{

  float cameraX = 20.0*cos(cameraRotation);
  float cameraZ = 20.0*sin(cameraRotation);

  double stretch,height,position,rotation;

  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

  glLoadIdentity ();

  if(useMyLookat)
    myLookAt (cameraX, cameraHeight,cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  else
    gluLookAt (cameraX, cameraHeight,cameraZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

  position=cos((double)frame*speed)*2;
  height=absf(sin((double)frame*speed)*10)+1;
  rotation=cos((double)frame*speed)*90;
  if(doTranslate) {
    if(height<2) stretch=height/2; else stretch=1;
  } else {
    stretch=sin((double)frame*speed/3)+1.5;
  }

  glPushMatrix();
  glTranslatef(0,-5,0);
  glScalef(8,0.2,8);
  drawCube();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(2,-5,0);
  glScalef(1.2,-0.5,1.2);
  drawCube();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(-2,-5,0);
  glScalef(1.2,-0.5,1.2);
  drawCube();
  glPopMatrix();

  if(doTranslate) glTranslatef(position,height-5,0.0);
  if(doRotate) glRotatef(rotation,0,1,0);
  if(doScale) glScalef(1/sqrt(stretch),stretch,1/sqrt(stretch));

  drawCube();

  frame++;
  cameraRotation += cameraRotationSpeed;
  cameraHeight = cameraHeight*0.99 + cameraHeightTarget*0.01;

  glutSwapBuffers();
}
Пример #3
0
void displayCallback( ){
  const float centerPosition[] = {0.0, 0.0, 0.0};

  float viewingTransform[16];
  float modelingTransform[16];

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);

  myLookAt( viewingTransform,
    eyePosition[0], eyePosition[1], eyePosition[2],
    centerPosition[0], centerPosition[1], centerPosition[2],
    upVector[0], upVector[1], upVector[2], camZ
  );

  // Set light & material properties for the teapot;
  // lights are transformed by current modelview matrix
  // such that they are positioned correctly in the scene.
  matMultVec4f( light0, light0_position, viewingTransform );
  matMultVec4f( light1, light1_position, viewingTransform );
  matMultVec4f( light2, light2_position, viewingTransform );
  matMultVec4f( light3, light3_position, viewingTransform );

  shaderProgram_A->activate( );
  activateUniforms_A( );
  glLoadIdentity( );
  glMultMatrixf(viewingTransform);
  myScalef(modelingTransform,
           teapotScale_A[0], teapotScale_A[1], teapotScale_A[2]);
  glMultMatrixf(modelingTransform);
  myTranslatef(modelingTransform,
               teapotTranslation_A[0],
               teapotTranslation_A[1],
               teapotTranslation_A[2]);
  glMultMatrixf(modelingTransform);
  _glutSolidTeapot(1.3);

  shaderProgram_B->activate( );
  activateUniforms_B( );
  glLoadIdentity( );
  glMultMatrixf(viewingTransform);
  myTranslatef(modelingTransform,
               teapotTranslation_B[0],
               teapotTranslation_B[1],
               teapotTranslation_B[2]);
  glMultMatrixf(modelingTransform);
  _glutSolidTeapot(1.3);

  glutSwapBuffers();
}