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