void CubeViewer:: init() { // initialize parent TrackballViewer::init(); // create uniform cube m_meshes.push_back(createCube()); m_meshes.push_back(createCube()); m_meshes.push_back(createCube()); // move cube to (0,0,1) m_meshes[0]->scaleObject( Vector3(2,2,2) ); m_meshes[0]->translateWorld( Vector3(0,0,1) ); // make second smaller cube m_meshes[1]->rotateObject(Vector3(0,-1,0), M_PI); m_meshes[1]->translateWorld( Vector3(-1,1,0) ); m_meshes[1]->scaleObject( Vector3(0.6,0.6,0.6) ); // make a third even smaller cube m_meshes[2]->rotateAroundAxisObject(Vector3(0.2,0.4,-0.3), Vector3(0.6,0.4,1).normalize(), 5*M_PI/6); m_meshes[2]->translateObject( Vector3(-1,1,1) ); // set camera to look at world coordinate center set_scene_pos(Vector3(0.0, 0.0, 0.0), 2.0); // load cube shader m_cubeShader.create("cube.vs", "cube.fs"); }
void TrackballViewer:: init() { // OpenGL state glClearColor(1.0, 1.0, 1.0, 0.0); glColor4f(0.0, 0.0, 0.0, 1.0); glDisable( GL_DITHER ); glEnable( GL_DEPTH_TEST ); set_scene_pos(Vector3(0.0, 0.0, 0.0), 1.0); }
void WaterRenderer:: init() { // initialize parent TrackballViewer::init(); m_water = *createPlane(); m_skybox = *createCube(); waterColor = Vector4(0.1,0.2,0.3,0.5); watch.start(); startingTime = watch.stop(); // set camera to look at world coordinate center sceneSize = 4; set_scene_pos(Vector3(0.0, 0.0, 0.0), sceneSize); isRadial = false; amplitude1 = 0.01f; wavelength1 = 2.0f; speed1 = 1.0f; direction1 = Vector2(1, -1); amplitude2 = 1.0f; wavelength2 = 8.0f; speed2 = 2.0f; direction2 = Vector2(1, 0); amplitude3 = 0.5f; wavelength3 = 15.0f; speed3 = 1.0f; direction3 = Vector2(0, 1); amplitude4 = 15; wavelength4 = 30; speed4 = 3.0; direction4 = Vector2(1,0); time4 = -1000; generateCubeMap(); // load shaders m_skyShader.create("skybox.vs", "skybox.fs"); m_waterShader.create("water.vs", "water.fs"); }
void SolarViewer:: init() { // initialize parent TrackballViewer::init(); // set camera to look at world coordinate center set_scene_pos(Vector3(0.0, 0.0, 0.0), 2.0); // load mesh shader m_meshShaderDiffuse.create("diffuse.vs", "diffuse.fs"); m_meshShaderTexture.create("tex.vs","tex.fs"); m_showTextureStars = false; m_showTextureSun = false; m_showTextureEarth = false; m_showTextureMoon = false; currentTime = 0.0; isWatchOn = false; daysPerMiliSecond = 1 / 180.0; totalDaysElapsed = 0; m_geocentric = false; m_recSunlightInt = 1.0; m_moonScale = 50.0; m_earthScale = m_moonScale * 2.0; m_sunScale = m_moonScale * 5.0; m_starsScale = m_moonScale * 100.0; m_earthTrans = m_sunScale + 1250; m_moonTrans = m_earthTrans + m_earthScale + 200; m_starsScale = m_moonScale * 100.0; // Mercury m_PlanetsScale[0] = m_earthScale * 1.0; m_PlanetsTranslate[0] = m_earthTrans*0.4*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[0] = 88.0; // Venus m_PlanetsScale[1] = m_earthScale * 1.0; m_PlanetsTranslate[1] = m_earthTrans*0.7*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[1] = 224.0; // Mars m_PlanetsScale[2] = m_earthScale * 1.0; m_PlanetsTranslate[2] = m_earthTrans*1.5*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[2] = 780.0; // Jupiter m_PlanetsScale[3] = m_earthScale * 1.5; m_PlanetsTranslate[3] = m_earthTrans*5.2*0.5*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[3] = 4330; // Saturn m_PlanetsScale[4] = m_earthScale * 1.0; m_PlanetsTranslate[4] = m_earthTrans*9.5*0.4*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[4] = 10000; // Uranus m_PlanetsScale[5] = m_earthScale * 1.0; m_PlanetsTranslate[5] = m_earthTrans*19.6*0.25*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[5] = 30000.0; // Neptune m_PlanetsScale[6] = m_earthScale * 1.0; m_PlanetsTranslate[6] = m_earthTrans*30.0*0.2*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[6] = 60000.0; // Pluto m_PlanetsScale[7] = m_earthScale * 0.5; m_PlanetsTranslate[7] = m_earthTrans*40.0*0.2*Vector3(drand48()-0.5,0,drand48()-0.5).normalize(); m_PlanetsYear[7] = 90600.0; }
void SolarViewer:: load_mesh(const std::string& filenameObj, MeshType type) { Vector3 bbmin, bbmax; double radius; Vector3 center; switch(type) { case STARS: // load mesh from obj Mesh3DReader::read( filenameObj, m_Stars); // calculate normals if(!m_Stars.hasNormals()) m_Stars.calculateVertexNormals(); m_Stars.calculateBoundingBox(bbmin, bbmax); radius = 0.5*(bbmin - bbmax).length(); center = 0.5*(bbmin + bbmax); m_Stars.scaleObject(Vector3(10*m_starsScale, 10*m_starsScale, 10*m_starsScale)); radius *= 700.0; set_scene_pos(m_Stars.origin(), m_earthTrans*3.3); m_showTextureStars = m_Stars.hasUvTextureCoord(); break; case SUN: // load mesh from obj Mesh3DReader::read( filenameObj, m_Sun); // calculate normals if(!m_Sun.hasNormals()) m_Sun.calculateVertexNormals(); //Exercise 4.2: Scale the sun using the attribute m_sunScale m_Sun.scaleObject(Vector3(m_sunScale, m_sunScale, m_sunScale)); m_Sun.translateWorld(Vector3(0,0,0)); //Exercise 4.4: Set the light position to the center of the sun m_light.translateWorld(m_Sun.origin()); m_showTextureSun = m_Sun.hasUvTextureCoord(); break; case EARTH: // load mesh from obj Mesh3DReader::read( filenameObj, m_Earth); // calculate normals if(!m_Earth.hasNormals()) m_Earth.calculateVertexNormals(); //Exercise 4.2: Scale and translate the earth using the attributes m_earthScale and m_earthTrans m_Earth.translateObject(Vector3(m_earthTrans, 0, 0)); m_Earth.scaleObject(Vector3(m_earthScale, m_earthScale, m_earthScale)); m_showTextureEarth = m_Earth.hasUvTextureCoord(); break; case MOON: // load mesh from obj Mesh3DReader::read( filenameObj, m_Moon); // calculate normals if(!m_Moon.hasNormals()) m_Moon.calculateVertexNormals(); //Exercise 4.2: Scale and translate the moon using the attributes m_moonScale and m_moonTrans m_Moon.translateObject(Vector3(m_moonTrans, 0, 0)); m_Moon.scaleObject(Vector3(m_moonScale, m_moonScale, m_moonScale)); m_showTextureMoon = m_Moon.hasUvTextureCoord(); break; case MERCURY: case VENUS: case MARS: case JUPITER: case SATURN: case URANUS: case NEPTUNE: case PLUTO: { int index = (type-MERCURY); Mesh3DReader::read( filenameObj, m_Planets[index] ); if(!m_Planets[index].hasNormals()) m_Planets[index].calculateVertexNormals(); //Optional: Scale and translate the planets break; } default: break; } }
void WaterRenderer:: keyboard(int key, int x, int y) { double scale = 0.01; switch (key) { case '-': // reset camera position if(sceneSize>1) { sceneSize*=0.5; m_skybox.scaleObject(Vector3 (0.5,0.5,0.5)); m_water.scaleObject(Vector3 (0.5,0.5,0.5)); m_camera.setIdentity(); set_scene_pos(Vector3(0.0, 0.0, 0.0), sceneSize); } break; case '+': sceneSize*=2; m_skybox.scaleObject(Vector3 (2.0,2.0,2.0)); m_water.scaleObject(Vector3 (2.0,2.0,2.0)); // reset camera position m_camera.setIdentity(); set_scene_pos(Vector3(0.0, 0.0, 0.0), sceneSize); break; case 'q': amplitude1+=0.02; break; case 'a': wavelength1++; break; case 'y': speed1++; break; case 'w': if(amplitude1>0.02) { amplitude1-=0.02; } break; case 's': if(wavelength1>1) { wavelength1--; } break; case 'x': if(speed1>1) { speed1--; } break; case 'e': amplitude2++; break; case 'd': wavelength2++; break; case 'c': speed2++; break; case 'r': if(amplitude2>1) { amplitude2--; } break; case 'f': if(wavelength2>1) { wavelength2--; } break; case 'v': if(speed2>1) { speed2--; } break; case 't': amplitude3++; break; case 'g': wavelength3++; break; case 'b': speed3++; break; case 'z': if(amplitude3>1) { amplitude3--; } break; case 'h': if(wavelength3>1) { wavelength3--; } break; case 'n': if(speed3>1) { speed3--; } break; case 'u': amplitude4++; break; case 'j': wavelength4++; break; case 'm': speed4++; break; case 'i': if(amplitude4>1) { amplitude4--; } break; case 'k': if(wavelength4>1) { wavelength4--; } break; case ',': if(speed4>1) { speed4--; } break; case 'p': amplitude2=0; amplitude3=0; time4= (watch.stop() - startingTime)/1000; break; case '0': isRadial = true; break; default: TrackballViewer::keyboard(key, x, y); break; } glutPostRedisplay(); }
void VDPMLoader::openVDPM_ServerRendering(const char *_filename) { unsigned int i; unsigned int value; unsigned int fvi[3]; char fileformat[16]; Vec3f p, normal; float radius, sin_square, mue_square, sigma_square; VHierarchyNodeHandleContainer roots; VertexHandle vertex_handle; VHierarchyNodeIndex node_index; VHierarchyNodeIndex lchild_node_index, rchild_node_index; VHierarchyNodeIndex fund_lcut_index, fund_rcut_index; VHierarchyNodeHandle node_handle; VHierarchyNodeHandle lchild_node_handle, rchild_node_handle; std::ifstream ifs(_filename, std::ios::binary); if (!ifs) { std::cerr << "read error\n"; exit(1); } // bool swap = Endian::local() != Endian::LSB; // read header ifs.read(fileformat, 10); fileformat[10] = '\0'; if (std::string(fileformat) != std::string("VDProgMesh")) { std::cerr << "Wrong file format.\n"; ifs.close(); exit(1); } IO::restore(ifs, n_base_vertices_, swap); IO::restore(ifs, n_base_faces_, swap); IO::restore(ifs, n_details_, swap); mesh_.clear(); vfront_.clear(); vhierarchy_.clear(); vhierarchy_.set_num_roots(n_base_vertices_); // load base mesh for (i=0; i<n_base_vertices_; ++i) { IO::restore(ifs, p, swap); IO::restore(ifs, radius, swap); IO::restore(ifs, normal, swap); IO::restore(ifs, sin_square, swap); IO::restore(ifs, mue_square, swap); IO::restore(ifs, sigma_square, swap); vertex_handle = mesh_.add_vertex(p); node_index = vhierarchy_.generate_node_index(i, 1); node_handle = vhierarchy_.add_node(); VHierarchyNode &node = vhierarchy_.node(node_handle); node.set_index(node_index); node.set_vertex_handle(vertex_handle); mesh_.data(vertex_handle).set_vhierarchy_node_handle(node_handle); node.set_radius(radius); node.set_normal(normal); node.set_sin_square(sin_square); node.set_mue_square(mue_square); node.set_sigma_square(sigma_square); mesh_.set_normal(vertex_handle, normal); index2handle_map[node_index] = node_handle; roots.push_back(node_handle); } vfront_.init(roots, n_details_); for (i=0; i<n_base_faces_; ++i) { IO::restore(ifs, fvi[0], swap); IO::restore(ifs, fvi[1], swap); IO::restore(ifs, fvi[2], swap); mesh_.add_face(mesh_.vertex_handle(fvi[0]), mesh_.vertex_handle(fvi[1]), mesh_.vertex_handle(fvi[2])); } vsplit_loaded.clear(); // load details for (i=0; i<n_details_; ++i) { Vsplit avs; // position of v0 IO::restore(ifs, p, swap); avs.v0 = p; // vsplit info. IO::restore(ifs, value, swap); node_index = VHierarchyNodeIndex(value); avs.node_index = value; IO::restore(ifs, value, swap); fund_lcut_index = VHierarchyNodeIndex(value); avs.fund_lcut_index = value; IO::restore(ifs, value, swap); fund_rcut_index = VHierarchyNodeIndex(value); avs.fund_rcut_index = value; node_handle = index2handle_map[node_index]; vhierarchy_.make_children(node_handle); VHierarchyNode &node = vhierarchy_.node(node_handle); VHierarchyNode &lchild = vhierarchy_.node(node.lchild_handle()); VHierarchyNode &rchild = vhierarchy_.node(node.rchild_handle()); node.set_fund_lcut(fund_lcut_index); node.set_fund_rcut(fund_rcut_index); vertex_handle = mesh_.add_vertex(p); lchild.set_vertex_handle(vertex_handle); rchild.set_vertex_handle(node.vertex_handle()); index2handle_map[lchild.node_index()] = node.lchild_handle(); index2handle_map[rchild.node_index()] = node.rchild_handle(); // view-dependent parameters IO::restore(ifs, radius, swap); IO::restore(ifs, normal, swap); IO::restore(ifs, sin_square, swap); IO::restore(ifs, mue_square, swap); IO::restore(ifs, sigma_square, swap); lchild.set_radius(radius); lchild.set_normal(normal); lchild.set_sin_square(sin_square); lchild.set_mue_square(mue_square); lchild.set_sigma_square(sigma_square); avs.l_radius = radius; avs.l_normal = normal; avs.l_mue_square = mue_square; avs.l_sigma_square = sigma_square; avs.l_sin_square = sin_square; IO::restore(ifs, radius, swap); IO::restore(ifs, normal, swap); IO::restore(ifs, sin_square, swap); IO::restore(ifs, mue_square, swap); IO::restore(ifs, sigma_square, swap); rchild.set_radius(radius); rchild.set_normal(normal); rchild.set_sin_square(sin_square); rchild.set_mue_square(mue_square); rchild.set_sigma_square(sigma_square); avs.r_radius = radius; avs.r_normal = normal; avs.r_mue_square = mue_square; avs.r_sigma_square = sigma_square; avs.r_sin_square = sin_square; vsplit_loaded.push_back(avs); } ifs.close(); //refine 100 vsplits int cc = 0; for ( vfront_.begin(); !vfront_.end() && cc < 100; ++cc) { VHierarchyNodeHandle node_handle = vfront_.node_handle(); if (vhierarchy_.is_leaf_node(node_handle) != true) { force_vsplit(node_handle, vsplits_to_send); } vfront_.next(); std::cout << "vfront_ size " << vfront_.size() <<std::endl; } //**********// // update face and vertex normals mesh_.update_face_normals(); // bounding box VDPMMesh::ConstVertexIter vIt(mesh_.vertices_begin()), vEnd(mesh_.vertices_end()); VDPMMesh::Point bbMin, bbMax; bbMin = bbMax = mesh_.point(vIt); for (; vIt!=vEnd; ++vIt) { bbMin.minimize(mesh_.point(vIt)); bbMax.maximize(mesh_.point(vIt)); } // set center and radius VDPMMesh::Point center = 0.5f * (bbMin + bbMax); set_scene_pos(0.5f*(bbMin + bbMax), 0.5*(bbMin - bbMax).norm()); // info std::cerr << mesh_.n_vertices() << " vertices, " << mesh_.n_edges() << " edge, " << mesh_.n_faces() << " faces, " << n_details_ << " detail vertices\n"; mesh_loaded = true; }