RigsofRods
Soft-body Physics Simulation
Mesh.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #ifndef _Hydrax_Mesh_H_
26 #define _Hydrax_Mesh_H_
27 
28 #include "Prerequisites.h"
29 
30 #include "Help.h"
31 #include "Image.h"
32 
35 
38 
39 namespace Hydrax
40 {
41  class Hydrax;
42 
46  class Mesh
47  {
48  public:
52  {
53  float x,y,z;
54  float nx,ny,nz;
55  float tu,tv;
56  };
57 
61  {
62  float x,y,z;
63  float nx,ny,nz;
64  };
65 
69  {
70  float x,y,z;
71  float tu,tv;
72  };
73 
76  struct POS_VERTEX
77  {
78  float x,y,z;
79  };
80 
84  {
87  VT_POS_UV = 2,
88  VT_POS = 3,
89  };
90 
93  struct Options
94  {
98  : MeshComplexity(128)
99  , MeshSize(Size(0))
100  , MeshStrength(10)
102  {
103  }
104 
110  Options(const int &meshComplexity, const Size &meshSize, const VertexType &meshVertexType)
111  : MeshComplexity(meshComplexity)
112  , MeshSize(meshSize)
113  , MeshStrength(10)
114  , MeshVertexType(meshVertexType)
115  {
116  }
117 
124  Options(const int &meshComplexity, const Size &meshSize, const float &meshStrength, const VertexType &meshVertexType)
125  : MeshComplexity(meshComplexity)
126  , MeshSize(meshSize)
127  , MeshStrength(meshStrength)
128  , MeshVertexType(meshVertexType)
129  {
130  }
131 
140  };
141 
145  Mesh(Hydrax *h);
146 
149  ~Mesh();
150 
155  void setOptions(const Options &Options);
156 
160  void setMaterialName(const Ogre::String &MaterialName);
161 
165  void create();
166 
169  void remove();
170 
176  bool updateGeometry(const int &numVer, void* verArray);
177 
182  bool isPointInGrid(const Ogre::Vector2 &Position);
183 
188  Ogre::Vector2 getGridPosition(const Ogre::Vector2 &Position);
189 
194  const Ogre::Vector3 getObjectSpacePosition(const Ogre::Vector3& WorldSpacePosition) const;
195 
200  const Ogre::Vector3 getWorldSpacePosition(const Ogre::Vector3& ObjectSpacePosition) const;
201 
205  inline Ogre::MeshPtr getMesh()
206  {
207  return mMesh;
208  }
209 
213  inline Ogre::SubMesh* getSubMesh()
214  {
215  return mSubMesh;
216  }
217 
221  inline Ogre::Entity* getEntity()
222  {
223  return mEntity;
224  }
225 
229  inline const Options& getOptions() const
230  {
231  return mOptions;
232  }
233 
237  inline const Size& getSize() const
238  {
239  return mOptions.MeshSize;
240  }
241 
245  inline const VertexType& getVertexType() const
246  {
247  return mOptions.MeshVertexType;
248  }
249 
253  inline const int& getNumFaces() const
254  {
255  return mNumFaces;
256  }
257 
261  inline const int& getNumVertices() const
262  {
263  return mNumVertices;
264  }
265 
269  inline const Ogre::String& getMaterialName() const
270  {
271  return mMaterialName;
272  }
273 
277  inline Ogre::HardwareVertexBufferSharedPtr &getHardwareVertexBuffer()
278  {
279  return mVertexBuffer;
280  }
281 
285  inline Ogre::HardwareIndexBufferSharedPtr &getHardwareIndexBuffer()
286  {
287  return mIndexBuffer;
288  }
289 
293  inline Ogre::SceneNode* getSceneNode()
294  {
295  return mSceneNode;
296  }
297 
301  inline const bool& isCreated() const
302  {
303  return mCreated;
304  }
305 
306  private:
309  void _createGeometry();
310 
314  bool mCreated;
316  Ogre::MeshPtr mMesh;
318  Ogre::SubMesh *mSubMesh;
320  Ogre::Entity *mEntity;
325 
327  Ogre::HardwareVertexBufferSharedPtr mVertexBuffer;
329  Ogre::HardwareIndexBufferSharedPtr mIndexBuffer;
330 
332  Ogre::SceneNode* mSceneNode;
333 
335  Ogre::String mMaterialName;
336 
339  };
340 }
341 
344 
345 #endif
Hydrax::Mesh::create
void create()
Create our water mesh, geometry, entity, etc...
Definition: Mesh.cpp:117
Hydrax::Mesh::getOptions
const Options & getOptions() const
Get options.
Definition: Mesh.h:229
Hydrax::Mesh::mOptions
Options mOptions
Mesh options.
Definition: Mesh.h:312
Hydrax::Mesh::VertexType
VertexType
Mesh vertex type enum.
Definition: Mesh.h:83
Hydrax::Mesh::mSubMesh
Ogre::SubMesh * mSubMesh
Ogre::Submesh pointer.
Definition: Mesh.h:318
Hydrax::Mesh::Options::MeshStrength
float MeshStrength
Water strength.
Definition: Mesh.h:137
Hydrax::Mesh::POS_VERTEX
Vertex struct for position data.
Definition: Mesh.h:76
Hydrax::Mesh::mEntity
Ogre::Entity * mEntity
Ogre::Entity pointer.
Definition: Mesh.h:320
Hydrax::Mesh::POS_NORM_UV_VERTEX::nz
float nz
Definition: Mesh.h:54
Hydrax::Mesh::mMaterialName
Ogre::String mMaterialName
Material name.
Definition: Mesh.h:335
Hydrax::Mesh::POS_UV_VERTEX::z
float z
Definition: Mesh.h:70
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Mesh::Options::MeshVertexType
VertexType MeshVertexType
Vertex type.
Definition: Mesh.h:139
Hydrax::Mesh::POS_VERTEX::z
float z
Definition: Mesh.h:78
Hydrax::Mesh::updateGeometry
bool updateGeometry(const int &numVer, void *verArray)
Update geomtry.
Definition: Mesh.cpp:281
Hydrax::Mesh::POS_UV_VERTEX
Vertex struct for position and uv data.
Definition: Mesh.h:68
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::Mesh::POS_VERTEX::x
float x
Definition: Mesh.h:78
Hydrax::Mesh::Mesh
Mesh(Hydrax *h)
Constructor.
Definition: Mesh.cpp:32
Hydrax::Mesh::POS_NORM_UV_VERTEX::z
float z
Definition: Mesh.h:53
Hydrax::Mesh::POS_NORM_UV_VERTEX::y
float y
Definition: Mesh.h:53
Hydrax::Mesh::mNumFaces
int mNumFaces
Number of faces.
Definition: Mesh.h:322
Hydrax::Mesh::POS_NORM_VERTEX::nx
float nx
Definition: Mesh.h:63
Hydrax::Mesh::POS_NORM_VERTEX::ny
float ny
Definition: Mesh.h:63
Hydrax::Mesh::POS_UV_VERTEX::y
float y
Definition: Mesh.h:70
Hydrax::Mesh::Options
Base Hydrax mesh options.
Definition: Mesh.h:93
Image.h
Hydrax::Mesh::getHardwareIndexBuffer
Ogre::HardwareIndexBufferSharedPtr & getHardwareIndexBuffer()
Get hardware index buffer reference.
Definition: Mesh.h:285
Hydrax::Mesh::getSubMesh
Ogre::SubMesh * getSubMesh()
Get sub mesh.
Definition: Mesh.h:213
Hydrax::Mesh::getMaterialName
const Ogre::String & getMaterialName() const
Get material name.
Definition: Mesh.h:269
Hydrax::Mesh::POS_NORM_VERTEX::z
float z
Definition: Mesh.h:62
Hydrax::Mesh::mMesh
Ogre::MeshPtr mMesh
Ogre::MeshPtr.
Definition: Mesh.h:316
Hydrax::Mesh::Options::Options
Options(const int &meshComplexity, const Size &meshSize, const VertexType &meshVertexType)
Constructor.
Definition: Mesh.h:110
Hydrax::Mesh::mSceneNode
Ogre::SceneNode * mSceneNode
Ogre::SceneNode pointer.
Definition: Mesh.h:332
Help.h
Hydrax::Mesh::mNumVertices
int mNumVertices
Number of vertices.
Definition: Mesh.h:324
Hydrax::Mesh::VT_POS_NORM_UV
@ VT_POS_NORM_UV
Definition: Mesh.h:85
Hydrax::Mesh::Options::Options
Options(const int &meshComplexity, const Size &meshSize, const float &meshStrength, const VertexType &meshVertexType)
Constructor.
Definition: Mesh.h:124
Hydrax::Mesh::getGridPosition
Ogre::Vector2 getGridPosition(const Ogre::Vector2 &Position)
Get the [0,1] range x/y grid position from a 2D world space x/z point.
Definition: Mesh.cpp:353
Hydrax::Mesh::setMaterialName
void setMaterialName(const Ogre::String &MaterialName)
Set mesh material.
Definition: Mesh.cpp:107
Hydrax::Mesh::getVertexType
const VertexType & getVertexType() const
Get vertex type return Mesh vertex type.
Definition: Mesh.h:245
Hydrax::Mesh::getSceneNode
Ogre::SceneNode * getSceneNode()
Get the Ogre::SceneNode pointer where Hydrax mesh is attached.
Definition: Mesh.h:293
Hydrax::Mesh::getNumFaces
const int & getNumFaces() const
Get number of faces.
Definition: Mesh.h:253
Hydrax::Mesh::POS_NORM_UV_VERTEX::ny
float ny
Definition: Mesh.h:54
Hydrax::Mesh::POS_NORM_UV_VERTEX::nx
float nx
Definition: Mesh.h:54
Hydrax::Mesh::VT_POS_UV
@ VT_POS_UV
Definition: Mesh.h:87
Hydrax::Mesh::getObjectSpacePosition
const Ogre::Vector3 getObjectSpacePosition(const Ogre::Vector3 &WorldSpacePosition) const
Get the object-space position from world-space position.
Definition: Mesh.cpp:409
Hydrax::Mesh::POS_NORM_UV_VERTEX::tv
float tv
Definition: Mesh.h:55
Hydrax::Mesh::_createGeometry
void _createGeometry()
Create mesh geometry.
Definition: Mesh.cpp:169
Hydrax::Mesh::remove
void remove()
Remove all resources.
Definition: Mesh.cpp:52
Hydrax::Mesh::POS_UV_VERTEX::tv
float tv
Definition: Mesh.h:71
Hydrax::Mesh::mHydrax
Hydrax * mHydrax
Hydrax pointer.
Definition: Mesh.h:338
Hydrax::Mesh::getHardwareVertexBuffer
Ogre::HardwareVertexBufferSharedPtr & getHardwareVertexBuffer()
Get hardware vertex buffer reference.
Definition: Mesh.h:277
Hydrax::Mesh
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition: Mesh.h:46
Hydrax::Mesh::VT_POS
@ VT_POS
Definition: Mesh.h:88
Hydrax::Mesh::POS_UV_VERTEX::x
float x
Definition: Mesh.h:70
Hydrax::Mesh::POS_NORM_UV_VERTEX::x
float x
Definition: Mesh.h:53
Hydrax::Mesh::Options::MeshComplexity
int MeshComplexity
Mesh complexity.
Definition: Mesh.h:133
Prerequisites.h
Hydrax::Mesh::POS_NORM_VERTEX::y
float y
Definition: Mesh.h:62
Hydrax::Mesh::Options::MeshSize
Size MeshSize
Grid size (X/Z) world space.
Definition: Mesh.h:135
Hydrax::Mesh::getNumVertices
const int & getNumVertices() const
Get number of vertices.
Definition: Mesh.h:261
Hydrax::Mesh::mCreated
bool mCreated
Is _createGeometry() called?
Definition: Mesh.h:314
Hydrax::Mesh::POS_NORM_UV_VERTEX::tu
float tu
Definition: Mesh.h:55
Hydrax::Mesh::isCreated
const bool & isCreated() const
Is _createGeometry() called?
Definition: Mesh.h:301
Hydrax::Mesh::mVertexBuffer
Ogre::HardwareVertexBufferSharedPtr mVertexBuffer
Vertex buffer.
Definition: Mesh.h:327
Hydrax::Mesh::POS_NORM_VERTEX
Vertex struct for position and normals data.
Definition: Mesh.h:60
Hydrax::Mesh::POS_NORM_VERTEX::x
float x
Definition: Mesh.h:62
Hydrax::Mesh::isPointInGrid
bool isPointInGrid(const Ogre::Vector2 &Position)
Get if a Position point is inside of the grid.
Definition: Mesh.cpp:300
Hydrax::Mesh::getWorldSpacePosition
const Ogre::Vector3 getWorldSpacePosition(const Ogre::Vector3 &ObjectSpacePosition) const
Get the world-space position from object-space position.
Definition: Mesh.cpp:430
Hydrax::Mesh::getMesh
Ogre::MeshPtr getMesh()
Get mesh.
Definition: Mesh.h:205
Hydrax::Mesh::setOptions
void setOptions(const Options &Options)
Update options.
Definition: Mesh.cpp:78
Hydrax::Mesh::~Mesh
~Mesh()
Destructor.
Definition: Mesh.cpp:47
Hydrax::Mesh::POS_VERTEX::y
float y
Definition: Mesh.h:78
Hydrax::Mesh::VT_POS_NORM
@ VT_POS_NORM
Definition: Mesh.h:86
Hydrax::Mesh::POS_UV_VERTEX::tu
float tu
Definition: Mesh.h:71
Hydrax::Mesh::POS_NORM_UV_VERTEX
Vertex struct for position, normals and uv data.
Definition: Mesh.h:51
Hydrax::Mesh::POS_NORM_VERTEX::nz
float nz
Definition: Mesh.h:63
Hydrax::Mesh::getEntity
Ogre::Entity * getEntity()
Get entity.
Definition: Mesh.h:221
Hydrax::Mesh::Options::Options
Options()
Constructor.
Definition: Mesh.h:97
Hydrax::Mesh::mIndexBuffer
Ogre::HardwareIndexBufferSharedPtr mIndexBuffer
Index buffer.
Definition: Mesh.h:329
Hydrax::Mesh::getSize
const Size & getSize() const
Get mesh size.
Definition: Mesh.h:237