Added directional light type
This commit is contained in:
1 parent
5c10fdc1a4
commit
f749b29c31
10 files changed
+66
-54
No files matched your search
@@ -5,9 +5,9 @@
|
||||
|
||||
namespace nf {
|
||||
Gamestate::Gamestate(Application* app) :
|
||||
m_camera(app)
|
||||
camera(app)
|
||||
{
|
||||
m_app = app;
|
||||
this->app = app;
|
||||
}
|
||||
|
||||
void Gamestate::onEnter() {
|
||||
@@ -19,7 +19,7 @@ namespace nf {
|
||||
}
|
||||
|
||||
Camera* Gamestate::getCamera() {
|
||||
return &m_camera;
|
||||
return &camera;
|
||||
}
|
||||
|
||||
void Gamestate::render(Renderer& renderer) {
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace nf {
|
||||
|
||||
void IntroGamestate::update(double deltaTime) {
|
||||
if (m_counter >= 120) {
|
||||
m_app->changeState("Main State");
|
||||
app->changeState("Main State");
|
||||
}
|
||||
m_counter++;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,10 @@ namespace nf {
|
||||
return m_position;
|
||||
}
|
||||
|
||||
const Vec3& Camera::getRotation() {
|
||||
return m_front;
|
||||
}
|
||||
|
||||
void Camera::bind(Shader* shader) {
|
||||
glm::mat4 view;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace nf {
|
||||
|
||||
}
|
||||
|
||||
void Light::create(const Vec3& position, const Vec3& color, Type type, float strength) {
|
||||
void Light::create(const Vec3& position, const Vec3& color, float strength, Type type) {
|
||||
m_constructed = true;
|
||||
m_position = position;
|
||||
m_color = color;
|
||||
@@ -32,37 +32,33 @@ namespace nf {
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
void Light::setStrength(double strength) {
|
||||
m_strength = (float)strength;
|
||||
}
|
||||
|
||||
void Light::bind(Shader* shader, unsigned int lightNumber) {
|
||||
glm::vec3 pos(m_position.x, m_position.y, m_position.z);
|
||||
glm::vec3 color(m_color.x, m_color.y, m_color.z);
|
||||
std::string stringPos = "light[";
|
||||
std::string stringLocation = std::to_string(lightNumber);
|
||||
stringPos += stringLocation;
|
||||
stringPos += std::to_string(lightNumber);
|
||||
stringPos += "].";
|
||||
std::string lightPos = stringPos + (std::string)"pos";
|
||||
std::string lightColor = stringPos + (std::string)"color";
|
||||
std::string lightStrength = stringPos + (std::string)"strength";
|
||||
glm::vec3 pos(m_position.x, m_position.y, m_position.z);
|
||||
glm::vec3 color(m_color.x, m_color.y, m_color.z);
|
||||
shader->setUniform(lightPos, pos);
|
||||
shader->setUniform(lightColor, color);
|
||||
//switch (m_type) {
|
||||
// case Type::DIRECTIONAL: {
|
||||
// shader->setUniform(lightType.c_str(), 1);
|
||||
// std::string lightConsant = light + (std::string)"falloffConstant";
|
||||
// std::string lightLinear = light + (std::string)"falloffLinear";
|
||||
// std::string lightQuad = light + (std::string)"falloffQuad";
|
||||
// shader->setUniform(lightConsant.c_str(), 1.0f);
|
||||
// shader->setUniform(lightLinear.c_str(), 0.7f);
|
||||
// shader->setUniform(lightQuad.c_str(), 1.8f);
|
||||
// break;
|
||||
// }
|
||||
// case Type::POINT: {
|
||||
// //shader->setUniform(lightType.c_str(), 2);
|
||||
// break;
|
||||
// }
|
||||
// case Type::SPOTLIGHT: {
|
||||
// shader->setUniform(lightType.c_str(), 3);
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
shader->setUniform(lightStrength, m_strength);
|
||||
std::string lightType = stringPos + (std::string)"type";
|
||||
switch (m_type) {
|
||||
case Type::DIRECTIONAL: {
|
||||
shader->setUniform(lightType, 1);
|
||||
break;
|
||||
}
|
||||
case Type::POINT: {
|
||||
shader->setUniform(lightType, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Light::Type Light::getType() {
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace nf {
|
||||
void setPosition(double x, double y, double z);
|
||||
void setPosition(const Vec3& position);
|
||||
const Vec3& getPosition();
|
||||
const Vec3& getRotation();
|
||||
|
||||
void bind(Shader* shader);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace nf {
|
||||
|
||||
virtual void onExit();
|
||||
protected:
|
||||
Application* m_app;
|
||||
Camera m_camera;
|
||||
Application* app;
|
||||
Camera camera;
|
||||
};
|
||||
}
|
||||
@@ -8,15 +8,15 @@ namespace nf {
|
||||
public:
|
||||
enum class Type {
|
||||
DIRECTIONAL,
|
||||
POINT,
|
||||
SPOTLIGHT
|
||||
POINT
|
||||
};
|
||||
Light();
|
||||
|
||||
void create(const Vec3& position, const Vec3& color, Type type = Type::POINT, float strength = 1.0f);
|
||||
void create(const Vec3& position, const Vec3& color, float strength = 1.0f, Type type = Type::POINT);
|
||||
bool isConstructed();
|
||||
void setPosition(const Vec3& position);
|
||||
void setColor(const Vec3& color);
|
||||
void setStrength(double strength);
|
||||
|
||||
void bind(Shader* shader, unsigned int lightNumber);
|
||||
|
||||
|
||||
Reference in new issue
Block a user