diff --git a/asciientity.cpp b/asciientity.cpp index fc0be16..9035a8e 100644 --- a/asciientity.cpp +++ b/asciientity.cpp @@ -1,5 +1,6 @@ #include "asciientity.h" #include +#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) +{ + +} diff --git a/asciientity.h b/asciientity.h index 9a18172..a3b4963 100644 --- a/asciientity.h +++ b/asciientity.h @@ -6,9 +6,12 @@ #include #include #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 diff --git a/basicmodule.cpp b/basicmodule.cpp index 9990890..dc76df2 100644 --- a/basicmodule.cpp +++ b/basicmodule.cpp @@ -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()); } diff --git a/basicmodule.h b/basicmodule.h index 31b4718..4743821 100644 --- a/basicmodule.h +++ b/basicmodule.h @@ -6,21 +6,21 @@ #include class Shader; -class Entity; +class PhongEntity; class Camera; class BasicModule : public Module { protected: Shader* shader; - std::vector entities; + std::vector 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); }; diff --git a/entity.h b/entity.h index 15fca1a..af85a36 100644 --- a/entity.h +++ b/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 + diff --git a/entity.cpp b/phongentity.cpp similarity index 70% rename from entity.cpp rename to phongentity.cpp index 9e8cf3e..ece4d4a 100644 --- a/entity.cpp +++ b/phongentity.cpp @@ -1,12 +1,12 @@ -#include "entity.h" +#include "phongentity.h" #include "shader.h" #include #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; } diff --git a/phongentity.h b/phongentity.h new file mode 100644 index 0000000..dd7d8d8 --- /dev/null +++ b/phongentity.h @@ -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 diff --git a/resourcebase.cpp b/resourcebase.cpp index e409251..7fec541 100644 --- a/resourcebase.cpp +++ b/resourcebase.cpp @@ -4,7 +4,7 @@ ResourceBase::DataBase ResourceBase::textures; ResourceBase::DataBase ResourceBase::meshes; ResourceBase::DataBase ResourceBase::materials; ResourceBase::DataBase ResourceBase::shaders; -ResourceBase::DataBase ResourceBase::entities; +ResourceBase::DataBase ResourceBase::entities; ResourceBase::DataBase 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); } diff --git a/resourcebase.h b/resourcebase.h index 918df97..8a59f22 100644 --- a/resourcebase.h +++ b/resourcebase.h @@ -5,7 +5,7 @@ class Texture; class Mesh; class Material; class Shader; -class Entity; +class PhongEntity; class Lights; #include @@ -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 meshes; static DataBase materials; static DataBase shaders; - static DataBase entities; + static DataBase entities; static DataBase lights; }; diff --git a/skyboxmodule.cpp b/skyboxmodule.cpp index 340788e..9407292 100644 --- a/skyboxmodule.cpp +++ b/skyboxmodule.cpp @@ -1,7 +1,7 @@ #include #include #include "skyboxmodule.h" -#include "entity.h" +#include "phongentity.h" #include "shader.h" #include "texture.h" #include "camera.h" diff --git a/sparrowRenderer.pro b/sparrowRenderer.pro index f3543db..8d2ae06 100644 --- a/sparrowRenderer.pro +++ b/sparrowRenderer.pro @@ -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