ComputerGraphik TU WIEN
model.hpp
Go to the documentation of this file.
1 #ifndef MODEL_HPP
2 #define MODEL_HPP
3 
4 #include <vector>
5 #include <string>
6 #include <memory>
7 #include <GL/glew.h>
8 #include <glm/vec3.hpp>
9 #include <glm/vec4.hpp>
10 
11 class Texture;
12 
14 class Model {
15 
16  enum { VBO_POSITIONS = 0,
19  VBO_UVS = 3,
21  VBO_COUNT = 5};
22 public:
23  Model(const std::vector<float>& positions,
24  const std::vector<unsigned int>& indices,
25  const std::vector<unsigned int>& adjacentIndices,
26  const std::vector<float>& normals,
27  const std::vector<float>& uvs,
28  Texture* texture = 0);
29 
30  ~Model();
31 
32  GLuint getPosition() const { return vbo[VBO_POSITIONS]; }
33  GLuint getNormals() const { return vbo[VBO_NORMALS]; }
34  GLuint getIndices() const { return vbo[VBO_INDICES]; }
35  GLuint getIndicesAdj() const { return vbo[VBO_ADJ_INDICES]; }
36  GLuint getUVs() const { return vbo[VBO_UVS]; }
37  size_t getIndexCount() const { return indexCount; }
38  size_t getIndexAdjCount() const { return indexAdjCount; }
39  Texture* getTexture() const { return texture; }
40  float getShininess() const { return shininess; }
41  glm::vec4 getDiffuse() const { return diffuse; }
42  glm::vec4 getAmbient() const { return ambient; }
43  glm::vec4 getSpecular() const { return specular; }
44 
45  void setShininess(float val) { shininess = val; }
46  void setTexture(Texture* val) { texture = val; }
47  void setDiffuse(const glm::vec4& val) { diffuse = val; }
48  void setAmbient(const glm::vec4& val) { ambient = val; }
49  void setSpecular(const glm::vec4& val) { specular = val; }
50 
51  static void getTerrainModel(size_t width,
52  size_t height,
53  size_t bitPerPixel,
54  float cellSize,
55  std::vector<unsigned char>& data,
56  std::vector<float>& heights,
57  std::vector<float>& positions,
58  std::vector<unsigned int>& indices,
59  std::vector<float>& normals,
60  std::vector<float>& uvs);
61 
62  static void getCubeModel(std::vector<float>& positions,
63  std::vector<unsigned int>& indices,
64  std::vector<float>& normals,
65  std::vector<float>& uvs);
66 
67  static void getQuadModel(std::vector<float>& positions,
68  std::vector<unsigned int>& indices,
69  std::vector<float>& uvs,
70  float width,
71  float height);
72 
73  static void getSphereModel(std::vector<float>& positions,
74  std::vector<unsigned int>& indices,
75  std::vector<float>& normals,
76  std::vector<float>& uvs);
77 
78  static void loadModels(const std::string& modelPath, std::vector<std::unique_ptr<Model> >& models);
79 
80 private:
81  GLuint vbo[VBO_COUNT];
82  size_t indexCount;
83  size_t indexAdjCount;
85  float shininess;
86  glm::vec4 diffuse;
87  glm::vec4 ambient;
88  glm::vec4 specular;
89 };
90 
91 #endif //MODEL_HPP
static void getCubeModel(std::vector< float > &positions, std::vector< unsigned int > &indices, std::vector< float > &normals, std::vector< float > &uvs)
Definition: model.cpp:105
glm::vec4 diffuse
Definition: model.hpp:86
void setTexture(Texture *val)
Definition: model.hpp:46
Texture * getTexture() const
Definition: model.hpp:39
Definition: model.hpp:16
size_t getIndexCount() const
Definition: model.hpp:37
Encapsulates a graphical object model in the GPU.
Definition: model.hpp:14
static void getTerrainModel(size_t width, size_t height, size_t bitPerPixel, float cellSize, std::vector< unsigned char > &data, std::vector< float > &heights, std::vector< float > &positions, std::vector< unsigned int > &indices, std::vector< float > &normals, std::vector< float > &uvs)
Definition: model.cpp:232
void setAmbient(const glm::vec4 &val)
Definition: model.hpp:48
GLuint getIndicesAdj() const
Definition: model.hpp:35
size_t indexCount
Definition: model.hpp:82
Definition: model.hpp:18
Definition: model.hpp:20
static void loadModels(const std::string &modelPath, std::vector< std::unique_ptr< Model > > &models)
Definition: model.cpp:54
void setSpecular(const glm::vec4 &val)
Definition: model.hpp:49
size_t getIndexAdjCount() const
Definition: model.hpp:38
GLuint getIndices() const
Definition: model.hpp:34
Definition: model.hpp:17
GLuint vbo[VBO_COUNT]
Definition: model.hpp:81
Model(const std::vector< float > &positions, const std::vector< unsigned int > &indices, const std::vector< unsigned int > &adjacentIndices, const std::vector< float > &normals, const std::vector< float > &uvs, Texture *texture=0)
Definition: model.cpp:11
GLuint getPosition() const
Definition: model.hpp:32
size_t indexAdjCount
Definition: model.hpp:83
static void getQuadModel(std::vector< float > &positions, std::vector< unsigned int > &indices, std::vector< float > &uvs, float width, float height)
Definition: model.cpp:70
glm::vec4 specular
Definition: model.hpp:88
Definition: model.hpp:21
float getShininess() const
Definition: model.hpp:40
static void getSphereModel(std::vector< float > &positions, std::vector< unsigned int > &indices, std::vector< float > &normals, std::vector< float > &uvs)
Definition: model.cpp:304
float shininess
Definition: model.hpp:85
void setDiffuse(const glm::vec4 &val)
Definition: model.hpp:47
glm::vec4 getSpecular() const
Definition: model.hpp:43
~Model()
Definition: model.cpp:49
Encapsulates a texture in the GPU.
Definition: texture.hpp:10
glm::vec4 getAmbient() const
Definition: model.hpp:42
glm::vec4 getDiffuse() const
Definition: model.hpp:41
GLuint getUVs() const
Definition: model.hpp:36
void setShininess(float val)
Definition: model.hpp:45
Texture * texture
Definition: model.hpp:84
Definition: model.hpp:19
GLuint getNormals() const
Definition: model.hpp:33
glm::vec4 ambient
Definition: model.hpp:87