void Picture::render(int w, int h) { //picture will not look exactly like in class programs //normals used are those from the text file GLuint* tex_num = new GLuint[2]; //obtain two unique integers that have not been used as texture id before glGenTextures(2, tex_num); const char* fileName = "sphere_texture.txt"; BasicObject* sphere = new BasicObject(fileName); //sphere 1 with moon color texture InstanceObject* sphere1 = new InstanceObject(sphere); Color* d1 = new Color(0.3, 0.3, 0.9); sphere1->setDiffuseMaterial(d1); const char* texture = "MoonColor.raw"; Texture* moon_color = new Texture(texture, 512, 256); sphere1->setColorTexture(moon_color, tex_num[0]); //sphere 2 with moon normal map texture InstanceObject* sphere2 = new InstanceObject(sphere); Color* d2 = new Color(1.0, 0.0, 0.0); sphere2->setDiffuseMaterial(d2); const char* normal = "MoonNormal.raw"; Texture* moon_normal = new Texture(normal, 512, 256); sphere2->setColorTexture(moon_normal, tex_num[1]); Scene* scene = new Scene(); TransformNode* tn = new TransformNode(); tn->buildTransform(AffineTransforms::scale(.9, .3, .3)); tn->buildTransform(AffineTransforms::rotateX(90)); tn->buildTransform(AffineTransforms::rotateY(290)); tn->buildTransform(AffineTransforms::translate(0, 0, 0)); tn->addChild(sphere1); scene->addTransformNode(tn); tn = new TransformNode(); tn->buildTransform(AffineTransforms::scale(.7, 1.3, .7)); tn->buildTransform(AffineTransforms::rotateX(90)); tn->buildTransform(AffineTransforms::rotateZ(290)); tn->buildTransform(AffineTransforms::translate(-.75, .75, 0)); tn->addChild(sphere2); scene->addTransformNode(tn); scene->render(w, h); delete scene; }
void Picture::render(Pixel* px) { Color *ambient = new Color(1, 1, 1); Vertex *eye = new Vertex(0,0,0); Light *light = new Light(); double attenuation = 0; //while(true) //{ char* fileName = "sphere.txt"; //cout<<"calling read object"<<endl; BasicObject* sphere = readObject(fileName); sphere->computeSandT(); //sphere->printFaces(); //cout<<"called it bitches"<<endl; //delete[] fileName; //mingw appears to delete this automatically fileName = "trs.txt"; InstanceObject* sphereInstance = buildInstanceObject(fileName, sphere); //delete[] fileName; //obtaining the window transform int widthPixels = px->getWidth(); //the dimensions of the panel on which the drawing will occur int heightPixels = px->getHeight(); getShaderInfo(eye, ambient, light, &attenuation); Scene* scene = new Scene(light, ambient); scene->buildTransform(getCameraTransform("camera.txt")); scene->buildTransform(getPerspectiveTransform("fov.txt", widthPixels, heightPixels)); scene->buildTransform(AffineTransforms::window(widthPixels, heightPixels)); TransformNode* tn = new TransformNode(); tn->addChild(sphereInstance); scene->addTransformNode(tn); //for(;;) //{ scene->render(px, eye, attenuation); //} delete scene; //} }
// Function to process the Copy menu command. void copySelectedObjects() { if (!noAncestorDescendantSelections()) return; for (set<TransformNode*>::const_iterator iter = selections.begin(); iter != selections.end(); ++iter) { TransformNode* target = *iter; if (target == sceneRoot) { sceneRoot = new TransformNode(NULL); sceneRoot->addChild(target); target->setParent(sceneRoot); } TransformNode* parent = target->getParent(); TransformNode* newThing = target->clone(); parent->addChild(newThing); newThing->setParent(parent); target->translate(COPY_OFF_X, COPY_OFF_Y); } glutPostRedisplay(); }
BasicSceneExample::BasicSceneExample(int argc, const char* argv[]): ExampleApplication("Basic Scene", argc, argv) { // Open Sans openSans = new FontFamily(resourceContext->getFontManager()); openSans->setName("Open Sans"); FontFace* openSansRegular = openSans->createFontFace(); openSansRegular->setSource("data/fonts/Open_Sans/OpenSans-Regular.ttf"); FontFace* openSansItalic = openSans->createFontFace(); openSansItalic->setSource("data/fonts/Open_Sans/OpenSans-Italic.ttf"); openSansItalic->setStyle(FontStyle::ITALIC); FontFace* openSansBold = openSans->createFontFace(); openSansBold->setSource("data/fonts/Open_Sans/OpenSans-Bold.ttf"); openSansBold->setWeight(FontWeight::BOLD); FontFace* openSansBoldItalic = openSans->createFontFace(); openSansBoldItalic->setSource("data/fonts/Open_Sans/OpenSans-BoldItalic.ttf"); openSansBoldItalic->setStyle(FontStyle::ITALIC); openSansBoldItalic->setWeight(FontWeight::BOLD); SharedFont font = openSansItalic->getFont(22); if (!font) { std::cerr << "Failed to find font.\n"; } // Load meshes object = resourceContext->getMeshManager()->load("data/models/Hexapod.mesh"); lightMesh = resourceContext->getMeshManager()->load("data/models/circle.obj"); checker = resourceContext->getImageManager()->load("data/textures/checker2.tga", true); //scene.addChild(new AmbientCubeNode(&ambientCube)); floor = resourceContext->getMeshManager()->load("data/models/CheckerFloor.obj"); // Setup camera camera.setLens(20.0f, 24.0f); camera.setAspectRatio(graphicsContext->getViewport().getAspectRatio()); camera.setClipNear(0.1f); camera.setClipFar(100.0f); camera.lookAt( {0.0f, 0.0f, 3.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f}); camera.update(); orthoCamera.setClipTop(0.0f); orthoCamera.setClipLeft(0.0f); orthoCamera.setClipBottom(window->getHeight()); orthoCamera.setClipRight(window->getWidth()); orthoCamera.setClipNear(-1.0f); orthoCamera.setClipFar(1.0f); orthoCamera.lookAt( {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f, 0.0f}); orthoCamera.update(); yaw = 0.0f; pitch = 0.0f; mouseDown = false; // Setup lighting light.setColor({1.0f, 1.0f, 1.0f}); light.setPosition({0.0f, 2.5f, 4.0f}); light.setAttenuation({1.0f, 0.025f, 0.01f}); light.setDirection(-light.getPosition().normalized()); light.setCutoff(std::cos(math::radians<float>(30.0f))); light.setExponent(20.0f); plight.setColor(light.getColor()); plight.setPosition(light.getPosition()); plight.setAttenuation(light.getAttenuation()); sun.setColor({1.0f, 1.0f, 1.0f}); sun.setDirection(Vector<3, float>(0.75f, -0.5f, -1.0f).normalized()); // Add lights to scene //scene.addChild(new SpotlightNode(&light)); scene.addChild(new DirectionalLightNode(&sun)); //scene.addChild(new PointLightNode(&plight)); // Add geometry to scene scene.addChild(new GeometryNode(floor)); GeometryNode* objectNode = nullptr; if (object->getSkeleton() && object->getSkeleton()->isLoaded()) { // Pose const Skeleton* skeleton = object->getSkeleton().get(); pose = new SkeletonPose(skeleton); objectNode = new RiggedGeometryNode(object, pose); } else { objectNode = new GeometryNode(object); } float objectHeight = (object->getAABB().getMax() - object->getAABB().getMin()).y; Vector<3, float> objectPosition = (object->getAABB().getMin() + object->getAABB().getMax()) * -0.5f; objectPosition.y += objectHeight * 0.5f; /* FogNode* fogNode = new FogNode(); fogNode->setFogMode(FogMode::EXPONENTIAL_SQUARED); fogNode->setFogColor({1.0f, 1.0f, 1.0f}); fogNode->setFogDensity(0.25f); scene.addChild(fogNode); */ SharedImage skyboxCubeMap = resourceContext->getImageManager()->load( "data/textures/cubemap_positive_x.tga", "data/textures/cubemap_negative_x.tga", "data/textures/cubemap_positive_y.tga", "data/textures/cubemap_negative_y.tga", "data/textures/cubemap_positive_z.tga", "data/textures/cubemap_negative_z.tga", true); SkyboxNode* skyboxNode = new SkyboxNode(skyboxCubeMap); scene.addChild(skyboxNode); camera.lookAt( {0.0f, objectHeight * 0.5f, 3.0f}, {0.0f, objectHeight * 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}); camera.update(); TransformNode* transform = new TransformNode(); transform->setLocalTransform( Transform<float>( {objectPosition}, {0, 0, 0, 1}, {1.0f, 1.0f, 1.0f})); transform->addChild(objectNode); scene.addChild(transform); BillboardNode* billboardNode = new BillboardNode(); billboardNode->setAlignment(BillboardAlignment::SCREEN); billboardNode->addChild(new GeometryNode(lightMesh)); transform = new TransformNode(); transform->setLocalTransform( Transform<float>( light.getPosition(), {0.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f})); transform->addChild(billboardNode); scene.addChild(transform); // Setup controls Keyboard* keyboard = getInputManager()->getKeyboard(0); moveForward = new KeyboardAction(keyboard, KeyCode::W); moveBack = new KeyboardAction(keyboard, KeyCode::S); strafeLeft = new KeyboardAction(keyboard, KeyCode::A); strafeRight = new KeyboardAction(keyboard, KeyCode::D); rollCW = new KeyboardAction(keyboard, KeyCode::E); rollCCW = new KeyboardAction(keyboard, KeyCode::Q); increaseAction = new KeyboardAction(keyboard, KeyCode::EQUALS); decreaseAction = new KeyboardAction(keyboard, KeyCode::MINUS); up = {0.0f, 1.0f, 0.0f}; //graphicsContext->setClearColor({0.145f, 0.145f, 0.145f, 0.0f}); getInputManager()->getMouse(0)->addObserver(this); }