75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#include "scene.h"
|
|
#include "glassert.h"
|
|
#include <glm/glm.hpp>
|
|
#include <glm/ext.hpp>
|
|
#include "camera.h"
|
|
#include "entity.h"
|
|
#include "shader.h"
|
|
#include "material.h"
|
|
|
|
// MAIN METHODS
|
|
|
|
Scene::~Scene()
|
|
{
|
|
for(Entity* e : entities)
|
|
delete(e);
|
|
}
|
|
|
|
void Scene::drawAll()
|
|
{
|
|
glm::mat4 viewMatrix = camera->getViewMatrix();
|
|
glm::mat4 projectionMatrix = camera->getProjectionMatrix();
|
|
for(Entity* e : entities)
|
|
{
|
|
Shader* shader = e->getShader();
|
|
shader->bind();
|
|
if(e->getMaterial()->requireLights())
|
|
{
|
|
directionnalLights.bind(shader->getLocation("dirLights"), shader->getLocation("nbDirLights"), shader);
|
|
pointLights.bind(shader->getLocation("pointLights"), shader->getLocation("nbPointLights"), shader);
|
|
}
|
|
e->draw(viewMatrix, projectionMatrix);
|
|
}
|
|
}
|
|
|
|
// ENTITIES
|
|
|
|
void Scene::addEntity(Entity* parent, Mesh* mesh, Material* mat)
|
|
{
|
|
entities.push_back(new Entity(parent, mesh, mat));
|
|
}
|
|
|
|
void Scene::addEntity(Mesh* mesh, Material* mat)
|
|
{
|
|
entities.push_back(new Entity(NULL, mesh, mat));
|
|
}
|
|
|
|
void Scene::addEntity(Entity* entity)
|
|
{
|
|
entities.push_back(entity);
|
|
}
|
|
|
|
// LIGHTS
|
|
|
|
void Scene::addDirectionnalLight(const glm::vec3 &position, const glm::vec3 &color)
|
|
{
|
|
directionnalLights.addLight(position, color);
|
|
}
|
|
|
|
void Scene::addPointLight(const glm::vec3 &position, const glm::vec3 &color)
|
|
{
|
|
pointLights.addLight(position, color);
|
|
}
|
|
|
|
// CAMERA
|
|
|
|
void Scene::setCamera(Camera* myCamera)
|
|
{
|
|
camera = myCamera;
|
|
}
|
|
|
|
Camera* Scene::getCamera()
|
|
{
|
|
return camera;
|
|
}
|