48 lines
973 B
C++
48 lines
973 B
C++
#include "scene.h"
|
|
#include "glassert.h"
|
|
#include <glm/glm.hpp>
|
|
#include <glm/ext.hpp>
|
|
#include "camera.h"
|
|
|
|
Scene::Scene()
|
|
{
|
|
|
|
}
|
|
|
|
Scene::~Scene()
|
|
{
|
|
for(Entity* e : entities)
|
|
delete(e);
|
|
}
|
|
|
|
void Scene::addEntity(Mesh& mesh, Material& mat)
|
|
{
|
|
entities.push_back(new Entity(NULL, mesh, mat));
|
|
}
|
|
|
|
void Scene::addEntity(Mesh& mesh)
|
|
{
|
|
Material default_material = Material();
|
|
entities.push_back(new Entity(NULL, mesh, default_material));
|
|
}
|
|
|
|
void Scene::drawEntities(GLuint programId)
|
|
{
|
|
glm::mat4 viewMatrix = camera->getViewMatrix();
|
|
glm::mat4 projectionMatrix = camera->getProjectionMatrix();
|
|
glAssert(GLuint viewMatrixUniform = glGetUniformLocation(programId, "viewMatrix"));
|
|
glAssert(glUniformMatrix4fv(viewMatrixUniform, 1, GL_FALSE, glm::value_ptr(viewMatrix)));
|
|
for(Entity* e : entities)
|
|
e->mesh.draw();
|
|
}
|
|
|
|
void Scene::setCamera(Camera* myCamera)
|
|
{
|
|
camera = myCamera;
|
|
}
|
|
|
|
Camera* Scene::getCamera()
|
|
{
|
|
return camera;
|
|
}
|