Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Mesh.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://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
39namespace 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
77 {
78 float x,y,z;
79 };
80
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 {
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
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
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition Mesh.h:47
void _createGeometry()
Create mesh geometry.
Definition Mesh.cpp:169
const Ogre::String & getMaterialName() const
Get material name.
Definition Mesh.h:269
const Size & getSize() const
Get mesh size.
Definition Mesh.h:237
Ogre::SubMesh * mSubMesh
Ogre::Submesh pointer.
Definition Mesh.h:318
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
Ogre::HardwareIndexBufferSharedPtr & getHardwareIndexBuffer()
Get hardware index buffer reference.
Definition Mesh.h:285
void create()
Create our water mesh, geometry, entity, etc...
Definition Mesh.cpp:117
const Ogre::Vector3 getObjectSpacePosition(const Ogre::Vector3 &WorldSpacePosition) const
Get the object-space position from world-space position.
Definition Mesh.cpp:409
Hydrax * mHydrax
Hydrax pointer.
Definition Mesh.h:338
~Mesh()
Destructor.
Definition Mesh.cpp:47
const VertexType & getVertexType() const
Get vertex type return Mesh vertex type.
Definition Mesh.h:245
void setMaterialName(const Ogre::String &MaterialName)
Set mesh material.
Definition Mesh.cpp:107
void remove()
Remove all resources.
Definition Mesh.cpp:52
const int & getNumFaces() const
Get number of faces.
Definition Mesh.h:253
VertexType
Mesh vertex type enum.
Definition Mesh.h:84
@ VT_POS_NORM_UV
Definition Mesh.h:85
@ VT_POS_UV
Definition Mesh.h:87
@ VT_POS_NORM
Definition Mesh.h:86
Ogre::String mMaterialName
Material name.
Definition Mesh.h:335
Ogre::Entity * mEntity
Ogre::Entity pointer.
Definition Mesh.h:320
Ogre::SceneNode * mSceneNode
Ogre::SceneNode pointer.
Definition Mesh.h:332
Ogre::SubMesh * getSubMesh()
Get sub mesh.
Definition Mesh.h:213
void setOptions(const Options &Options)
Update options.
Definition Mesh.cpp:78
Ogre::HardwareVertexBufferSharedPtr mVertexBuffer
Vertex buffer.
Definition Mesh.h:327
Options mOptions
Mesh options.
Definition Mesh.h:312
Ogre::Entity * getEntity()
Get entity.
Definition Mesh.h:221
bool updateGeometry(const int &numVer, void *verArray)
Update geomtry.
Definition Mesh.cpp:281
const bool & isCreated() const
Is _createGeometry() called?
Definition Mesh.h:301
const int & getNumVertices() const
Get number of vertices.
Definition Mesh.h:261
Ogre::HardwareVertexBufferSharedPtr & getHardwareVertexBuffer()
Get hardware vertex buffer reference.
Definition Mesh.h:277
Ogre::HardwareIndexBufferSharedPtr mIndexBuffer
Index buffer.
Definition Mesh.h:329
Ogre::MeshPtr getMesh()
Get mesh.
Definition Mesh.h:205
const Options & getOptions() const
Get options.
Definition Mesh.h:229
int mNumFaces
Number of faces.
Definition Mesh.h:322
bool mCreated
Is _createGeometry() called?
Definition Mesh.h:314
Ogre::SceneNode * getSceneNode()
Get the Ogre::SceneNode pointer where Hydrax mesh is attached.
Definition Mesh.h:293
int mNumVertices
Number of vertices.
Definition Mesh.h:324
Ogre::MeshPtr mMesh
Ogre::MeshPtr.
Definition Mesh.h:316
const Ogre::Vector3 getWorldSpacePosition(const Ogre::Vector3 &ObjectSpacePosition) const
Get the world-space position from object-space position.
Definition Mesh.cpp:430
bool isPointInGrid(const Ogre::Vector2 &Position)
Get if a Position point is inside of the grid.
Definition Mesh.cpp:300
Base Hydrax mesh options.
Definition Mesh.h:94
VertexType MeshVertexType
Vertex type.
Definition Mesh.h:139
Size MeshSize
Grid size (X/Z) world space.
Definition Mesh.h:135
Options(const int &meshComplexity, const Size &meshSize, const VertexType &meshVertexType)
Constructor.
Definition Mesh.h:110
Options()
Constructor.
Definition Mesh.h:97
Options(const int &meshComplexity, const Size &meshSize, const float &meshStrength, const VertexType &meshVertexType)
Constructor.
Definition Mesh.h:124
float MeshStrength
Water strength.
Definition Mesh.h:137
int MeshComplexity
Mesh complexity.
Definition Mesh.h:133
Vertex struct for position, normals and uv data.
Definition Mesh.h:52
Vertex struct for position and normals data.
Definition Mesh.h:61
Vertex struct for position and uv data.
Definition Mesh.h:69
Vertex struct for position data.
Definition Mesh.h:77
Struct wich contains an especific width and height value.
Definition Help.h:41