void draw_diamond() { glColor3fv(colors[COLOR_GREEN]); glPushMatrix(); draw_pyramid(); glPopMatrix(); glPushMatrix(); glRotatef(180, 1, 0, 0); draw_pyramid(); glPopMatrix(); }
void glut_display(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,1.0,0.1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(Distance * cos(Angle2) * sin(Angle1), Distance * sin(Angle2), Distance * cos(Angle2) * cos(Angle1), 0.0,0.0,0.0,0.0,1.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glPushMatrix(); glTranslatef(-1.0,3.0,0.0); glRotatef(-30,0.0,0.0,1.0); glColor3f(1.0,1.0,1.0); glutWireTeapot(1.0); glPopMatrix(); glPushMatrix(); glTranslatef(0.0,-2.0,0.0); draw_pyramid(); glPopMatrix(); glFlush(); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); }
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(); } }
void glut_display(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0,1.0,0.1,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(Distance * cos(Angle2) * sin(Angle1), Distance * sin(Angle2), Distance * cos(Angle2) * cos(Angle1), 0.0,0.0,0.0,0.0,1.0,0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); draw_pyramid(); glFlush(); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); }
void glut_display(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, 1.0, 0.1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(g_distance * cos(g_angle2) * sin(g_angle1), g_distance * sin(g_angle2), g_distance * cos(g_angle2) * cos(g_angle1), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); GLfloat lightpos[]={static_cast<GLfloat>(5 * cos(g_angle4) * sin(g_angle3)), static_cast<GLfloat>(5 * sin(g_angle4)), static_cast<GLfloat>(5 * cos(g_angle4) * cos(g_angle3)), 1.0}; GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glPushMatrix(); glTranslatef(5 * cos(g_angle4) * sin(g_angle3), 5 * sin(g_angle4), 5 * cos(g_angle4) * cos(g_angle3)); glutSolidSphere(0.2, 50, 50); glPopMatrix(); glPushMatrix(); glTranslatef(5 * cos(g_angle4) * sin(g_angle4), 5 * sin(g_angle4), 5 * cos(g_angle4) * cos(g_angle4)); glutSolidSphere(0.2, 50, 50); glPopMatrix(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION,lightpos); glLightfv(GL_LIGHT0, GL_DIFFUSE,diffuse); GLfloat lightpos2[]={static_cast<GLfloat>(10 * cos(g_angle4) * sin(g_angle4)), static_cast<GLfloat>(10 * sin(g_angle4)), static_cast<GLfloat>(10 * cos(g_angle4) * cos(g_angle4)), 1.0}; glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_POSITION,lightpos2); glLightfv(GL_LIGHT1, GL_DIFFUSE,diffuse); glPushMatrix(); glTranslatef(0.0, -2.0, 0.0); draw_plane(); glPopMatrix(); glPushMatrix(); glScalef(1.0, 2.0, 1.0); draw_pyramid(); glPopMatrix(); glFlush(); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); }
void render_scene(void) { float angle = timer.GetElapsedSeconds() * 3.14f / 10.0f; location[0] = -8.0f * cos(angle / 2.0f); location[1] = -8.0f * sin(angle / 2.0f); location[2] = 5.0f; light_0.position[0] = 10.0f * cos(-angle); light_0.position[1] = 10.0f * sin(-angle); light_0.position[2] = 3.0f; look_at(camera_frame, location, target, up_dir); camera_frame.GetCameraMatrix(camera_matrix); p_stack.LoadMatrix(view_frustum.GetProjectionMatrix()); mv_stack.LoadMatrix(camera_matrix); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //-- glUseProgram(shader_color); mv_stack.PushMatrix(); mv_stack.Translate(light_0.position[0], light_0.position[1], light_0.position[2]); mv_stack.Scale(0.25f, 0.25f, 0.25f); glUniformMatrix4fv(mvp_matrix_location_shader_color, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); draw_light(); mv_stack.PopMatrix(); //-- glUseProgram(shader_light); glUniformMatrix3fv(normal_matrix_location, 1, GL_FALSE, geometry_pipeline.GetNormalMatrix()); glUniformMatrix4fv(v_matrix_location, 1, GL_FALSE, camera_matrix); glUniform3fv(intensity_ambient_component_location, 1, intensity_ambient_component); glUniform3fv(light_0_position_location, 1, light_0.position); glUniform3fv(light_0_intensity_diffuse_location, 1, light_0.intensity_diffuse); glUniform3fv(light_0_intensity_specular_location, 1, light_0.intensity_specular); glUniform3fv(light_0_attenuation_location, 1, light_0.attenuation); glUniform1f(material_0_ka_location, material_0.ka); glUniform1f(material_0_kd_location, material_0.kd); glUniform1f(material_0_ks_location, material_0.ks); glUniform1f(material_0_alpha_location, material_0.alpha); //-- glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix()); draw_grid(); draw_floor(); //-- for(int i = -20; i < 20; i += 5) { for(int j = -20; j < 20; j += 5) { mv_stack.PushMatrix(); mv_stack.Translate((float)i, (float)j, 0.0f); glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix()); draw_pyramid(); mv_stack.PopMatrix(); } } //-- mv_stack.PushMatrix(); mv_stack.Translate(0.0f, 0.0f, 4.0f); glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix()); draw_icosahedron(20, vertices_icosahedron, faces_icosahedron); mv_stack.PopMatrix(); //-- mv_stack.PushMatrix(); mv_stack.Translate(-5.0f, 0.0f, 4.0f); glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix()); draw_icosahedron_smooth(20, vertices_icosahedron, faces_icosahedron); mv_stack.PopMatrix(); //-- glUseProgram(0); glutSwapBuffers(); glutPostRedisplay(); }
void draw() const //draw the triangle { shape::draw(); draw_pyramid(xCo, yCo, height); }
void glut_display(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, 1.0, 0.1, 100); // if(g_rotate_self) { // glRotatef(g_angle1, 0.0, 1.0, 0.0); // glRotatef(g_angle2, -1.0, 0.0, 0.0); // } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if(g_rotate_self) { gluLookAt(g_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } else { if(cos(g_angle2) > 0){ gluLookAt(g_distance * cos(g_angle2) * sin(g_angle1), g_distance * sin(g_angle2), g_distance * cos(g_angle2) * cos(g_angle1), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } else { gluLookAt(g_distance * cos(g_angle2) * sin(g_angle1), g_distance * sin(g_angle2), g_distance * cos(g_angle2) * cos(g_angle1), 0.0, 0.0, 0.0, 0.0, -1.0, 0.0); } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST);//これをコメントアウトすると、デプス方向に描画ができなくなり、最終的に描画されたものに上書きされてしまうじょうたいになる。 //この間に図形のマトリクスに対する操作を書き込む //glPushMatrix(); if(g_rotate_self){ /*float rot[2] = {0.0,1.0}; rot[0] = cos(20*g_angle1) * rot[0] + sin(20*g_angle1) * rot[1]; rot[1] = -sin(20*g_angle1) * rot[0] + cos(20*g_angle1) * rot[1]; glRotatef(g_angle1 * 20, 0.0, 1.0, 0.0);//左右回転。この回転軸も回してあげる必要がある glRotatef(-g_angle2 * 20, 0.0, 0.0, -1.0);//上下回転*/ float verticle_vec[2] = {-g_angle2, g_angle1}; glRotatef(20*sqrt(g_angle2*g_angle2 + g_angle1*g_angle1), verticle_vec[0]/*sin(g_angle1)*/, -verticle_vec[1], verticle_vec[0]/*cos(g_angle1)*/); } switch(g_display_mode){ case 0: draw_pyramid(); break; case 1: draw_cube(); break; } //glPopMatrix(); // if(g_rotate_self){ // glRotatef(g_angle1, 0.0, 1.0, 0.0); // glRotatef(g_angle2, -1.0, 0.0, 0.0); // } glFlush(); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); }