Remove "Drawable" virtual class to simplify class hierarchy

This commit is contained in:
Dane Johnson 2021-01-18 13:31:09 -06:00
parent 0f3dbdff64
commit 66bf7776c7
7 changed files with 17 additions and 25 deletions

View File

@ -1,14 +0,0 @@
#ifndef DRAWABLE_H
#define DRAWABLE_H
#include "Node.h"
#include "Material.h"
class Drawable : virtual public Node {
public:
virtual bool IsDrawable() const {return true;}
virtual void Draw() = 0;
Material *material;
};
#endif /* DRAWABLE_H */

View File

@ -38,6 +38,10 @@ void Mesh::SetupMesh() {
glBindVertexArray(0);
}
Mesh Mesh::FromFile(const char *filename) {
return Mesh();
}
void Mesh::Draw() {
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);

View File

@ -5,17 +5,20 @@
#include "types.h"
#include "Spatial.h"
#include "Drawable.h"
#include "Vertex.h"
#include "Index.h"
#include "Material.h"
class Mesh : public Spatial, public Drawable {
class Mesh : public Spatial {
public:
VertexList vertices;
IndexList indices;
Material *material;
Mesh();
~Mesh();
Mesh(VertexList vertices, IndexList indices);
static Mesh FromFile(const char *filename);
virtual bool IsDrawable() const {return true;}
virtual void Draw();
virtual void SetupMesh();
private:

View File

@ -14,6 +14,7 @@ public:
NodeList children;
static Node *GetRoot();
virtual bool IsDrawable() const;
virtual void Draw(){};
virtual bool IsTransformable() const;
private:
static Node *root;

View File

@ -4,7 +4,7 @@
#include "Node.h"
#include "Transform.h"
class Spatial : virtual public Node {
class Spatial : public Node {
public:
Transform transform;
virtual bool IsTransformable() const { return true;}

View File

@ -36,18 +36,18 @@ void render(Node *curr, Shader *shader, Matrix model) {
model = glm::translate(model, spatial->transform.position);
shader->UpdateModel(model);
}
Drawable *drawable = dynamic_cast<Drawable*>(curr);
if (drawable->material->usesColor) {
shader->UpdateColor(true, drawable->material->color);
Mesh *mesh = dynamic_cast<Mesh*>(curr);
if (mesh->material->usesColor) {
shader->UpdateColor(true, mesh->material->color);
} else {
shader->UpdateColor(false);
}
if (drawable->material->usesTex) {
shader->UpdateTex(true, drawable->material->tex);
if (mesh->material->usesTex) {
shader->UpdateTex(true, mesh->material->tex);
} else {
shader->UpdateTex(false);
}
drawable->Draw();
mesh->Draw();
}
for (Node *child : curr->children) {
render(child, shader, model);

View File

@ -7,7 +7,6 @@
#include "Node.h"
#include "Transform.h"
#include "Spatial.h"
#include "Drawable.h"
#include "Material.h"
#include "Mesh.h"
#include "Ball.h"
@ -36,7 +35,6 @@ public:
%include "Node.h"
%include "Spatial.h"
%include "Transform.h"
%include "Drawable.h"
%include "Material.h"
%include "Mesh.h"
%include "Ball.h"