Beispiel #1
0
//draw tree based on cylinders
void draw_tree(glm::mat4 M){
  draw_cylinder(0.3,0.3,2,12,brown,false,M);
  M *= Mtranslate(0,0,2);
  draw_cylinder(2,1,2,12,c2,false,M);
  M *= Mtranslate(0,0,2);
  draw_cylinder(2,1,2,12,c2,false,M);
  M *= Mtranslate(0,0,2);
  draw_cylinder(2,0,2,12,c2,false,M);
}
Beispiel #2
0
/*TODO: expand according to assignment 2 specs*/
void draw_object(int shape) {

    switch(shape) {
    case HOUSE:
        draw_house();
        break;
    case CUBE:
        draw_cube_brute();
        break;
    case CYLINDER:
        draw_cylinder(crt_rs, crt_vs);
        break;
    case SPHERE:
        draw_sphere(crt_rs, crt_vs);
        break;
    case TORUS: /*TODO EC: call your function here*/
        ;
        break;
    case MESH: /*TODO EC: call your function here*/
        ;
        break;

    default:
        break;
    }

}
void ShZshapeManager::draw_shape(const char* content)
{
	if (content == "cube")
	{
		draw_cube();
	}

	if (content == "cylinder")
	{
		draw_cylinder();
	}

	if (content == "pipe")
	{
		draw_pipe();
	}

	if (content == "cone")
	{
		draw_cone();
	}

	if (content == "circle")
	{
		draw_circle();
	}

	if (content == "ring")
	{
		draw_ring();
	}

	if (content == "pyramid")
	{
		draw_pyramid();
	}

	if (content == "triangle")
	{
		draw_triangle();
	}

	if (content == "rectangle")
	{
		draw_rectangle();
	}

	if (content == "polygon")
	{
		draw_polygon();
	}

	if (content == "multigonalStar")
	{
		draw_multigonalStar();
	}
}
Beispiel #4
0
//draw sphere based on cylinders
void draw_sphere(float r, int slices, int stacks, float color[3],glm::mat4 M){
  glPushMatrix();
  //glMultMatrixf(&M[0][0]);
  glm::mat4 buf = M;
  for (int i = 0; i < stacks/2; ++i)
  {
    // std::cout<<r*sin((i+1)*(PI)/stacks)<<std::endl;
    draw_cylinder(r*cos(i*(PI)/stacks),r*cos((i+1)*(PI)/stacks),
      r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks),slices,color,true,buf);
    //glTranslatef(0,0,r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks));
    buf = buf * Mtranslate(0,0,r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks));
  }
  // glRotatef(180,1,0,0);
  buf = M * Mrotate(180,1,0,0);
  for (int i = 0; i < stacks/2; ++i)
  {
    // std::cout<<r*sin((i+1)*(PI)/stacks)<<std::endl;
    draw_cylinder(r*cos(i*(PI)/stacks),r*cos((i+1)*(PI)/stacks),
      r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks),slices,color,true,buf);
    // glTranslatef(0,0,r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks));
    buf = buf * Mtranslate(0,0,r*sin((i+1)*(PI)/stacks)-r*sin((i)*(PI)/stacks));
  }
  glPopMatrix();
}
Beispiel #5
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display(){
	float cylinder_color_a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
	float cylinder_color_b[3][3] = {{252.0/255.0, 141.0/255.0, 89/255.0},
		{1, 1, 191/255.0}, {145/255.0, 207/255.0, 96/255.0}};

	//  Erase the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	//  Enable Z-buffering in OpenGL
	glEnable(GL_DEPTH_TEST);
	//  Undo previous transformations
	glLoadIdentity();
	//  Set view angle

	// MAKE the projection transformations after loading the identity matrix
	if (mode){
		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);
	}

	// cylinder one
	glPushMatrix();
	glRotatef(cylinder_rotation, 1, 0, 0);
	glRotatef(cylinder_rotation/0.5, 0, 1, 0);
	glScaled(0.9, 0.78, 0.4);
	draw_cylinder(0, 0, 0, 500, cylinder_color_a);
	glPopMatrix();

	// cylinder two
	glPushMatrix();
	glScaled(0.5, 0.5, 0.5);
	draw_cylinder(2, 2, 2, 500, cylinder_color_b);
	glPopMatrix();

	// house one
	glPushMatrix();
	draw_house(-2, -2, -2, cylinder_color_b);
	glPopMatrix();

	// house two
	glPushMatrix();
	draw_house(0.5, -.8, -2, cylinder_color_b);
	glPopMatrix();

	// house 3
	glPushMatrix();
	draw_house(house_x, house_y, house_z, cylinder_color_a);
	glPopMatrix();

	//  White
	glColor3f(1,1,1);
	//  Draw axes
	if (axes){
		glBegin(GL_LINES);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(dim-0.5,0.0,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,dim-0.5,0.0);
		glVertex3d(0.0,0.0,0.0);
		glVertex3d(0.0,0.0,dim-0.5);
		glEnd();
		//  Label axes
		glRasterPos3d(dim-0.5,0.0,0.0);
		Print("X");
		glRasterPos3d(0.0,dim-0.5,0.0);
		Print("Y");
		glRasterPos3d(0.0,0.0,dim-0.5);
		Print("Z");
	}

	//  Five pixels from the lower left corner of the window
	glWindowPos2i(5,5);
	//  Print the text string
	Print("Angle=%d,%d  Dim=%.1f FOV=%d Projection=%s",th,ph,dim,fov,mode?"Perpective":"Orthogonal");
	//  Render the scene
	glFlush();
	//  Make the rendered scene visible
	glutSwapBuffers();
}
Beispiel #6
0
static void draw_house(double x, double y, double z, float colors[3][3]){
	draw_cylinder(x, y, z, 5, colors);
}
Beispiel #7
0
//draw the main object
void draw_man(){

  stacks.push(modelM);


  // modelM *= Mtranslate(0,-ii,0);
  modelM *= Mrotate(angle_whole,0,0,1);
  // modelM *= Mtranslate(0,ii,0);

  //modelM *= Mtranslate(0,-ii,0);
  //modelM = modelM*Mrotate(angle_whole,0,0,1);
  //modelM *= Mtranslate(0,ii,0);
  //ii=0;
  stacks.push(modelM);


  //Head and nose
  modelM = modelM*Mrotate(angle_head,0,0,1);
  modelM = modelM*Mtranslate(0,0,5);
  draw_sphere(1.5,12,12,c1,modelM);//head
  modelM = modelM*Mtranslate(0,-2,0);

  modelM = modelM*Mtranslate(0,1,0);
  modelM = modelM*Mrotate(angle_nose,0,0,1);
  modelM = modelM*Mtranslate(0,-1,0);
  modelM = modelM*Mrotate(90,1,0,0);
  draw_cylinder(0.2,0.1,1,12,c4,false,modelM);//nose
  //draw_cube(1,c2,modelM);
  

  //Left arm and body
  modelM=stacks.top();

  modelM = modelM * Mtranslate(0,0,2);
  draw_cylinder(2,1,4,12,c6,false,modelM);//Body

  modelM = modelM * Mtranslate(-2,0,1);
  modelM = modelM*Mrotate(90,0,1,0);

  modelM = modelM*Mtranslate(0,0,1);
  modelM = modelM*Mrotate(angle_larm,0,1,0);
  modelM = modelM*Mtranslate(0,0,-1);

  draw_cylinder(0.5,0.8,2,12,c3,false,modelM);//L Arm

  modelM = modelM * Mtranslate(0,0,-1);
  draw_sphere(0.5,12,12,c1,modelM); // L connector

  // modelM = modelM*Mtranslate(0,0,1);
  modelM = modelM*Mrotate(angle_lhand,0,1,0);
  // modelM = modelM*Mtranslate(0,0,-1);

  modelM = modelM * Mtranslate(0,0,-1);
  draw_cylinder(0.1,0.5,2,12,c5,false,modelM);

  //Right arm
  modelM=stacks.top();

  modelM = modelM*Mtranslate(2,0,3);
  modelM = modelM*Mrotate(-90,0,1,0);

  modelM = modelM*Mtranslate(0,0,1);
  modelM = modelM*Mrotate(angle_rarm,0,1,0);
  modelM = modelM*Mtranslate(0,0,-1);

  draw_cylinder(0.5,0.8,2,12,c3,false,modelM);//R Arm

  modelM = modelM * Mtranslate(0,0,-1);
  draw_sphere(0.5,12,12,c1,modelM); // R connector

  // modelM = modelM*Mtranslate(0,0,1);
  modelM = modelM*Mrotate(angle_rhand,0,1,0);
  // modelM = modelM*Mtranslate(0,0,-1);

  modelM = modelM * Mtranslate(0,0,-1);
  draw_cylinder(0.1,0.5,2,12,c5,false,modelM);

  //legs
  modelM=stacks.top();
  modelM = modelM*Mtranslate(1,0,-2);
  modelM = modelM*Mscale(0.7,0.7,4);
  draw_cube(1,c3,modelM);

  modelM=stacks.top();
  modelM = modelM*Mtranslate(-1,0,-2);
  modelM = modelM*Mscale(0.7,0.7,4);
  draw_cube(1,c3,modelM);



  stacks.pop();
  modelM=stacks.top();
  stacks.pop();
}
Beispiel #8
0
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display(){
	const double len=4.5;  //  Length of axes

	float cylinder_color_a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
	float cylinder_color_b[3][3] = {{252.0/255.0, 141.0/255.0, 89/255.0},
		{1, 1, 191/255.0}, {145/255.0, 207/255.0, 96/255.0}};


	//  Erase the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	//  Enable Z-buffering in OpenGL
	glEnable(GL_DEPTH_TEST);
	//  Undo previous transformations
	glLoadIdentity();
	//  Set view angle
	glRotatef(ph,1,0,0);
	glRotatef(th,0,1,0);

	// cylinder one
	glPushMatrix();
	glRotatef(cylinder_rotation, 1, 0, 0);
	glRotatef(cylinder_rotation/0.5, 0, 1, 0);
	glScaled(0.9, 0.78, 0.4);
	draw_cylinder(0, 0, 0, 500, cylinder_color_a);
	glPopMatrix();

	// cylinder two
	glPushMatrix();
	glScaled(0.5, 0.5, 0.5);
	draw_cylinder(2, 2, 2, 500, cylinder_color_b);
	glPopMatrix();

	// house one
	glPushMatrix();
	draw_house(-2, -2, -2, cylinder_color_b);
	glPopMatrix();

	// house two
	glPushMatrix();
	draw_house(0.5, -.8, -2, cylinder_color_b);
	glPopMatrix();


	glPushMatrix();
	draw_house(house_x, house_y, house_z, cylinder_color_a);
	glPopMatrix();

	//  White
	glColor3f(1,1,1);
	//  Draw axes
	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");
	}
	//  Five pixels from the lower left corner of the window
	glWindowPos2i(5,5);
	//  Print the text string
	Print("Angle=%d,%d",th,ph);
	//  Render the scene
	glFlush();
	//  Make the rendered scene visible
	glutSwapBuffers();
}
Beispiel #9
0
static void cylinder_layer_update_proc(Layer *cylinder_layer, GContext *ctx) {
  CylinderState *state = layer_get_data(cylinder_layer);
  GRect bounds = layer_get_bounds(cylinder_layer);
  draw_cylinder(state, bounds, ctx);
}