diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index ff83d14..b705e1f 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -7,7 +7,7 @@ void MainState::onEnter() { ap.load("example.nfpack"); test.create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC); test.setPosition(nf::Vec3(0.0, 1.5, -5.0)); - plane.create(ap.get("env.obj"), nf::Entity::Type::ENVIRONMENT); + plane.create(ap.get("env.obj"), nf::Entity::Type::MAP); plane.setScale(20.0); plane.setPosition(0.0, -20.0, 0.0); text.create("", nf::Vec2(0.1, 0.025), nf::Vec3(0.8)); @@ -27,9 +27,9 @@ void MainState::onEnter() { sound2.setVolume(3.0); sound2.setEntity(test); - for (int x = 0; x < 5; x++) { - for (int y = 0; y < 5; y++) { - for (int z = 0; z < 5; z++) { + for (int x = 0; x < 3; x++) { + for (int y = 0; y < 3; y++) { + for (int z = 0; z < 3; z++) { entities.push_back(new nf::Entity); entities.back()->create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC); entities.back()->setPosition(nf::Vec3(5.0 + x * 2.05, 1.0 + y * 2.05, -5.0 + z * 2.05)); @@ -40,6 +40,8 @@ void MainState::onEnter() { grav = 2.0f; setGravity(grav); + amb = 0.1f; + camera->setPosition(-20.0, 15.0, 0.0); camera->setRotation(85.0, -30.0); } @@ -103,6 +105,13 @@ void MainState::update(float deltaTime) { } gravText.setText("Gravity Scale: " + std::to_string(grav)); + if (app->isKeyHeld(NFI_LEFT)) + amb -= 0.01f; + if (app->isKeyHeld(NFI_RIGHT)) + amb += 0.01f; + if (amb >= 0.0f) + setAmbientLight(amb); + if (app->isKeyPressed(NFI_ESCAPE)) app->quit(); } diff --git a/Game/src/include/MainState.h b/Game/src/include/MainState.h index b79fdcd..8814b8b 100644 --- a/Game/src/include/MainState.h +++ b/Game/src/include/MainState.h @@ -29,6 +29,7 @@ private: nf::Sound sound2; float grav; + float amb; std::vector entities; }; \ No newline at end of file diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj index 5b0bcfe..79a9f59 100644 --- a/NothinFancy/NothinFancy.vcxproj +++ b/NothinFancy/NothinFancy.vcxproj @@ -61,6 +61,7 @@ true $(ProjectDir)src\include\;$(ProjectDir)dep\include\ $(IntDir)obj\ + true Console @@ -92,6 +93,7 @@ true $(ProjectDir)src\include\;$(ProjectDir)dep\include\ $(IntDir)obj\ + true Console diff --git a/NothinFancy/assets/base/shaders/lightingFragment.shader b/NothinFancy/assets/base/shaders/lightingFragment.shader index c8fb78e..47d17b8 100644 --- a/NothinFancy/assets/base/shaders/lightingFragment.shader +++ b/NothinFancy/assets/base/shaders/lightingFragment.shader @@ -22,6 +22,7 @@ uniform Light light[12]; uniform int numberOfLights; uniform bool isContinued; uniform float farPlane; +uniform float ambientStrength; uniform sampler2D gBPos; uniform sampler2D gBNorm; @@ -88,7 +89,6 @@ void main() { float specPower = specTemp.r; float matSpec = specTemp.g; - float ambientStrength = 0.1f; vec3 ambient = ambientStrength * matDiff; if (!isContinued) color += ambient; diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index 7a27146..1ef5342 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -45,11 +45,21 @@ namespace nf { SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor); } + Renderer* Application::getRenderer() const { + if (!m_renderer) + Error("Application not running yet!"); + return m_renderer; + } + AudioEngine* Application::getAudioEngine() const { + if(!m_audio) + Error("Application not running yet!"); return m_audio; } PhysicsEngine* Application::getPhysicsEngine() const { + if (!m_physics) + Error("Application not running yet!"); return m_physics; } diff --git a/NothinFancy/src/Gamestate.cpp b/NothinFancy/src/Gamestate.cpp index c35e552..630a9fb 100644 --- a/NothinFancy/src/Gamestate.cpp +++ b/NothinFancy/src/Gamestate.cpp @@ -54,6 +54,10 @@ namespace nf { return camera; } + void Gamestate::setAmbientLight(float strength) { + app->getRenderer()->setAmbient(strength); + } + void Gamestate::setGravity(const Vec3& gravity) { app->getPhysicsEngine()->setGravity(gravity * 9.81f); } diff --git a/NothinFancy/src/NFObject/Entity.cpp b/NothinFancy/src/NFObject/Entity.cpp index 5128554..fb674bd 100644 --- a/NothinFancy/src/NFObject/Entity.cpp +++ b/NothinFancy/src/NFObject/Entity.cpp @@ -37,7 +37,7 @@ namespace nf { bool convex = false, triangle = false; if (m_type == Entity::Type::STATIC || m_type == Entity::Type::DYNAMIC) convex = true; - else if (m_type == Entity::Type::ENVIRONMENT) + else if (m_type == Entity::Type::MAP) triangle = true; m_model = new Model(model, convex, triangle); model->alreadyLoaded = true; diff --git a/NothinFancy/src/PhysicsEngine.cpp b/NothinFancy/src/PhysicsEngine.cpp index 6a7a7c5..4dac779 100644 --- a/NothinFancy/src/PhysicsEngine.cpp +++ b/NothinFancy/src/PhysicsEngine.cpp @@ -4,9 +4,6 @@ #include "Entity.h" #include "Model.h" -//Remove this -#include "Input.h" - namespace nf { class PhysicsErrorCallback : public PxErrorCallback { virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line) { @@ -234,7 +231,7 @@ namespace nf { act->userData = entity; m_scene->addActor(*act); } - else if (type == Entity::Type::ENVIRONMENT) { + else if (type == Entity::Type::MAP) { PxRigidStatic* act = PxCreateStatic(*m_phy, PxTransform(PxIdentity), PxTriangleMeshGeometry(triangleMesh), *mat); act->userData = entity; m_scene->addActor(*act); diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index 0fb5429..6893349 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -290,6 +290,12 @@ namespace nf { SwapBuffers(m_hdc); } + void Renderer::setAmbient(float am) { + if (am < 0.0f) + Error("Cannot have a negative ambient light strength!"); + m_lightingShader->setUniform("ambientStrength", am); + } + void Renderer::loadBaseAssets() { m_baseAP.load("base.nfpack"); const char* gBufferVertex = m_baseAP.get("gBufferVertex.shader")->data; diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h index 01d324c..3a20ef1 100644 --- a/NothinFancy/src/include/Application.h +++ b/NothinFancy/src/include/Application.h @@ -24,6 +24,7 @@ namespace nf { void setWindowIcon(HICON hIcon); void setWindowCursor(HCURSOR hCursor); + Renderer* getRenderer() const; AudioEngine* getAudioEngine() const; PhysicsEngine* getPhysicsEngine() const; void addState(Gamestate* state, const std::string& stateName); diff --git a/NothinFancy/src/include/Entity.h b/NothinFancy/src/include/Entity.h index bff5311..9f28108 100644 --- a/NothinFancy/src/include/Entity.h +++ b/NothinFancy/src/include/Entity.h @@ -15,7 +15,7 @@ namespace nf { enum class Type { STATIC, DYNAMIC, - ENVIRONMENT, + MAP, DETAIL }; diff --git a/NothinFancy/src/include/Gamestate.h b/NothinFancy/src/include/Gamestate.h index 5d90ee0..191a7b0 100644 --- a/NothinFancy/src/include/Gamestate.h +++ b/NothinFancy/src/include/Gamestate.h @@ -29,6 +29,8 @@ namespace nf { virtual void render(Renderer& renderer); Camera* getCamera(); + //Defaults to 0.1f + void setAmbientLight(float stength); //In units of Earth gravity (9.81 m/s^2) void setGravity(const Vec3& gravity); void setGravity(float strength); diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index 044cd2a..2ce3098 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -1,6 +1,8 @@ -//TODO: Rework this file to only contain functions the frontend will need to access - #pragma once +//TODO: Rework this file to only contain functions the frontend will need to access +//Maybe a implementation define here? + + #include #include #include diff --git a/NothinFancy/src/include/Renderer.h b/NothinFancy/src/include/Renderer.h index 9f7834d..30268b7 100644 --- a/NothinFancy/src/include/Renderer.h +++ b/NothinFancy/src/include/Renderer.h @@ -30,6 +30,7 @@ namespace nf { void render(Cubemap& in); void doFrame(Camera* camera, float dT); + void setAmbient(float am); ~Renderer(); private: