did some small refactoring
This commit is contained in:
parent
2012905a73
commit
192413642c
@ -1,5 +1,6 @@
|
||||
#include "asciientity.h"
|
||||
#include <glm/ext.hpp>
|
||||
#include "texture.h"
|
||||
|
||||
#define TEX_ID 0
|
||||
|
||||
@ -17,6 +18,10 @@ void ASCIIMaterial::bindAttributes()
|
||||
void ASCIIEntity::updateModelView()
|
||||
{
|
||||
modelView = glm::translate(glm::mat4(), glm::vec3(position, 0));
|
||||
modelView = glm::scalemodel(modelView, glm::vec3(size, 1));
|
||||
modelView = glm::scale(modelView, glm::vec3(size, 1));
|
||||
}
|
||||
|
||||
void ASCIIEntity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -6,9 +6,12 @@
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include "material.h"
|
||||
#include "resourcebase.h"
|
||||
|
||||
class Texture;
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class ASCIIMaterial : public Material
|
||||
{
|
||||
Texture* glyphMap;
|
||||
@ -29,7 +32,7 @@ public:
|
||||
virtual void bindAttributes();
|
||||
};
|
||||
|
||||
class ASCIIEntity
|
||||
class ASCIIEntity : public Entity
|
||||
{
|
||||
GLuint rows;
|
||||
GLuint columns;
|
||||
@ -55,6 +58,8 @@ public:
|
||||
// TODO set all chars to ' '
|
||||
updateModelView();
|
||||
}
|
||||
|
||||
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix);
|
||||
};
|
||||
|
||||
#endif // ASCIIENTITY_H
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "basicmodule.h"
|
||||
#include "shader.h"
|
||||
#include "entity.h"
|
||||
#include "phongentity.h"
|
||||
#include "camera.h"
|
||||
|
||||
void BasicModule::addEntity(Entity* myEntity)
|
||||
void BasicModule::addEntity(PhongEntity* myEntity)
|
||||
{
|
||||
entities.push_back(myEntity);
|
||||
}
|
||||
@ -12,7 +12,7 @@ void BasicModule::renderGL(Camera* myCamera)
|
||||
{
|
||||
shader->bind();
|
||||
bindModule();
|
||||
for(Entity* e : entities)
|
||||
for(PhongEntity* e : entities)
|
||||
e->draw(myCamera->getViewMatrix(), myCamera->getProjectionMatrix());
|
||||
}
|
||||
|
||||
|
@ -6,21 +6,21 @@
|
||||
#include <cstddef>
|
||||
|
||||
class Shader;
|
||||
class Entity;
|
||||
class PhongEntity;
|
||||
class Camera;
|
||||
|
||||
class BasicModule : public Module
|
||||
{
|
||||
protected:
|
||||
Shader* shader;
|
||||
std::vector<Entity*> entities;
|
||||
std::vector<PhongEntity*> entities;
|
||||
|
||||
BasicModule(Shader* myShader = NULL) : shader(myShader) {}
|
||||
|
||||
virtual void bindModule() = 0;
|
||||
|
||||
public:
|
||||
void addEntity(Entity* myEntity);
|
||||
void addEntity(PhongEntity* myEntity);
|
||||
void virtual renderGL(Camera* myCamera);
|
||||
};
|
||||
|
||||
|
23
entity.h
23
entity.h
@ -1,24 +1,11 @@
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include "glm/mat4x4.hpp"
|
||||
|
||||
class Mesh;
|
||||
class Material;
|
||||
class Shader;
|
||||
#ifndef ENTITY
|
||||
#define ENTITY
|
||||
|
||||
class Entity
|
||||
{
|
||||
protected:
|
||||
Mesh* mesh;
|
||||
Material* mat;
|
||||
glm::mat4 modelMatrix;
|
||||
public:
|
||||
Entity(Mesh* myMesh, Material* myMat);
|
||||
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix);
|
||||
glm::mat4* getTransform();
|
||||
Shader* getShader();
|
||||
Material* getMaterial();
|
||||
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix) = 0;
|
||||
};
|
||||
|
||||
#endif // ENTITY_H
|
||||
#endif // ENTITY
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include "entity.h"
|
||||
#include "phongentity.h"
|
||||
#include "shader.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include "material.h"
|
||||
#include "mesh.h"
|
||||
|
||||
Entity::Entity(Mesh* myMesh, Material* myMat) : mesh(myMesh), mat(myMat) {}
|
||||
PhongEntity::PhongEntity(Mesh* myMesh, Material* myMat) : mesh(myMesh), mat(myMat) {}
|
||||
|
||||
void Entity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix)
|
||||
void PhongEntity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix)
|
||||
{
|
||||
glm::mat4 modelViewMatrix = viewMatrix * modelMatrix;
|
||||
glm::mat4 mvp = projectionMatrix * modelViewMatrix;
|
||||
@ -20,17 +20,17 @@ void Entity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix)
|
||||
mesh->draw();
|
||||
}
|
||||
|
||||
glm::mat4* Entity::getTransform()
|
||||
glm::mat4* PhongEntity::getTransform()
|
||||
{
|
||||
return &modelMatrix;
|
||||
}
|
||||
|
||||
Shader* Entity::getShader()
|
||||
Shader* PhongEntity::getShader()
|
||||
{
|
||||
return mat->getShader();
|
||||
}
|
||||
|
||||
Material* Entity::getMaterial()
|
||||
Material* PhongEntity::getMaterial()
|
||||
{
|
||||
return mat;
|
||||
}
|
26
phongentity.h
Normal file
26
phongentity.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef PHONGENTITY_H
|
||||
#define PHONGENTITY_H
|
||||
|
||||
#include "glm/mat4x4.hpp"
|
||||
|
||||
class Mesh;
|
||||
class Material;
|
||||
class Shader;
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
class PhongEntity : public Entity
|
||||
{
|
||||
protected:
|
||||
Mesh* mesh;
|
||||
Material* mat;
|
||||
glm::mat4 modelMatrix;
|
||||
public:
|
||||
PhongEntity(Mesh* myMesh, Material* myMat);
|
||||
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix);
|
||||
glm::mat4* getTransform();
|
||||
Shader* getShader();
|
||||
Material* getMaterial();
|
||||
};
|
||||
|
||||
#endif // PHONGENTITY_H
|
@ -4,7 +4,7 @@ ResourceBase::DataBase<Texture> ResourceBase::textures;
|
||||
ResourceBase::DataBase<Mesh> ResourceBase::meshes;
|
||||
ResourceBase::DataBase<Material> ResourceBase::materials;
|
||||
ResourceBase::DataBase<Shader> ResourceBase::shaders;
|
||||
ResourceBase::DataBase<Entity> ResourceBase::entities;
|
||||
ResourceBase::DataBase<PhongEntity> ResourceBase::entities;
|
||||
ResourceBase::DataBase<Lights> ResourceBase::lights;
|
||||
|
||||
void ResourceBase::setTexture(const std::string &textureName, Texture* myTexture)
|
||||
@ -27,7 +27,7 @@ void ResourceBase::setShader(const std::string &shaderName, Shader* myShader)
|
||||
shaders.add(shaderName, myShader);
|
||||
}
|
||||
|
||||
void ResourceBase::setEntity(const std::string &entityName, Entity* myEntity)
|
||||
void ResourceBase::setEntity(const std::string &entityName, PhongEntity* myEntity)
|
||||
{
|
||||
entities.add(entityName, myEntity);
|
||||
}
|
||||
@ -58,7 +58,7 @@ Shader* ResourceBase::getShader(const std::string &shaderName)
|
||||
return shaders.get(shaderName);
|
||||
}
|
||||
|
||||
Entity* ResourceBase::getEntity(const std::string &entityName)
|
||||
PhongEntity* ResourceBase::getEntity(const std::string &entityName)
|
||||
{
|
||||
return entities.get(entityName);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ class Texture;
|
||||
class Mesh;
|
||||
class Material;
|
||||
class Shader;
|
||||
class Entity;
|
||||
class PhongEntity;
|
||||
class Lights;
|
||||
|
||||
#include <unordered_map>
|
||||
@ -22,14 +22,14 @@ public:
|
||||
static void setMesh(const std::string &meshName, Mesh* myMesh);
|
||||
static void setMaterial(const std::string &materialName, Material* myMaterial);
|
||||
static void setShader(const std::string &shaderName, Shader* myShader);
|
||||
static void setEntity(const std::string &entityName, Entity* myEntity);
|
||||
static void setEntity(const std::string &entityName, PhongEntity* myEntity);
|
||||
static void setLights(const std::string &lightsName, Lights* myLights);
|
||||
|
||||
static Texture* getTexture(const std::string &textureName);
|
||||
static Mesh* getMesh(const std::string &meshName);
|
||||
static Material* getMaterial(const std::string &materialName);
|
||||
static Shader* getShader(const std::string &shaderName);
|
||||
static Entity* getEntity(const std::string &entityName);
|
||||
static PhongEntity* getEntity(const std::string &entityName);
|
||||
static Lights* getLights(const std::string &lightsName);
|
||||
|
||||
protected:
|
||||
@ -62,7 +62,7 @@ protected:
|
||||
static DataBase<Mesh> meshes;
|
||||
static DataBase<Material> materials;
|
||||
static DataBase<Shader> shaders;
|
||||
static DataBase<Entity> entities;
|
||||
static DataBase<PhongEntity> entities;
|
||||
static DataBase<Lights> lights;
|
||||
};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/mat3x3.hpp>
|
||||
#include "skyboxmodule.h"
|
||||
#include "entity.h"
|
||||
#include "phongentity.h"
|
||||
#include "shader.h"
|
||||
#include "texture.h"
|
||||
#include "camera.h"
|
||||
|
@ -29,7 +29,6 @@ SOURCES += shader.cpp \
|
||||
texture.cpp \
|
||||
phongmaterial.cpp \
|
||||
sphere.cpp \
|
||||
entity.cpp \
|
||||
lights.cpp \
|
||||
sparrowrenderer.cpp \
|
||||
resourcebase.cpp \
|
||||
@ -40,7 +39,8 @@ SOURCES += shader.cpp \
|
||||
meshbuilder.cpp \
|
||||
mesh.cpp \
|
||||
asciimodule.cpp \
|
||||
asciientity.cpp
|
||||
asciientity.cpp \
|
||||
phongentity.cpp
|
||||
|
||||
HEADERS += shader.h \
|
||||
camera.h \
|
||||
@ -50,7 +50,6 @@ HEADERS += shader.h \
|
||||
texture.h \
|
||||
phongmaterial.h \
|
||||
sphere.h \
|
||||
entity.h \
|
||||
lights.h \
|
||||
sparrowrenderer.h \
|
||||
resourcebase.h \
|
||||
@ -64,7 +63,9 @@ HEADERS += shader.h \
|
||||
mesh.h \
|
||||
image.h \
|
||||
asciimodule.h \
|
||||
asciientity.h
|
||||
asciientity.h \
|
||||
phongentity.h \
|
||||
entity.h
|
||||
|
||||
OTHER_FILES += *.frag *.vert *.glsl *.todo
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user