50 lines
1.1 KiB
C++
50 lines
1.1 KiB
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::drawEntities()
|
|
{
|
|
glm::mat4 viewMatrix = camera->getViewMatrix();
|
|
glm::mat4 projectionMatrix = camera->getProjectionMatrix();
|
|
for(Entity* e : entities)
|
|
{
|
|
glm::mat4 modelViewMatrix = viewMatrix * e->modelMatrix;
|
|
glm::mat4 mvp = projectionMatrix * modelViewMatrix;
|
|
Shader* shader = e->mat->getShader();
|
|
shader->bind();
|
|
e->mat->bindAttributes();
|
|
shader->bindMatrix(shader->getLocation("viewMatrix"), viewMatrix);
|
|
shader->bindMatrix(shader->getLocation("modelViewMatrix"), modelViewMatrix);
|
|
shader->bindMatrix(shader->getLocation("MVP"), mvp);
|
|
e->mesh->draw();
|
|
}
|
|
}
|
|
|
|
void Scene::setCamera(Camera* myCamera)
|
|
{
|
|
camera = myCamera;
|
|
}
|
|
|
|
Camera* Scene::getCamera()
|
|
{
|
|
return camera;
|
|
}
|