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);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mesh Mesh::FromFile(const char *filename) {
|
||||||
|
return Mesh();
|
||||||
|
}
|
||||||
|
|
||||||
void Mesh::Draw() {
|
void Mesh::Draw() {
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
||||||
|
@ -5,17 +5,20 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "Spatial.h"
|
#include "Spatial.h"
|
||||||
#include "Drawable.h"
|
|
||||||
#include "Vertex.h"
|
#include "Vertex.h"
|
||||||
#include "Index.h"
|
#include "Index.h"
|
||||||
|
#include "Material.h"
|
||||||
|
|
||||||
class Mesh : public Spatial, public Drawable {
|
class Mesh : public Spatial {
|
||||||
public:
|
public:
|
||||||
VertexList vertices;
|
VertexList vertices;
|
||||||
IndexList indices;
|
IndexList indices;
|
||||||
|
Material *material;
|
||||||
Mesh();
|
Mesh();
|
||||||
~Mesh();
|
~Mesh();
|
||||||
Mesh(VertexList vertices, IndexList indices);
|
Mesh(VertexList vertices, IndexList indices);
|
||||||
|
static Mesh FromFile(const char *filename);
|
||||||
|
virtual bool IsDrawable() const {return true;}
|
||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
virtual void SetupMesh();
|
virtual void SetupMesh();
|
||||||
private:
|
private:
|
||||||
|
@ -14,6 +14,7 @@ public:
|
|||||||
NodeList children;
|
NodeList children;
|
||||||
static Node *GetRoot();
|
static Node *GetRoot();
|
||||||
virtual bool IsDrawable() const;
|
virtual bool IsDrawable() const;
|
||||||
|
virtual void Draw(){};
|
||||||
virtual bool IsTransformable() const;
|
virtual bool IsTransformable() const;
|
||||||
private:
|
private:
|
||||||
static Node *root;
|
static Node *root;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
|
|
||||||
class Spatial : virtual public Node {
|
class Spatial : public Node {
|
||||||
public:
|
public:
|
||||||
Transform transform;
|
Transform transform;
|
||||||
virtual bool IsTransformable() const { return true;}
|
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);
|
model = glm::translate(model, spatial->transform.position);
|
||||||
shader->UpdateModel(model);
|
shader->UpdateModel(model);
|
||||||
}
|
}
|
||||||
Drawable *drawable = dynamic_cast<Drawable*>(curr);
|
Mesh *mesh = dynamic_cast<Mesh*>(curr);
|
||||||
if (drawable->material->usesColor) {
|
if (mesh->material->usesColor) {
|
||||||
shader->UpdateColor(true, drawable->material->color);
|
shader->UpdateColor(true, mesh->material->color);
|
||||||
} else {
|
} else {
|
||||||
shader->UpdateColor(false);
|
shader->UpdateColor(false);
|
||||||
}
|
}
|
||||||
if (drawable->material->usesTex) {
|
if (mesh->material->usesTex) {
|
||||||
shader->UpdateTex(true, drawable->material->tex);
|
shader->UpdateTex(true, mesh->material->tex);
|
||||||
} else {
|
} else {
|
||||||
shader->UpdateTex(false);
|
shader->UpdateTex(false);
|
||||||
}
|
}
|
||||||
drawable->Draw();
|
mesh->Draw();
|
||||||
}
|
}
|
||||||
for (Node *child : curr->children) {
|
for (Node *child : curr->children) {
|
||||||
render(child, shader, model);
|
render(child, shader, model);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "Transform.h"
|
#include "Transform.h"
|
||||||
#include "Spatial.h"
|
#include "Spatial.h"
|
||||||
#include "Drawable.h"
|
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Ball.h"
|
#include "Ball.h"
|
||||||
@ -36,7 +35,6 @@ public:
|
|||||||
%include "Node.h"
|
%include "Node.h"
|
||||||
%include "Spatial.h"
|
%include "Spatial.h"
|
||||||
%include "Transform.h"
|
%include "Transform.h"
|
||||||
%include "Drawable.h"
|
|
||||||
%include "Material.h"
|
%include "Material.h"
|
||||||
%include "Mesh.h"
|
%include "Mesh.h"
|
||||||
%include "Ball.h"
|
%include "Ball.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user