Ambient light can now be set; Code cleanup
This commit is contained in:
parent
231ac792d7
commit
f884847513
@ -7,7 +7,7 @@ void MainState::onEnter() {
|
|||||||
ap.load("example.nfpack");
|
ap.load("example.nfpack");
|
||||||
test.create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC);
|
test.create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC);
|
||||||
test.setPosition(nf::Vec3(0.0, 1.5, -5.0));
|
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.setScale(20.0);
|
||||||
plane.setPosition(0.0, -20.0, 0.0);
|
plane.setPosition(0.0, -20.0, 0.0);
|
||||||
text.create("", nf::Vec2(0.1, 0.025), nf::Vec3(0.8));
|
text.create("", nf::Vec2(0.1, 0.025), nf::Vec3(0.8));
|
||||||
@ -27,9 +27,9 @@ void MainState::onEnter() {
|
|||||||
sound2.setVolume(3.0);
|
sound2.setVolume(3.0);
|
||||||
sound2.setEntity(test);
|
sound2.setEntity(test);
|
||||||
|
|
||||||
for (int x = 0; x < 5; x++) {
|
for (int x = 0; x < 3; x++) {
|
||||||
for (int y = 0; y < 5; y++) {
|
for (int y = 0; y < 3; y++) {
|
||||||
for (int z = 0; z < 5; z++) {
|
for (int z = 0; z < 3; z++) {
|
||||||
entities.push_back(new nf::Entity);
|
entities.push_back(new nf::Entity);
|
||||||
entities.back()->create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC);
|
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));
|
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;
|
grav = 2.0f;
|
||||||
setGravity(grav);
|
setGravity(grav);
|
||||||
|
|
||||||
|
amb = 0.1f;
|
||||||
|
|
||||||
camera->setPosition(-20.0, 15.0, 0.0);
|
camera->setPosition(-20.0, 15.0, 0.0);
|
||||||
camera->setRotation(85.0, -30.0);
|
camera->setRotation(85.0, -30.0);
|
||||||
}
|
}
|
||||||
@ -103,6 +105,13 @@ void MainState::update(float deltaTime) {
|
|||||||
}
|
}
|
||||||
gravText.setText("Gravity Scale: " + std::to_string(grav));
|
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))
|
if (app->isKeyPressed(NFI_ESCAPE))
|
||||||
app->quit();
|
app->quit();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ private:
|
|||||||
nf::Sound sound2;
|
nf::Sound sound2;
|
||||||
|
|
||||||
float grav;
|
float grav;
|
||||||
|
float amb;
|
||||||
|
|
||||||
std::vector<nf::Entity*> entities;
|
std::vector<nf::Entity*> entities;
|
||||||
};
|
};
|
@ -61,6 +61,7 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -92,6 +93,7 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)src\include\;$(ProjectDir)dep\include\</AdditionalIncludeDirectories>
|
||||||
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
|
||||||
|
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
@ -22,6 +22,7 @@ uniform Light light[12];
|
|||||||
uniform int numberOfLights;
|
uniform int numberOfLights;
|
||||||
uniform bool isContinued;
|
uniform bool isContinued;
|
||||||
uniform float farPlane;
|
uniform float farPlane;
|
||||||
|
uniform float ambientStrength;
|
||||||
|
|
||||||
uniform sampler2D gBPos;
|
uniform sampler2D gBPos;
|
||||||
uniform sampler2D gBNorm;
|
uniform sampler2D gBNorm;
|
||||||
@ -88,7 +89,6 @@ void main() {
|
|||||||
float specPower = specTemp.r;
|
float specPower = specTemp.r;
|
||||||
float matSpec = specTemp.g;
|
float matSpec = specTemp.g;
|
||||||
|
|
||||||
float ambientStrength = 0.1f;
|
|
||||||
vec3 ambient = ambientStrength * matDiff;
|
vec3 ambient = ambientStrength * matDiff;
|
||||||
if (!isContinued)
|
if (!isContinued)
|
||||||
color += ambient;
|
color += ambient;
|
||||||
|
@ -45,11 +45,21 @@ namespace nf {
|
|||||||
SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor);
|
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 {
|
AudioEngine* Application::getAudioEngine() const {
|
||||||
|
if(!m_audio)
|
||||||
|
Error("Application not running yet!");
|
||||||
return m_audio;
|
return m_audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsEngine* Application::getPhysicsEngine() const {
|
PhysicsEngine* Application::getPhysicsEngine() const {
|
||||||
|
if (!m_physics)
|
||||||
|
Error("Application not running yet!");
|
||||||
return m_physics;
|
return m_physics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ namespace nf {
|
|||||||
return camera;
|
return camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Gamestate::setAmbientLight(float strength) {
|
||||||
|
app->getRenderer()->setAmbient(strength);
|
||||||
|
}
|
||||||
|
|
||||||
void Gamestate::setGravity(const Vec3& gravity) {
|
void Gamestate::setGravity(const Vec3& gravity) {
|
||||||
app->getPhysicsEngine()->setGravity(gravity * 9.81f);
|
app->getPhysicsEngine()->setGravity(gravity * 9.81f);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ namespace nf {
|
|||||||
bool convex = false, triangle = false;
|
bool convex = false, triangle = false;
|
||||||
if (m_type == Entity::Type::STATIC || m_type == Entity::Type::DYNAMIC)
|
if (m_type == Entity::Type::STATIC || m_type == Entity::Type::DYNAMIC)
|
||||||
convex = true;
|
convex = true;
|
||||||
else if (m_type == Entity::Type::ENVIRONMENT)
|
else if (m_type == Entity::Type::MAP)
|
||||||
triangle = true;
|
triangle = true;
|
||||||
m_model = new Model(model, convex, triangle);
|
m_model = new Model(model, convex, triangle);
|
||||||
model->alreadyLoaded = true;
|
model->alreadyLoaded = true;
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
//Remove this
|
|
||||||
#include "Input.h"
|
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class PhysicsErrorCallback : public PxErrorCallback {
|
class PhysicsErrorCallback : public PxErrorCallback {
|
||||||
virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line) {
|
virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line) {
|
||||||
@ -234,7 +231,7 @@ namespace nf {
|
|||||||
act->userData = entity;
|
act->userData = entity;
|
||||||
m_scene->addActor(*act);
|
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);
|
PxRigidStatic* act = PxCreateStatic(*m_phy, PxTransform(PxIdentity), PxTriangleMeshGeometry(triangleMesh), *mat);
|
||||||
act->userData = entity;
|
act->userData = entity;
|
||||||
m_scene->addActor(*act);
|
m_scene->addActor(*act);
|
||||||
|
@ -290,6 +290,12 @@ namespace nf {
|
|||||||
SwapBuffers(m_hdc);
|
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() {
|
void Renderer::loadBaseAssets() {
|
||||||
m_baseAP.load("base.nfpack");
|
m_baseAP.load("base.nfpack");
|
||||||
const char* gBufferVertex = m_baseAP.get("gBufferVertex.shader")->data;
|
const char* gBufferVertex = m_baseAP.get("gBufferVertex.shader")->data;
|
||||||
|
@ -24,6 +24,7 @@ namespace nf {
|
|||||||
|
|
||||||
void setWindowIcon(HICON hIcon);
|
void setWindowIcon(HICON hIcon);
|
||||||
void setWindowCursor(HCURSOR hCursor);
|
void setWindowCursor(HCURSOR hCursor);
|
||||||
|
Renderer* getRenderer() const;
|
||||||
AudioEngine* getAudioEngine() const;
|
AudioEngine* getAudioEngine() const;
|
||||||
PhysicsEngine* getPhysicsEngine() const;
|
PhysicsEngine* getPhysicsEngine() const;
|
||||||
void addState(Gamestate* state, const std::string& stateName);
|
void addState(Gamestate* state, const std::string& stateName);
|
||||||
|
@ -15,7 +15,7 @@ namespace nf {
|
|||||||
enum class Type {
|
enum class Type {
|
||||||
STATIC,
|
STATIC,
|
||||||
DYNAMIC,
|
DYNAMIC,
|
||||||
ENVIRONMENT,
|
MAP,
|
||||||
DETAIL
|
DETAIL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ namespace nf {
|
|||||||
virtual void render(Renderer& renderer);
|
virtual void render(Renderer& renderer);
|
||||||
|
|
||||||
Camera* getCamera();
|
Camera* getCamera();
|
||||||
|
//Defaults to 0.1f
|
||||||
|
void setAmbientLight(float stength);
|
||||||
//In units of Earth gravity (9.81 m/s^2)
|
//In units of Earth gravity (9.81 m/s^2)
|
||||||
void setGravity(const Vec3& gravity);
|
void setGravity(const Vec3& gravity);
|
||||||
void setGravity(float strength);
|
void setGravity(float strength);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
//TODO: Rework this file to only contain functions the frontend will need to access
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
//TODO: Rework this file to only contain functions the frontend will need to access
|
||||||
|
//Maybe a implementation define here?
|
||||||
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
@ -30,6 +30,7 @@ namespace nf {
|
|||||||
void render(Cubemap& in);
|
void render(Cubemap& in);
|
||||||
|
|
||||||
void doFrame(Camera* camera, float dT);
|
void doFrame(Camera* camera, float dT);
|
||||||
|
void setAmbient(float am);
|
||||||
|
|
||||||
~Renderer();
|
~Renderer();
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user