zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Model.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
64 #ifndef ZENI_MODEL_H
65 #define ZENI_MODEL_H
66 
67 #include <Zeni/Coordinate.h>
68 #include <Zeni/Vector3f.h>
69 
70 #include <memory>
71 
72 struct Lib3dsFile;
73 struct Lib3dsMesh;
75 struct Lib3dsNode;
76 
77 namespace Zeni {
78 
79  class ZENI_GRAPHICS_DLL Model;
80  struct Quaternion;
81 
82  class ZENI_GRAPHICS_DLL Model_Visitor {
83  public:
85  virtual ~Model_Visitor() {}
86 
87  // Note visiting function
88  virtual void operator()(const Model & /*model*/, Lib3dsNode * const & /*node*/) {}
89 
90  // Mesh visiting function
91  virtual void operator()(const Model & /*model*/, Lib3dsMeshInstanceNode * const & /*node*/, Lib3dsMesh * const & /*mesh*/) {}
92  };
93 
94  class ZENI_GRAPHICS_DLL Model_Extents : public Model_Visitor {
95  public:
96  Model_Extents();
97 
98  virtual void operator()(const Model &model, Lib3dsMeshInstanceNode * const &node, Lib3dsMesh * const &mesh);
99 
100  Point3f lower_bound, upper_bound;
101  bool started;
102  };
103 
104 #ifndef TEMP_DISABLE
105  class ZENI_GRAPHICS_DLL Model {
106  public:
108  Model(const String &filename, const bool align_normals_ = false);
109  Model(const Model &rhs);
110  ~Model();
111 
112  Model & operator =(const Model &rhs);
113 
114  // Accessors
115  inline Lib3dsFile * const & get_file() const;
116  Point3f get_position() const;
117  inline const Model_Extents & get_extents() const;
118  float get_keyframes() const;
119  inline const Vector3f & get_scale() const;
120  inline std::pair<Vector3f, float> get_rotate() const;
121  inline const Point3f & get_translate() const;
122  inline const float & get_keyframe() const;
123  inline bool will_do_normal_alignment() const; // Find out whether the Model will try to fix broken normals before rendering
124 
125  // Modifiers
126  inline void set_scale(const Vector3f &multiplier);
127  inline void set_rotate(const float &angle, const Vector3f &ray);
128  inline void set_rotate(const Quaternion &quaternion);
129  inline void set_translate(const Point3f &vector);
130  void set_keyframe(const float &keyframe);
131  inline void do_normal_alignment(const bool align_normals_ = true); // Set whether Model should try to fix broken normals before rendering
132 
133  // Post-Order Traversal
134  void visit_nodes(Model_Visitor &mv, Lib3dsNode * node = 0) const;
135  void visit_meshes(Model_Visitor &mv, Lib3dsNode * node = 0, Lib3dsMesh * const &mesh = 0) const;
136 
137  void render() const;
138 
139  // Thread-Unsafe versions
140  inline Lib3dsFile * const & thun_get_file() const;
141 
142  private:
143  String m_filename;
144  Lib3dsFile *m_file;
145  float m_keyframe;
146  bool m_align_normals;
147 
148  mutable Model_Visitor *m_unrenderer;
149 
150  Model_Extents m_extents;
151  Point3f m_position;
152 
153  Vector3f m_scale, m_rotate;
154  Point3f m_translate;
155  float m_rotate_angle;
156 
157 // class ZENI_GRAPHICS_DLL Loader : public Task {
158 // Loader(const Loader &);
159 // Loader & operator=(const Loader &);
160 //
161 // public:
162 // Loader(Model &model) : m_model(model) {}
163 //
164 // int function();
165 //
166 // private:
167 // Model &m_model;
168 // };
169 
170  void load();
171 
172 // mutable Loader m_loader;
173 // mutable Runonce_Computation m_loader_op;
174  };
175 #endif
176 
177  struct ZENI_GRAPHICS_DLL Model_Init_Failure : public Error {
178  Model_Init_Failure() : Error("Zeni Model Failed to Initialize Correctly") {}
179  };
180 
181  struct ZENI_GRAPHICS_DLL Model_Render_Failure : public Error {
182  Model_Render_Failure() : Error("Zeni Model Failed to Render") {}
183  };
184 
185 }
186 
187 #endif
An Abstraction of a 3D Model.
Definition: Model.h:105
GLdouble angle
Definition: glew.h:8396
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
virtual void operator()(const Model &, Lib3dsNode *const &)
Definition: Model.h:88
A 3D Point represented with floats.
Definition: Coordinate.h:133
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
A visitor base class.
Definition: Model.h:82
A Featureful Quaternion Class.
Definition: Quaternion.h:44
virtual ~Model_Visitor()
Definition: Model.h:85
Point3f upper_bound
The bounding box of model, first frame only if animated.
Definition: Model.h:100
A visitor for determining the extents or bounds of a model.
Definition: Model.h:94
The Error Class.
Definition: Error.h:52
virtual void operator()(const Model &, Lib3dsMeshInstanceNode *const &, Lib3dsMesh *const &)
Definition: Model.h:91