/** * draw_teapot: * @solid: TRUE if the teapot should be solid. * @scale: relative size of the teapot. * * Renders a teapot. * Both surface normals and texture coordinates for the teapot are generated. * The teapot is generated with OpenGL evaluators. * **/ void draw_teapot (gboolean solid, double scale) { if (solid) teapot (7, scale, GL_FILL); else teapot (10, scale, GL_LINE); }
//==================================================== // TeapotRenderComponent definitions //==================================================== shared_ptr<SceneNode> TeapotRenderComponent::CreateSceneNode() { // get the transform shared_ptr<TransformComponent> pTransformComponent = MakeStrongPtr(m_pOwner->GetComponent<TransformComponent>(TransformComponent::g_Name)); if (pTransformComponent) { WeakBaseRenderComponentPtr weakThis(this); switch (WindowsApp::GetRendererImpl()) { case WindowsApp::Renderer_D3D9: return shared_ptr<SceneNode>(CB_NEW D3DTeapotMeshNode9(m_pOwner->GetId(), weakThis, "Effects\\Main.fx", RenderPass_Object, &pTransformComponent->GetTransform())); case WindowsApp::Renderer_D3D11: { Mat4x4 rot90; rot90.BuildRotationY(-CB_PI / 2.0f); shared_ptr<SceneNode> parent(CB_NEW SceneNode(m_pOwner->GetId(), weakThis, RenderPass_Object, &pTransformComponent->GetTransform())); shared_ptr<SceneNode> teapot(CB_NEW D3DTeapotMeshNode11(INVALID_GAMEOBJECT_ID, weakThis, RenderPass_Object, &rot90)); parent->AddChild(teapot); return parent; } default: CB_ERROR("Unknown Renderer Implementation in TeapotRenderComponent"); } } return shared_ptr<SceneNode>(); }
/*! Un premier lot d'objets : 1 table, 1 coupe de fruits, 3 chaises !*/ static void lot1(void) { glPushMatrix(); /* une table */ table(1); /* une theière, posée sur la table */ glPushMatrix(); glTranslatef(0.,0.,2.); glRotatef(120.,0.,0.,1.); teapot(); glPopMatrix(); /* 4 chaises */ glPushMatrix(); glTranslatef(-1.5,0.,0.); Material(rouge,0.25,0.5,0.0,1.0,1.); chaise(0); glPopMatrix(); glPushMatrix(); glTranslatef(0.,-0.8,0.); glRotatef(70.,0.,0.,1.); Material(vert,0.25,0.5,0.0,1.0,1.); chaise(1); glPopMatrix(); glPushMatrix(); glTranslatef(0.,+0.8,0.); glRotatef(-80.,0.,0.,1.); Material(bleu,0.25,0.5,0.0,1.0,1.); chaise(0); glPopMatrix(); glPushMatrix(); glTranslatef(+1.5,0.,0.); glRotatef(170.,0.,0.,1.); Material(cyan,0.25,0.5,0.0,1.0,1.); chaise(1); glPopMatrix(); /* 4 verres */ Material(glass,0.6,0.85,0.5,1.0,0.5); glPushMatrix(); glTranslatef(-1.4,0.,+2.01); verre(); glPopMatrix(); glPushMatrix(); glTranslatef(0.,-0.75,+2.01); verre(); glPopMatrix(); glPushMatrix(); glTranslatef(0.,+0.75,+2.01); verre(); glPopMatrix(); glPushMatrix(); glTranslatef(+1.4,0.,+2.01); verre(); glPopMatrix(); glPopMatrix(); }
void render() { sphere(); teapot(); cone(); torus(); tetrahedron(); }
int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowPosition(100,100); glutInitWindowSize(600,600); glutCreateWindow("Teapot"); init(); Teapot teapot(0.4); teapot.setCurrentPrimitive(&teapot); glutDisplayFunc(teapot.display); glutIdleFunc(teapot.idle); glutMainLoop(); return 0; }
void GeometryRendererDemo::onProcessorValidated(AbstractProcessor* processor) { if (processor == &_geometryReader) { // update camera ScopedTypedData<IHasWorldBounds> lv(*_dataContainer, _geometryReader.p_targetImageID.getValue()); ScopedTypedData<IHasWorldBounds> teapot(*_dataContainer, "teapot"); ScopedTypedData<IHasWorldBounds> cube(*_dataContainer, "cube"); if (lv != 0 && teapot != 0) { cgt::Bounds unionBounds; unionBounds.addVolume(lv->getWorldBounds()); unionBounds.addVolume(teapot->getWorldBounds()); unionBounds.addVolume(cube->getWorldBounds()); _tcp.reinitializeCamera(unionBounds); } } }
static void initdlists(void) { GLUquadricObj *lcone,*lbase; GLfloat plane[4]; GLfloat v0[3]={0.0,0.0,0.0}; GLfloat v1[3]={1.0,0.0,0.0}; GLfloat v2[3]={0.0,1.0,0.0}; findplane(plane,v0,v1,v2); shadowmatrix(baseshadow,plane,lightpos); teapotdlist=glGenLists(1); glNewList(teapotdlist,GL_COMPILE); glRotatef(90.0,1.0,0.0,0.0); glCullFace(GL_FRONT); glBindTexture(GL_TEXTURE_2D,t2id); teapot(TEAPOTRES,0.6,GL_FILL); glCullFace(GL_BACK); glEndList(); basedlist=glGenLists(1); glNewList(basedlist,GL_COMPILE); drawbase(); glEndList(); lightdlist=glGenLists(1); glNewList(lightdlist,GL_COMPILE); glDisable(GL_LIGHTING); lcone=gluNewQuadric(); lbase=gluNewQuadric(); glRotatef(45.0,0.0,1.0,0.0); glColor3f(1.0,1.0,1.0); glCullFace(GL_FRONT); gluDisk(lbase,0.0,0.2,12.0,1.0); glCullFace(GL_BACK); glColor3f(0.5,0.0,0.0); gluCylinder(lcone,0.2,0.0,0.5,12,1); gluDeleteQuadric(lcone); gluDeleteQuadric(lbase); glEnable(GL_LIGHTING); glEndList(); }
int main() { Bitmap bitmap(640, 480); Camera cam; cam.zoom = 1, cam.focus = 10000, cam.height = 100; BezObj teapot(INPUT); teapot.move(P3(0, -100, -1000)); teapot.rotateZ(-45); teapot.rotateX(-45); teapot.split(2); cam.shot(teapot, bitmap); ImageProcessor ip(&bitmap); ip.rerange( P2(-320, -240), P2(0, 0) ); ip.GaussianBlur(2); bitmap.save(OUTPUT); system(OUTPUT); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) // HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow { config = _CONFIG(1024, 768, {0.0f,1.2f,10.f}, {}, 60.f, 0.01f, 40.f); _WINDOW wnd = _WINDOW(hInstance, "Main Window"); if (wnd.isInitialized()) { //load file Model teapot(getFilenameFromCurrentDirectory("teapot.obj"), {0,3,1}, {}, {.5f, .5f, .5f}); Model ball(getFilenameFromCurrentDirectory("sphere.obj"), {}, {}, {.8f,.8f,.8f}); float rotOfTeapot[3] = {0.0f, 0.0f, 0.0f}; while (true) { while (PeekMessage(&wnd.msg, nullptr, 0, 0, PM_REMOVE) > 0) { TranslateMessage(&wnd.msg); DispatchMessage(&wnd.msg); } //Background DrawWindowElements::ClearZBuffer(); DrawWindowElements::FillRectangle(MyColor::LIGHTBLUE); //DrawWindowElements::DrawGrid(32, MyColor::BLACK); //Setting visual and camera DrawCommon::SetProjection(); DrawCommon::SetViewMatrix(); //Drawing models drawTeapot(teapot, rotOfTeapot); drawBalls(ball); DrawMyWindow(wnd.hwndMain); Controller::OverlayHUD(wnd.hwndMain); Sleep(20); if (wnd.msg.message == WM_QUIT) return EXIT_SUCCESS; } } return EXIT_FAILURE; }
void APIENTRY glutWireTeapot(GLdouble scale) { teapot(10, scale, GL_LINE); }
/* CENTRY */ void APIENTRY glutSolidTeapot(GLdouble scale) { teapot(14, scale, GL_FILL); }
/* CENTRY */ void GLUTAPIENTRY glutSolidTeapot(GLdouble scale) { teapot(7, scale, GL_FILL); }
void VolumeRender::generate() { double start_time, end_time, dt; start_time = glfwGetTime(); // Load tree int32_t tree_size = 0; tree_data = 0; // Load from file if (_scene == 0) { tree_size = rendering::read_full_file_binary(_treeFilename, &tree_data); if (tree_size == 0) { fprintf(stderr, "Invalid tree file: %s\n", _treeFilename); exit(1); } } else { char filename_buffer[1024]; sprintf(filename_buffer, "scene%d.tree.%d", _scene, _depth); FILE* file = fopen(filename_buffer, "rb"); if (file != nullptr) { // Load tree printf("Loading file %s\n", filename_buffer); fclose(file); tree_size = rendering::read_full_file_binary(filename_buffer, &tree_data); if (tree_size == 0) { fprintf(stderr, "Invalid tree file: %s\n", filename_buffer); exit(1); } } else { // Generate printf("Generating scene for the first time, please wait..\n"); // Generate from sphere if (_scene == 1) { tree_size = rendering::genOctreeSphere((int32_t**)&tree_data, _depth, glm::vec3(0.5f, 0.5f, 0.5f), 0.4f); } // Generate from miku mesh if (_scene == 2) { if (_mesh.load("miku.md2")) { // Rotate mesh to right rotation (md2s are messed up like that..) glm::mat4 rotation = glm::rotate(180.0f, glm::vec3(0, 0, 1.0f)); rotation = glm::rotate(rotation, 90.0f, glm::vec3(0, 1.0f, 0)); _mesh.transform(rotation); tree_size = genOctreeMesh((int32_t**)&tree_data, _depth, &_mesh); } } // r = 1.5 sphere with embedded r = 1 sphere if (_scene == 3) { if (_mesh.load("miku.md2")) { // Rotate mesh to right rotation (md2s are messed up like that..) glm::mat4 rotation = glm::rotate(180.0f, glm::vec3(0, 0, 1.0f)); rotation = glm::rotate(rotation, 90.0f, glm::vec3(0, 1.0f, 0)); _mesh.transform(rotation); // Get min, max and func for octree generation glm::vec3 overall_min = *_mesh.getMin(); glm::vec3 overall_max = *_mesh.getMax(); overall_max += (overall_max - overall_min); // Make cube around bounds glm::vec3 extents = (overall_max - overall_min) * 0.5f; glm::vec3 centre = overall_min + extents; float greatest_extent = std::max(std::max(extents.x, extents.y), extents.z); extents.x = greatest_extent; extents.y = greatest_extent; extents.z = greatest_extent; overall_min = centre - extents; overall_max = centre + extents; // Sphere position glm::vec3 sphere_pos = centre; sphere_pos.x += extents.x * 0.5f; float sphere_radius = 10.0f; // Test function auto test_func = [&] (glm::vec3 min, glm::vec3 max, raw_attachment_uncompressed& shading_attributes) { glm::vec3 half_size = 0.5f * (max - min); glm::vec3 centre = min + half_size; float half_size_one_axis = half_size.x; //bool sphere_intersect = cubeSphereSurfaceIntersection(centre, half_size_one_axis, sphere_pos, sphere_radius); bool sphere_intersect = boxSphereIntersection(min, max, sphere_pos, sphere_radius); if (sphere_intersect) { // This is not normalised to save generation time // it is normalised later in the GPU anyway after being unpacked shading_attributes.normal = sphere_pos - centre; shading_attributes.colour = glm::vec4(1.0f, 1.0f, 1.0f, 0.5f); shading_attributes.reflectivity = 1.0f; shading_attributes.refractive_index = 1.5f; float distFromCentre = glm::length(shading_attributes.normal); if (distFromCentre < 0.5f * sphere_radius) shading_attributes.refractive_index = 1.0f; return true; } else { bool mesh_intersect = meshAABBIntersect(&_mesh, min, max, shading_attributes); if (mesh_intersect) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 0.0f; return true; } } return false; }; point_test_func func(test_func); // Generate octree tree_size = genOctree((int32_t**)&tree_data, _depth, func, overall_min, overall_max); } } // r = 1.5 sphere with hollow sphere (should be the same as above) if (_scene == 4) { if (_mesh.load("miku.md2")) { // Rotate mesh to right rotation (md2s are messed up like that..) glm::mat4 rotation = glm::rotate(180.0f, glm::vec3(0, 0, 1.0f)); rotation = glm::rotate(rotation, 90.0f, glm::vec3(0, 1.0f, 0)); _mesh.transform(rotation); // Get min, max and func for octree generation glm::vec3 overall_min = *_mesh.getMin(); glm::vec3 overall_max = *_mesh.getMax(); overall_max += (overall_max - overall_min); // Make cube around bounds glm::vec3 extents = (overall_max - overall_min) * 0.5f; glm::vec3 centre = overall_min + extents; float greatest_extent = std::max(std::max(extents.x, extents.y), extents.z); extents.x = greatest_extent; extents.y = greatest_extent; extents.z = greatest_extent; overall_min = centre - extents; overall_max = centre + extents; // Sphere position glm::vec3 sphere_pos = centre; sphere_pos.x += extents.x * 0.5f; float sphere_radius = 10.0f; // Test function auto test_func = [&] (glm::vec3 min, glm::vec3 max, raw_attachment_uncompressed& shading_attributes) { glm::vec3 half_size = 0.5f * (max - min); glm::vec3 centre = min + half_size; float half_size_one_axis = half_size.x; //bool sphere_intersect = cubeSphereSurfaceIntersection(centre, half_size_one_axis, sphere_pos, sphere_radius); bool sphere_intersect = boxSphereIntersection(min, max, sphere_pos, sphere_radius); if (sphere_intersect) { // This is not normalised to save generation time // it is normalised later in the GPU anyway after being unpacked shading_attributes.normal = sphere_pos - centre; shading_attributes.colour = glm::vec4(1.0f, 1.0f, 1.0f, 0.5f); shading_attributes.reflectivity = 1.0f; shading_attributes.refractive_index = 1.5f; float distFromCentre = glm::length(shading_attributes.normal); if (distFromCentre < 0.5f * sphere_radius) return false; return true; } else { bool mesh_intersect = meshAABBIntersect(&_mesh, min, max, shading_attributes); if (mesh_intersect) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 0.0f; return true; } } return false; }; point_test_func func(test_func); // Generate octree tree_size = genOctree((int32_t**)&tree_data, _depth, func, overall_min, overall_max); } } // Generate from mesh if (_scene == 5) { Mesh teapot("teapot.obj", true); Mesh checkerboard("checkerboard.obj", true); // Lift teapot off checkerboard a bit so they don't intersect glm::mat4 translation = glm::translate(glm::vec3(0.0f, 0.1f, 0.0f)); glm::mat4 rotation = glm::rotate(180.0f, glm::vec3(0, 0, 1.0f)); checkerboard.transform(translation * rotation); teapot.transform(rotation); // Get min, max and func for octree generation glm::vec3 overall_min = *teapot.getMin(); glm::vec3 overall_max = *teapot.getMax(); overall_max += (overall_max - overall_min); // Make cube around bounds glm::vec3 extents = (overall_max - overall_min) * 0.5f; glm::vec3 centre = overall_min + extents; float greatest_extent = std::max(std::max(extents.x, extents.y), extents.z); extents.x = greatest_extent; extents.y = greatest_extent; extents.z = greatest_extent; overall_min = centre - extents; overall_max = centre + extents; // Test function auto test_func = [&] (glm::vec3 min, glm::vec3 max, raw_attachment_uncompressed& shading_attributes) { if (meshAABBIntersect(&checkerboard, min, max, shading_attributes)) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 0.0f; return true; } if (meshAABBIntersect(&teapot, min, max, shading_attributes)) { shading_attributes.colour.a = 0.3f; shading_attributes.reflectivity = 0.5f; return true; } return false; }; point_test_func func(test_func); // Generate octree tree_size = genOctree((int32_t**)&tree_data, _depth, func, overall_min, overall_max); } // transparent and reflective boxes on checkerboard if (_scene == 6) { Mesh checkerboard("checkerboard.obj", true); // The cube should have flat normals instead of smooth Mesh box1("cube.obj", true, aiProcess_GenNormals); Mesh box2("cube.obj", true, aiProcess_GenNormals); // Rotate checkerboard glm::mat4 rotation = glm::rotate(180.0f, glm::vec3(0, 0, 1.0f)); checkerboard.transform(rotation); // Scale and position box glm::mat4 translation = glm::translate(glm::vec3(0, 1.0f, 0)); glm::mat4 scale = glm::scale(glm::vec3(0.25f)); glm::mat4 box_transform = scale * translation; box1.transform(scale); box2.transform(scale); // Get min, max and func for octree generation glm::vec3 overall_min = *checkerboard.getMin(); glm::vec3 overall_max = *checkerboard.getMax(); overall_max += (overall_max - overall_min); // Make cube around bounds glm::vec3 extents = (overall_max - overall_min) * 0.5f; glm::vec3 centre = overall_min + extents; float greatest_extent = std::max(std::max(extents.x, extents.y), extents.z); extents.x = greatest_extent; extents.y = greatest_extent; extents.z = greatest_extent; overall_min = centre - extents; overall_max = centre + extents; // Test function auto test_func = [&] (glm::vec3 min, glm::vec3 max, raw_attachment_uncompressed& shading_attributes) { if (meshAABBIntersect(&checkerboard, min, max, shading_attributes)) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 0.0f; return true; } if (meshAABBIntersect(&box1, min, max, shading_attributes)) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 1.0f; return true; } return false; }; point_test_func func(test_func); // Generate octree tree_size = genOctree((int32_t**)&tree_data, _depth, func, overall_min, overall_max); } // Reflective inverted box with teapot inside if (_scene == 7) { // The cube should have flat normals instead of smooth Mesh teapot("teapot.obj", true); Mesh box1("inverted_cube.obj", true, aiProcess_GenNormals); teapot.transform(glm::scale(glm::vec3(0.2f)) * glm::rotate(180.0f, glm::vec3(0.0f, 0.0f, 1.0f))); // Get min, max and func for octree generation glm::vec3 overall_min = *box1.getMin(); glm::vec3 overall_max = *box1.getMax(); overall_max += (overall_max - overall_min); // Make cube around bounds glm::vec3 extents = (overall_max - overall_min) * 0.5f; glm::vec3 centre = overall_min + extents; float greatest_extent = std::max(std::max(extents.x, extents.y), extents.z); extents.x = greatest_extent; extents.y = greatest_extent; extents.z = greatest_extent; overall_min = centre - extents; overall_max = centre + extents; // Test function auto test_func = [&] (glm::vec3 min, glm::vec3 max, raw_attachment_uncompressed& shading_attributes) { glm::vec3 aabb_extents = (max - min) * 0.5f; glm::vec3 aabb_centre = aabb_centre + min; if (meshAABBIntersect(&box1, min, max, shading_attributes)) { shading_attributes.colour.a = 1.0f; shading_attributes.reflectivity = 1.0f; return true; } if (meshAABBIntersect(&teapot, min, max, shading_attributes)) { shading_attributes.colour = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); shading_attributes.reflectivity = 0.0f; return true; } return false; }; point_test_func func(test_func); // Generate octree tree_size = genOctree((int32_t**)&tree_data, _depth, func, overall_min, overall_max); } // Write custom generation to file if (_saveTrees) { printf("Writing %s...\n", filename_buffer); file = fopen(filename_buffer, "wb"); if (file == nullptr) { fprintf(stderr, "Failed to open file for writing: %s\n", filename_buffer); } else { fwrite(tree_data, tree_size, sizeof(char), file); fclose(file); } } } } // Calculate time to load/generate end_time = glfwGetTime(); dt = end_time - start_time; printf("Time to load/generate tree: %f\n", dt); printf("%.2fMB\n", tree_size / (1024.0f * 1024.0f)); // Reset timer start_time = glfwGetTime(); // Upload sphere to GPU gpuErrchk(cudaMalloc((void**)&_gpuTree, tree_size)); gpuErrchk(cudaMemcpy(_gpuTree, tree_data, tree_size, cudaMemcpyHostToDevice)); // Calculate time to upload end_time = glfwGetTime(); dt = end_time - start_time; printf("Time to upload tree: %f\n", dt); printf("%.2fMB\n", tree_size / (1024.0f * 1024.0f)); // Free CPU memory //free(tree_data); }
// Create Objects void TestScene::SetupObjects() { spObject sun(new Object); sun->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128))); sun->GetTransform().SetScale(Vector3(2.f, 2.f, 2.f)); Texture sunTexture; LoadTexture(sunTexture, "textures/texture_sun.png"); sun->GetVO()->GetTexture() = sunTexture; sun->SetGLMode(GL_TRIANGLES); sun->EnableTexture(); sun->SetName(L"Sun"); objects.push_back(sun); objectMap.insert(std::make_pair(sun->GetName(), sun)); spObject world(new Object); world->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128))); world->GetTransform().SetPosition(Vector3(5.f, 0.f, 0.f)); Texture worldTexture; LoadTexture(worldTexture, "textures/4kworld.png"); world->GetVO()->GetTexture() = worldTexture; world->SetGLMode(GL_TRIANGLES); world->EnableTexture(); world->SetName(L"Earth"); world->SetParent(sun.Get(), TransformInheritance(true, false, true, false)); objects.push_back(world); objectMap.insert(std::make_pair(world->GetName(), world)); spObject clouds(new Object); clouds->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128))); clouds->GetTransform().SetScale(Vector3(1.01f, 1.01f, 1.01f)); Texture cloudTexture; LoadTexture(cloudTexture, "textures/clouds.png"); clouds->GetVO()->GetTexture() = cloudTexture; clouds->SetGLMode(GL_TRIANGLES); clouds->EnableTexture(); clouds->EnableTransparency(); clouds->SetName(L"Clouds"); clouds->SetParent(world.Get(), TransformInheritance(true, false, true, false)); objects.push_back(clouds); objectMap.insert(std::make_pair(clouds->GetName(), clouds)); //spObject disc(new Object); //disc->SetVO(new PrimitiveDisc(64)); //Texture discTexture; //LoadTexture(discTexture, "crate.png"); //disc->GetVO()->GetTexture() = discTexture; //disc->SetGLMode(GL_TRIANGLE_FAN); //disc->GetTransform().SetPosition(Vector3(2.5f, 0.0f, 0.0f)); //disc->EnableTexture(); //disc->SetName(L"Disc"); //objects.push_back(disc); spObject moon(new Object); moon->SetVO(MakeShareable(new PrimitiveUVSphere(256, 128))); moon->GetTransform().SetScale(Vector3(0.27f, 0.27f, 0.27f)); moon->GetTransform().SetPosition(Vector3(0.f, 0.f, -2.2f)); Texture moonTexture; LoadTexture(moonTexture, "textures/moonmap1k.png"); moon->GetVO()->GetTexture() = moonTexture; moon->SetGLMode(GL_TRIANGLES); moon->EnableTexture(); moon->SetName(L"Moon"); moon->SetParent(world.Get(), TransformInheritance(true, false, true, false)); objects.push_back(moon); objectMap.insert(std::make_pair(moon->GetName(), moon)); spObject hst(new Object); hst->SetVO(MakeShareable(new Model)); static_cast<Model*>(hst->GetVO().Get())->Load("models/hst.obj", "textures/hst.png"); hst->GetTransform().SetScale(Vector3(0.0001f, 0.0001f, 0.0001f)); // This thing is yuge! hst->GetTransform().SetPosition(Vector3(-1.1f, 0.f, 0.f)); hst->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.25f, 0.25f, -0.25f))); hst->GetTransform().SetRotation(Rotation(0.f, Vector3(-0.2f, 0.8f, -0.2f))); hst->SetGLMode(GL_TRIANGLES); hst->SetName(L"HST"); hst->EnableTexture(); hst->SetParent(world.Get(), TransformInheritance(true, false, true, false)); objects.push_back(hst); objectMap.insert(std::make_pair(hst->GetName(), hst)); spObject iss(new Object); iss->SetVO(MakeShareable(new Model)); static_cast<Model*>(iss->GetVO().Get())->Load("models/iss.obj", "textures/iss.png"); iss->GetTransform().SetScale(Vector3(0.01f, 0.01f, 0.01f)); iss->GetTransform().SetPreRotation(Rotation(0.f, Vector3(0.f, 0.5f, 0.f))); iss->GetTransform().SetRotation(Rotation(0.f, Vector3(0.25f, 0.5f, 0.25f))); iss->GetTransform().SetPosition(Vector3(0.f, 0.f, 1.2f)); iss->SetGLMode(GL_TRIANGLES); iss->SetName(L"ISS"); iss->EnableTexture(); iss->SetParent(world.Get(), TransformInheritance(true, false, true, false)); objects.push_back(iss); objectMap.insert(std::make_pair(iss->GetName(), iss)); spObject teapot(new Object); teapot->SetVO(MakeShareable(new Model)); static_cast<Model*>(teapot->GetVO().Get())->Load("Models/teapot.obj", "textures/teapot.png"); teapot->GetTransform().SetPosition(Vector3(5.f, 5.f, -3.f)); teapot->GetTransform().SetPreRotation(Rotation(0.f, Vector3(1.f, 0.f, 0.f))); teapot->GetTransform().SetRotation(Rotation(0.f, Vector3(0.f, 0.f, 1.f))); teapot->GetTransform().SetScale(Vector3(0.05f, 0.05f, 0.05f)); teapot->SetGLMode(GL_TRIANGLES); teapot->SetName(L"Teapot"); teapot->EnableTexture(); teapot->SetParent(iss.Get(), TransformInheritance(true, true, true, false)); objects.push_back(teapot); objectMap.insert(std::make_pair(teapot->GetName(), teapot)); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 }; GLfloat mat_diffuse[] = { 0.5, 0.5, 0.5, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat lightintensity[] = { 1, 1, 1, 1.0 }; GLfloat lightposition[] = { 2.0, 2.0, 2.0, 1.0 }; GLfloat lightposition2[] = { -2.0, -2.0, -2.0, 1.0 }; glClearColor(0.5, 0.5, 0.5, 0.0); switch (back) { case 1: glClearColor(1.0, 0.0, 0.0, 0.0); break; case 2: glClearColor(0.0, 0.0, 1.0, 0.0); break; case 3: glClearColor(0.0, 1.0, 0.0, 0.0); break; case 4: glClearColor(0.0, 0.0, 0.0, 0.0); break; } glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, lightposition); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightintensity); glLightfv(GL_LIGHT0, GL_SPECULAR, mat_specular); glLightfv(GL_LIGHT1, GL_POSITION, lightposition2); glLightfv(GL_LIGHT1, GL_DIFFUSE, lightintensity); glLightfv(GL_LIGHT1, GL_SPECULAR, mat_specular); if (lightflag) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); if (orthoflag) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -20, 20); glMatrixMode(GL_MODELVIEW); } else { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10.0); glMatrixMode(GL_MODELVIEW); } glLoadIdentity(); gluLookAt(viewer[0], viewer[1], viewer[2], 0, 0, 0, 0, 1, 0); glRotatef(theta[0], 1, 0, 0); glRotatef(theta[1], 0, 1, 0); glRotatef(theta[2], 0, 0, 1); house(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); htop(h[0], h[1], h[2], h[3], h[4]); tv(t[0], t[1], t[2], t[3]); tvs(ts[0], ts[1], ts[2], ts[3], ts[4], ts[5], ts[6], ts[7]); grass(); sofa1(); rainwater(); sump(); table(); teapot(); tree(); compound(); window(); housefront(hfrt[0], hfrt[1], hfrt[2], hfrt[3]); fan(f[0], f[1], f[2], f[3], f[4], f[5]); fblade(fb[0], fb[1], fb[2], fb[3], fb[4], fb[5], fb[6], fb[7], fb[8], fb[9], fb[10], fb[11], fb[12], fb[13], fb[14], fb[15]); glEnable(GL_DEPTH_TEST); glutSwapBuffers(); }