void Game::Init() { //Vertex data[3] = {Vertex(Vector3f(-1,-1,0)), // Vertex(Vector3f(0,1,0)), // Vertex(Vector3f(1,-1,0))}; //mesh.addVertices(data, ARRAY_SIZE(data)); //Vertex data[] = {Vertex(Vector3f(-1.0f, -1.0f, 0.5773f), Vector2f(0.0f, 0.0f)), // Vertex(Vector3f(0.0f, -1.0f, -1.15475f), Vector2f(0.5f, 0.0f)), // Vertex(Vector3f(1.0f, -1.0f, 0.5773f), Vector2f(1.0f, 0.0f)), // Vertex(Vector3f(0.0f, 1.0f, 0.0f), Vector2f(0.5f, 1.0f))}; //int indices[] = { 0, 3, 1, // 1, 3, 2, // 2, 3, 0, // 1, 2, 0}; float fieldDepth = 10.0f; float fieldWidth = 10.0f; Vertex data[] = { Vertex( Vector3f(-fieldWidth, 0.0f, -fieldDepth), Vector2f(0.0f, 0.0f)), Vertex(Vector3f(-fieldWidth, 0.0f, fieldDepth * 3), Vector2f(0.0f, 1.0f)), Vertex(Vector3f(fieldWidth * 3, 0.0f, -fieldDepth), Vector2f(1.0f, 0.0f)), Vertex(Vector3f(fieldWidth * 3, 0.0f, fieldDepth * 3),Vector2f(1.0f, 1.0f))}; int indices[] = { 0, 1, 2, 2, 1, 3}; m_mesh.AddVertices(data, ARRAY_SIZE_IN_ELEMENTS(data), indices, ARRAY_SIZE_IN_ELEMENTS(indices)); m_color.Set(1,1,1); //m_texture = Texture("test.png"); m_texture = new Texture("test.png"); m_material = Material(m_texture, m_color, 1, 8); m_shader = PhongShader::GetInstance(); //PhongShader::SetAmbientLight(Vector3f(0.1f,0.1f,0.1f)); PhongShader::SetDirectionalLight(DirectionalLight(BaseLight(Vector3f(1,1,1),0.1f),Vector3f(1,1,1))); m_pLights = new PointLight[2]; m_pLights[0] = PointLight(BaseLight(Vector3f(1,0.5f,0), 0.8f), Attenuation(0,0,1), Vector3f(-2,0,5), 10); m_pLights[1] = PointLight(BaseLight(Vector3f(0,0.5f,1), 0.8f), Attenuation(0,0,1), Vector3f(2,0,7), 10); m_sLights = new SpotLight[1]; m_sLights[0] = SpotLight(PointLight(BaseLight(Vector3f(0,1,1), 0.8f), Attenuation(0,0,0.1f), Vector3f(-2,0,5), 30),Vector3f(1,1,1).Normalized(),0.8f); PhongShader::SetPointLights(m_pLights, 2); PhongShader::SetSpotLights(m_sLights, 1); m_camera = Camera(); Transform::SetProjection(70.0f, (float)Window::GetWidth(), (float)Window::GetHeight(), 0.1f, 1000.0f); Transform::SetCamera(m_camera); }
void TestGame::Init() { GameObject* planeObject = new GameObject(); GameObject* pointLightObject = new GameObject(); GameObject* spotLightObject = new GameObject(); GameObject* directionalLightObject = new GameObject(); planeObject->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks.jpg"), 0.5f, 4, new Texture("bricks_normal.jpg"), new Texture("bricks_disp.png"), 0.03f, -0.5f))); planeObject->GetTransform().SetPos(Vector3f(0, -1, 5)); planeObject->GetTransform().SetScale(4.0f); pointLightObject->AddComponent(new PointLight(Vector3f(0,1,0),0.4f,Attenuation(0,0,1))); pointLightObject->GetTransform().SetPos(Vector3f(7,0,7)); spotLightObject->AddComponent(new SpotLight(Vector3f(0,1,1),0.4f,Attenuation(0,0,0.1f),0.7f)); spotLightObject->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), ToRadians(90.0f))); directionalLightObject->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f)); GameObject* testMesh1 = new GameObject(); GameObject* testMesh2 = new GameObject(); //WARNING: bricks2_normal.jpg is reversed on the y axis. This is intentional, and demonstrates how normal maps are sometimes flipped. //If you want to fix this, the easiest solution is to flip it in an image editor. testMesh1->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8, new Texture("bricks2_normal.jpg"), new Texture("bricks2_disp.jpg"), 0.04f, -1.0f))); testMesh2->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8, new Texture("bricks2_normal.jpg")))); testMesh1->GetTransform().SetPos(Vector3f(0, 2, 0)); testMesh1->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), 0.4f)); testMesh1->GetTransform().SetScale(1.0f); testMesh2->GetTransform().SetPos(Vector3f(0, 0, 25)); testMesh1->AddChild(testMesh2); AddToScene(planeObject); AddToScene(pointLightObject); AddToScene(spotLightObject); AddToScene(directionalLightObject); AddToScene(testMesh1); testMesh2->AddChild((new GameObject()) ->AddComponent(new Camera(Matrix4f().InitPerspective(ToRadians(70.0f), Window::GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook()) ->AddComponent(new FreeMove())); directionalLightObject->GetTransform().SetRot(Quaternion(Vector3f(1,0,0), ToRadians(-45))); }
void TestGame::Init(const Window& window) { Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Material skin("humanFace", Texture("human.jpg"), 0.0f, 0, Texture("human_normal_inv.jpg")); //Material skin("humanFace", Texture("human.jpg"), 0.08f, 8, Texture("human_normal_inv.jpg")); IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f)) ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(7,0,7))) ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1)))); AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f))); AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f))); AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity(Vector3f(0, 0, 25))) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity()) ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook(window.GetCenter())) ->AddComponent(new FreeMove(10.0f))))); AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); }
void Assignment2::Init() { GameObject* planeObject = new GameObject(); GameObject* pointLightObject = new GameObject(); GameObject* spotLightObject = new GameObject(); GameObject* directionalLightObject = new GameObject(); planeObject->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks.jpg"), 1, 8))); planeObject->GetTransform().SetPos(Vector3f(0, -1, 5)); planeObject->GetTransform().SetScale(4.0f); pointLightObject->AddComponent(new PointLight(Vector3f(0,1,0),0.4f,Attenuation(0,0,1))); pointLightObject->GetTransform().SetPos(Vector3f(7,0,7)); spotLightObject->AddComponent(new SpotLight(Vector3f(0,1,1),0.4f,Attenuation(0,0,0.1f),0.7f)); spotLightObject->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), ToRadians(90.0f))); directionalLightObject->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f)); GameObject* testMesh1 = new GameObject(); GameObject* testMesh2 = new GameObject(); testMesh1->GetTransform().SetPos(Vector3f(0, 2, 0)); testMesh1->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), 0.4f)); testMesh1->GetTransform().SetScale(1.0f); testMesh2->GetTransform().SetPos(Vector3f(0, 0, 25)); testMesh1->AddChild(testMesh2); AddToScene(planeObject); AddToScene(pointLightObject); AddToScene(spotLightObject); AddToScene(directionalLightObject); AddToScene(testMesh1); testMesh2->AddChild((new GameObject()) ->AddComponent(new Camera(Matrix4f().InitPerspective(ToRadians(70.0f), Window::GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook()) ->AddComponent(new FreeMove())); directionalLightObject->GetTransform().SetRot(Quaternion(Vector3f(1,0,0), ToRadians(-45))); }
Light::Light(Type theType): Object3D(), m_type(theType), m_attenuation(Attenuation(1.f, 0, 0)), m_spot_cutoff(25.f), m_spot_exponent(1.f), m_ambient(Color(0)), m_diffuse(Color(1)), m_specular(Color(1)), m_cast_shadow(false) { }
void TestGame::Init(const Window& window) { //Materials Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Standard square mesh (1x1) IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); //Light Entity* mainLight = new Entity(Vector3f(0, 4, 0), Quaternion(Vector3f(1, 0, 0), ToRadians(270)), 1); Entity* pointLight = new Entity(Vector3f(-1, 1.5, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); mainLight->AddModifier(new DirectionalLight(Vector3f(1, 1, 1), 0.4f, 10, 80, 1)); pointLight->AddModifier(new PointLight(Vector3f(0, 0, 1), 0.4f, Attenuation(0, 0, 1))); pointLight->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(1, 0, 0), 0.015f, 1)); //pointLight->AddModifier(new FreeMove(5.0f)); AddToScene(mainLight); //AddToScene(pointLight); //Camera Entity* mainCamera = new Entity(Vector3f(-10, 5, 5), Quaternion(Vector3f(0, 0, 0), 0), 1); mainCamera->AddModifier(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70), window.GetAspect(), 0.1f, 1000))); mainCamera->AddModifier(new FreeLook(window.GetCenter(), 0.15f)); mainCamera->AddModifier(new FreeMove(15)); AddToScene(mainCamera); //Environment /*Entity* floorPlane = new Entity(Vector3f(0, 0, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* floatingCube = new Entity(Vector3f(0, 1, 0), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 0.3f); floorPlane->AddModifier(new MeshRenderer(Mesh("plane.obj"), Material("bricks"))); floatingCube->AddModifier(new MeshRenderer(Mesh("cube.obj"), Material("bricks2"))); floatingCube->AddModifier(new RepetitiveLinearMotionModifier(Vector3f(0, 1, 0), 0.01f, 2)); floatingCube->AddModifier(new RepetitiveRotationalMotionModifier(Vector3f(0, 1, 0), 0.02f, 1, false)); AddToScene(floorPlane); AddToScene(floatingCube);*/ Entity* sphere1 = new Entity(Vector3f(0, 0, -4), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere2 = new Entity(Vector3f(0, 0, 1), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere3 = new Entity(Vector3f(0, 0, 3), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere4 = new Entity(Vector3f(0, 0, 5), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); Entity* sphere5 = new Entity(Vector3f(0, 0, 7), Quaternion(Vector3f(0, 0, 0), ToRadians(0)), 1); sphere1->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))); sphere2->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere3->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere4->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks2"))); sphere5->AddModifier(new MeshRenderer(Mesh("sphere.obj"), Material("bricks"))); AddToScene(sphere1); AddToScene(sphere2); AddToScene(sphere3); AddToScene(sphere4); AddToScene(sphere5); //Physics PhysicsEngine physicsEngine = PhysicsEngine(); PhysicsObject sphere1Rep = PhysicsObject(sphere1, new BoundingSphere(Vector3f(0, 0, -4), 1), Vector3f(0, 0, 1), Vector3f(0, 0, 0), false); PhysicsObject sphere2Rep = PhysicsObject(sphere2, new BoundingSphere(Vector3f(0, 0, 1), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere3Rep = PhysicsObject(sphere3, new BoundingSphere(Vector3f(0, 0, 3), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere4Rep = PhysicsObject(sphere4, new BoundingSphere(Vector3f(0, 0, 5), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); PhysicsObject sphere5Rep = PhysicsObject(sphere5, new BoundingSphere(Vector3f(0, 0, 7), 1), Vector3f(0, 0, 0), Vector3f(0, 0, 0), false); physicsEngine.AddObject(sphere1Rep); physicsEngine.AddObject(sphere2Rep); physicsEngine.AddObject(sphere3Rep); physicsEngine.AddObject(sphere4Rep); physicsEngine.AddObject(sphere5Rep); SetPhysicsEngine(physicsEngine); }
void Light::set_attenuation(float constant, float linear, float quadratic) { m_attenuation = Attenuation(std::max(constant, 0.f), std::max(linear, 0.f), std::max(quadratic, 0.f)); }
void Light::set_attenuation(const Attenuation &theAttenuation) { m_attenuation = Attenuation(std::max(theAttenuation.constant, 0.f), std::max(theAttenuation.linear, 0.f), std::max(theAttenuation.quadratic, 0.f)); }