Remove "Drawable" virtual class to simplify class hierarchy
This commit is contained in:
parent
0f3dbdff64
commit
66bf7776c7
@ -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 */
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;}
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user