2013-05-10 16:59:30 +00:00
|
|
|
#ifndef MESH_HPP__
|
|
|
|
#define MESH_HPP__
|
|
|
|
|
|
|
|
#include "gl.hpp"
|
|
|
|
#include "shader.hpp"
|
|
|
|
#include "texture.hpp"
|
|
|
|
#include <vector>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include "glm/glm.hpp"
|
|
|
|
#include "glm/gtc/matrix_transform.hpp"
|
2013-05-10 20:33:22 +00:00
|
|
|
#include "glm/gtc/type_ptr.hpp"
|
2013-05-11 17:03:51 +00:00
|
|
|
#include "shared.hpp"
|
2013-05-10 16:59:30 +00:00
|
|
|
|
|
|
|
namespace GL
|
|
|
|
{
|
|
|
|
struct Vertex
|
|
|
|
{
|
2013-05-10 20:33:22 +00:00
|
|
|
glm::vec3 vert;
|
|
|
|
glm::vec3 normal;
|
|
|
|
glm::vec2 tex;
|
2013-05-10 16:59:30 +00:00
|
|
|
};
|
|
|
|
|
2013-05-11 23:36:39 +00:00
|
|
|
struct Material
|
|
|
|
{
|
|
|
|
Material() :
|
2013-05-12 23:37:14 +00:00
|
|
|
ambient(0, 0, 0),
|
|
|
|
diffuse(0, 0, 0),
|
2013-05-12 00:46:07 +00:00
|
|
|
specular(0, 0, 0),
|
2013-05-12 11:20:33 +00:00
|
|
|
specular_power(60.0),
|
2013-05-12 00:46:07 +00:00
|
|
|
alpha_mod(1.0f)
|
2013-05-11 23:36:39 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
glm::vec3 ambient;
|
|
|
|
glm::vec3 diffuse;
|
2013-05-12 00:46:07 +00:00
|
|
|
glm::vec3 specular;
|
2013-05-12 11:20:33 +00:00
|
|
|
float specular_power;
|
2013-05-12 00:46:07 +00:00
|
|
|
float alpha_mod;
|
2013-05-11 23:36:39 +00:00
|
|
|
std1::shared_ptr<Texture> diffuse_map;
|
2013-05-12 11:28:39 +00:00
|
|
|
std1::shared_ptr<Texture> ambient_map;
|
2013-05-11 23:36:39 +00:00
|
|
|
};
|
|
|
|
|
2013-05-10 16:59:30 +00:00
|
|
|
class Mesh
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Mesh();
|
|
|
|
~Mesh();
|
|
|
|
|
2013-05-17 22:31:25 +00:00
|
|
|
std1::shared_ptr<std::vector<Vertex> > get_vertex() const { return vertex; }
|
2013-05-14 00:33:51 +00:00
|
|
|
const Material& get_material() const { return material; }
|
|
|
|
|
2013-05-10 20:33:22 +00:00
|
|
|
void set_vertices(std::vector<Vertex> vertex);
|
2013-05-11 23:36:39 +00:00
|
|
|
void set_vertices(const std1::shared_ptr<std::vector<Vertex> >& vertex);
|
2013-05-10 20:33:22 +00:00
|
|
|
void set_vertex_type(GLenum type);
|
2013-05-11 23:36:39 +00:00
|
|
|
void set_material(const Material& material);
|
2013-05-12 19:46:08 +00:00
|
|
|
void set_blank(const std1::shared_ptr<Texture>& blank);
|
2013-05-11 23:36:39 +00:00
|
|
|
void set_shader(const std1::shared_ptr<Shader>& shader);
|
2013-05-10 16:59:30 +00:00
|
|
|
|
|
|
|
void set_model(const glm::mat4& model);
|
|
|
|
void set_view(const glm::mat4& view);
|
|
|
|
void set_projection(const glm::mat4& projection);
|
2013-05-14 00:07:53 +00:00
|
|
|
void set_eye(const glm::vec3& eye_pos);
|
2013-05-10 16:59:30 +00:00
|
|
|
|
2013-05-14 00:07:53 +00:00
|
|
|
void set_light_pos(const glm::vec3& light_pos);
|
2013-05-11 23:36:39 +00:00
|
|
|
void set_light_ambient(const glm::vec3& light_ambient);
|
|
|
|
|
2013-05-10 16:59:30 +00:00
|
|
|
void render();
|
|
|
|
|
|
|
|
private:
|
|
|
|
GLuint vbo;
|
|
|
|
GLenum vertex_type;
|
2013-05-11 23:36:39 +00:00
|
|
|
std1::shared_ptr<std::vector<Vertex> > vertex;
|
|
|
|
std1::shared_ptr<Shader> shader;
|
2013-05-12 19:46:08 +00:00
|
|
|
std1::shared_ptr<Texture> blank;
|
2013-05-11 23:36:39 +00:00
|
|
|
|
|
|
|
Material material;
|
2013-05-14 00:07:53 +00:00
|
|
|
glm::vec3 light_pos;
|
2013-05-11 23:36:39 +00:00
|
|
|
glm::vec3 light_ambient;
|
2013-05-14 00:07:53 +00:00
|
|
|
glm::vec3 eye_pos;
|
2013-05-10 16:59:30 +00:00
|
|
|
|
|
|
|
glm::mat4 model;
|
|
|
|
glm::mat4 view;
|
|
|
|
glm::mat4 projection;
|
|
|
|
glm::mat4 mvp;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|