Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
model.hpp
Go to the documentation of this file.
1 #ifndef __MODEL__
2 #define __MODEL__
3 
4 #include <vector>
5 #include <fstream>
6 #include <Eigen/Dense>
7 
8 namespace Tucano
9 {
10 
16 class Model {
17 
18 protected:
19 
21  Eigen::Affine3f model_matrix;
22 
24  Eigen::Vector3f objectCenter;
25 
27  Eigen::Vector3f centroid;
28 
30  float radius;
31 
33  float scale;
34 
36  Eigen::Vector4f default_color = Eigen::Vector4f (0.7, 0.7, 0.7, 1.0);
37 
38 public:
39 
43  Model(void)
44  {
46  objectCenter = Eigen::Vector3f::Zero();
47  centroid = Eigen::Vector3f::Zero();
48  radius = 1.0;
49  scale = 1.0;
50  }
51 
56  Eigen::Vector4f getColor (void)
57  {
58  return default_color;
59  }
60 
65  void setColor (const Eigen::Vector4f & color)
66  {
67  default_color = color;
68  }
69 
70 
75  virtual Eigen::Vector3f getObjectCenter (void) const
76  {
77  return objectCenter;
78  }
79 
84  virtual Eigen::Vector3f getCentroid (void) const
85  {
86  return centroid;
87  }
88 
94  virtual float getBoundingSphereRadius (void) const
95  {
96  return radius;
97  }
98 
103  Eigen::Affine3f getModelMatrix (void) const
104  {
105  return model_matrix;
106  }
107 
112  Eigen::Affine3f* modelMatrix (void)
113  {
114  return &model_matrix;
115  }
116 
121  void setModelMatrix (const Eigen::Affine3f &m)
122  {
123  model_matrix = m;
124  }
125 
126 
131  float getScale (void) const
132  {
133  return scale;
134  }
135 
142  {
143  model_matrix.scale(scale);
144  model_matrix.translate(-centroid);
145  }
146 
151  {
152  model_matrix.translate(centroid);
153  model_matrix.scale(1.0/scale);
154  }
155 
159  void resetModelMatrix (void)
160  {
161  model_matrix = Eigen::Affine3f::Identity();
162  }
163 
164 };
165 
166 }
167 #endif
Eigen::Vector4f getColor(void)
Returns the default color of the model.
Definition: model.hpp:56
Eigen::Affine3f * modelMatrix(void)
Returns a pointer to the model matrix.
Definition: model.hpp:112
Eigen::Vector3f objectCenter
Center of the mesh object.
Definition: model.hpp:24
virtual Eigen::Vector3f getCentroid(void) const
Returns the centroid of the model.
Definition: model.hpp:84
Eigen::Vector4f default_color
Default color.
Definition: model.hpp:36
void desnormalizeModelMatrix(void)
Desnormalize model matrix.
Definition: model.hpp:150
Definition: bufferobject.hpp:34
The Model class is a holder for any kind of model, such as meshes, point clouds, surfaces ...
Definition: model.hpp:16
float getScale(void) const
Returns the scale factor for fitting the model inside a unit cube.
Definition: model.hpp:131
void setColor(const Eigen::Vector4f &color)
Sets the default color of the model.
Definition: model.hpp:65
Eigen::Vector3f centroid
Object&#39;s centroid (different from center of bounding box)
Definition: model.hpp:27
float scale
The normalization scale factor, scales the model matrix to fit the model inside a unit cube...
Definition: model.hpp:33
void setModelMatrix(const Eigen::Affine3f &m)
Sets the model matrix.
Definition: model.hpp:121
Model(void)
Definition: model.hpp:43
void resetModelMatrix(void)
Resets the model matrix.
Definition: model.hpp:159
virtual Eigen::Vector3f getObjectCenter(void) const
Returns the center of the axis-aligned bounding box.
Definition: model.hpp:75
Eigen::Affine3f model_matrix
Model matrix, holds information about the models location and orientation.
Definition: model.hpp:21
Eigen::Affine3f getModelMatrix(void) const
Returns the model matrix.
Definition: model.hpp:103
void normalizeModelMatrix(void)
Normalize model matrix to center and scale model. The model matrix will include a translation to plac...
Definition: model.hpp:141
virtual float getBoundingSphereRadius(void) const
Definition: model.hpp:94
float radius
Radius of the mesh bounding sphere.
Definition: model.hpp:30