683 Lab 1: Rotating Cube

683 Lab 1: Rotating Cube

Due: Wednesday Sept. 29, 11:59pm (submit source code for 'lab1.c')

Right now, this is a draft - it may need some improvement here and there, but the assignment itself and the due date are finalized.

last update: 24 Sept 2010; 12:45pm


PRELIMINARY NOTES


ASSIGNMENT: The basic task is to write a program to animate a cube rotating around the y-axis.

The animation part of this lab is fairly trivial. This lab is mainly intended to get everybody to organize a simulation system and associated support routines that they can use in future labs and to make sure everyone has the programming and OpenGL skills necessary for the class.

Placve a red cube (+/- 0.5, +/- 0.5, +/- 0.5) 5 units along the x-axis at (5,0,0). Rotate it around the global y-axis and at the same time rotate around its own z-axis.

Draw a reasonable groundplane and y-axis. For example, represent the y-axis by a cube (+/- 0.5, +/- 10.0, +/- 0.5)

Each frame, update the angles by some reasonable constant.

To initialize:

To reset:

To step the animation:

To render


EXAMPLES OF SUPPORT ROUTINES

throughout the quarter set up source code files for drawing geometry, set material properties, and (needed later) matrix operations

Geometry

for example,
draw-cube() - a routine that draws a cube in openGL

void  draw_cube()
{

  glShadeModel(GL_FLAT);

  // draw polygon at z=-1.0
  glBegin(GL_POLYGON);
  glNormal3f( 0.0, 0.0, -1.0);
  glVertex3f(-1.0,  1.0, -1.0);
  glVertex3f(-1.0, -1.0, -1.0);
  glVertex3f( 1.0, -1.0, -1.0);
  glVertex3f( 1.0,  1.0, -1.0);
  glEnd();

  // draw polygon at z= 1.0
  glBegin(GL_POLYGON);
  glNormal3f(0.0, 0.0 , 1.0);
  glVertex3f(-1.0,  1.0, 1.0);
  glVertex3f( 1.0,  1.0, 1.0);
  glVertex3f( 1.0, -1.0, 1.0);
  glVertex3f(-1.0, -1.0, 1.0);
  glEnd();

  // draw polygon at x= -1.0
  glBegin(GL_POLYGON);
  glNormal3f(-1.0,  0.0,  0.0);
  glVertex3f(-1.0,  1.0, 1.0);
  glVertex3f(-1.0, -1.0, 1.0);
  glVertex3f(-1.0, -1.0,-1.0);
  glVertex3f(-1.0,  1.0,-1.0);
  glEnd();

  // draw polygon at x= 1.0
  glBegin(GL_POLYGON);
  glNormal3f(1.0, 0.0, 0.0);
  glVertex3f( 1.0,  1.0, 1.0);
  glVertex3f( 1.0,  1.0,-1.0);
  glVertex3f( 1.0, -1.0,-1.0);
  glVertex3f( 1.0, -1.0, 1.0);
  glEnd();

  // draw polygon at y = 1.0
  glBegin(GL_POLYGON);
  glNormal3f(0.0, 1.0, 0.0);
  glVertex3f( 1.0,  1.0, 1.0);
  glVertex3f(-1.0,  1.0, 1.0);
  glVertex3f(-1.0,  1.0,-1.0);
  glVertex3f( 1.0,  1.0,-1.0);
  glEnd();

  // draw polygon at y = -1.0
  glBegin(GL_POLYGON);
  glNormal3f(0.0, -1.0, 0.0);
  glVertex3f( 1.0, -1.0,  1.0);
  glVertex3f( 1.0, -1.0, -1.0);
  glVertex3f(-1.0, -1.0, -1.0);
  glVertex3f(-1.0, -1.0,  1.0);
  glEnd();
}
Set material
material_td redPlastic = {
	0.4, 0.0, 0.0, 1.0 },
	0.6, 0.0, 0.0, 1.0 },
	0.0, 0.0, 0.0, 1.0 },
	0 }
	};

void  set_material(char *name)
{
  material_td *material;
  // printf("%s\\n",name);

  if (!strcmp(name,"redPlasticMaterial" )) material = &redPlastic;
  else if (!strcmp(name,"greenPlasticMaterial" )) material = &greenPlastic;
  else material = &redPlastic;

  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,material->ambient);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,material->diffuse);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,material->specular);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, material->shininess);

}
then, in your display code, just say
    set_material("redPlasticMaterial");
    draw_cube();

Matrix/Vector Operations

Some useful operations would be to: