void project1() { // Create scene Scene scn; scn.SetSkyColor(Color(0.8f, 0.9f, 1.0f)); // Create boxes LambertMaterial lambert1; lambert1.SetDiffuseColor(Color(0.3f,0.3f,0.3f)); MeshObject box1; box1.MakeBox(5.0f,0.1f,5.0f, &lambert1); scn.AddObject(box1); LambertMaterial lambert2; lambert2.SetDiffuseColor(Color(0.7f,0.7f,0.7f)); MeshObject box2; box2.MakeBox(1.0f,1.0f,1.0f, &lambert2); InstanceObject inst1(box2); Matrix34 mtx; mtx.MakeRotateX(0.5f); mtx.d.y=1.0f; inst1.SetMatrix(mtx); scn.AddObject(inst1); InstanceObject inst2(box2); mtx.MakeRotateY(1.0f); mtx.d.Set(-1.0f,0.0f,1.0f); inst2.SetMatrix(mtx); scn.AddObject(inst2); // Create lights DirectLight sunlgt; sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f)); sunlgt.SetIntensity(0.5f); sunlgt.SetDirection(Vector3(-0.5f, -1.0f, -0.5f)); scn.AddLight(sunlgt); PointLight redlgt; redlgt.SetBaseColor(Color(1.0f, 0.2f, 0.2f)); redlgt.SetIntensity(2.0f); redlgt.SetPosition(Vector3(2.0f, 2.0f, 0.0f)); scn.AddLight(redlgt); // Create camera Camera cam; cam.LookAt(Vector3(2.0f,2.0f,5.0f), Vector3(0.0f,0.0f,0.0f)); cam.SetResolution(800,600); cam.SetFOV(40.0f); cam.SetAspect(1.33f); // Render image cam.Render(scn); cam.SaveBitmap("project1.bmp"); }
void Tester::Keyboard(int key,int x,int y) { float rotateAmount = .1; float rotateNegAmount = -.1; float speedAmount = .01; float negSpeedAmount = -.01; float translateAmount = 0.1; float rotateClothRad = 0.1; Matrix34 rotMtx = Matrix34::IDENTITY; switch(key) { case 0x1b: // Escape Quit(); break; // case 'r': // Reset(); // break; ////---DOF Modifications // //case 'z': //Increase Dof X // // jnt->dofx.increaseValue(rotateAmount); // // break; // //case 'x': //Decrease Dof X // // jnt->dofx.increaseValue(rotateNegAmount); // // break; // //case 'c': //Increase Dof Y // // jnt->dofy.increaseValue(rotateAmount); // // break; // //case 'v': //Decrease Dof Y // // jnt->dofy.increaseValue(rotateNegAmount); // // break; // //case 'b': //Increase Dof Z // // jnt->dofz.increaseValue(rotateAmount); // // break; // //case 'n': //Decrease Dof Z // // jnt->dofz.increaseValue(rotateNegAmount); // // break; ////-----Image Modifications. // case 't': //Toggle Skeleton Draw // toggleSkeleton = !toggleSkeleton; // break; // case 'y': //Toggle Skin Draw // toggleSkin = !toggleSkin; // break; ////------Morph Modifications. // case 'k': //Decrease Morph // morphDof->increaseMorph(rotateNegAmount); // break; // case 'l': //Increase Morph // morphDof->increaseMorph(rotateAmount); // break; ////------Animation Modifications. // case 'p': //Pause Animation // pauseAnimation = !pauseAnimation; // break; // case 'i': //Decrease Speed // play.increaseSpeed(negSpeedAmount); // break; // case 'o': //Increase Speed // play.increaseSpeed(speedAmount); // break; case 'p': //Pause Animation pauseAnimation = !pauseAnimation; break; //Parachute case 'o': //toggle between cloth and parachute clothFirst = !clothFirst; break; //Cloth Modifications. case 'f': //Switch to solid drawStyle = 1; break; case 'g': //Switch to wire drawStyle = 0; break; case 'a': //Move left cloth.translateCloth(Vector3(-translateAmount, 0, 0)); break; case 'd': //Move right cloth.translateCloth(Vector3(translateAmount, 0, 0)); break; case 'w': //Move forward cloth.translateCloth(Vector3(0, 0, -translateAmount)); break; case 's': //Move backward cloth.translateCloth(Vector3(0, 0, translateAmount)); break; case 'v': //Move up cloth.translateCloth(Vector3(0, translateAmount, 0)); break; case 'b': //Move down cloth.translateCloth(Vector3(0, -translateAmount, 0)); break; case 'q': //rotate X counterclock wise rotMtx.MakeRotateX(rotateClothRad); cloth.rotateCloth(rotMtx); break; case 'e': //rotate X clock wise rotMtx.MakeRotateX(-rotateClothRad); cloth.rotateCloth(rotMtx); break; case 'r': //rotate Y counterclock wise rotMtx.MakeRotateY(rotateClothRad); cloth.rotateCloth(rotMtx); break; case 't': //rotate Y clock wise rotMtx.MakeRotateY(-rotateClothRad); cloth.rotateCloth(rotMtx); break; case 'y': //rotate Z counterclock wise rotMtx.MakeRotateZ(rotateClothRad); cloth.rotateCloth(rotMtx); break; case 'u': //rotate Z clock wise rotMtx.MakeRotateZ(-rotateClothRad); cloth.rotateCloth(rotMtx); break; //Wind adjustments case 'm': //toggle wind if(windFactor != 0) //on turn off windFactor = 0; else windFactor = 20; //off turn on break; case 'h': //Increase wind windFactor += 1; break; case 'j': windFactor -= 1; break; //Ground adjustments case 'z': //toggle ground toggleGnd = !toggleGnd; break; case 'x': //raise ground gnd.setPositionY(gnd.getPositionY() + 0.5); break; case 'c': //lower ground gnd.setPositionY(gnd.getPositionY() - 0.5); break; case 'k': //Draw Solid gndDrawType = 0; break; case 'l': //Draw Wire gndDrawType = 1; break; } }
void project2() { // Create scene Scene scn; scn.SetSkyColor(Color(0.8f, 0.8f, 1.0f)); // Create ground MeshObject ground; ground.MakeBox(5.0f,0.1f,5.0f); scn.AddObject(ground); // Create dragon MeshObject dragon; dragon.LoadPLY("dragon.ply"); dragon.Smooth(); std::chrono::time_point<std::chrono::system_clock> start, end; start = std::chrono::system_clock::now(); std::cout << "Constructing the tree ..." << std::endl; BoxTreeObject tree; tree.Construct(dragon); scn.AddObject(tree); end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end-start; std::cout << "Tree construcion done in " << elapsed_seconds.count() * 1000 << " milliseconds" << std::endl; // Create instance InstanceObject inst(tree); Matrix34 mtx; mtx.MakeRotateY(PI); mtx.d.Set(-0.05f,0.0f,-0.1f); inst.SetMatrix(mtx); scn.AddObject(inst); // Create lights DirectLight sunlgt; sunlgt.SetBaseColor(Color(1.0f, 1.0f, 0.9f)); sunlgt.SetIntensity(1.0f); sunlgt.SetDirection(Vector3(2.0f, -3.0f, -2.0f)); scn.AddLight(sunlgt); PointLight redlgt; redlgt.SetBaseColor(Color(1.0f, 0.2f, 0.2f)); redlgt.SetIntensity(0.02f); redlgt.SetPosition(Vector3(-0.2f, 0.2f, 0.2f)); scn.AddLight(redlgt); PointLight bluelgt; bluelgt.SetBaseColor(Color(0.2f, 0.2f, 1.0f)); bluelgt.SetIntensity(0.02f); bluelgt.SetPosition(Vector3(0.1f, 0.1f, 0.3f)); scn.AddLight(bluelgt); // Create camera Camera cam; cam.LookAt(Vector3(-0.1f,0.1f,0.2f),Vector3(-0.05f,0.12f,0.0f)); cam.SetFOV(40.0f); cam.SetAspect(1.33f); cam.SetResolution(800,600); start = std::chrono::system_clock::now(); std::cout << "Rendering the scene ..." << std::endl; // Render image cam.Render(scn); cam.SaveBitmap("project2.bmp"); end = std::chrono::system_clock::now(); elapsed_seconds = end-start; std::cout << "Scene rendering done in " << elapsed_seconds.count() * 1000 << " milliseconds" << std::endl; }