ruby-procedural 0.0.1-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/Gemfile +4 -0
  2. data/README.md +29 -0
  3. data/Rakefile +65 -0
  4. data/bindings/procedural/interface/ProceduralBoxGenerator.i +12 -0
  5. data/bindings/procedural/interface/ProceduralCapsuleGenerator.i +12 -0
  6. data/bindings/procedural/interface/ProceduralConeGenerator.i +12 -0
  7. data/bindings/procedural/interface/ProceduralCylinderGenerator.i +12 -0
  8. data/bindings/procedural/interface/ProceduralExtruder.i +8 -0
  9. data/bindings/procedural/interface/ProceduralGeometryHelpers.i +15 -0
  10. data/bindings/procedural/interface/ProceduralHeader.i +8 -0
  11. data/bindings/procedural/interface/ProceduralIcoSphereGenerator.i +12 -0
  12. data/bindings/procedural/interface/ProceduralLathe.i +8 -0
  13. data/bindings/procedural/interface/ProceduralMeshGenerator.i +9 -0
  14. data/bindings/procedural/interface/ProceduralMultiShape.i +8 -0
  15. data/bindings/procedural/interface/ProceduralPath.i +8 -0
  16. data/bindings/procedural/interface/ProceduralPathGenerators.i +10 -0
  17. data/bindings/procedural/interface/ProceduralPlaneGenerator.i +12 -0
  18. data/bindings/procedural/interface/ProceduralPlatform.i +8 -0
  19. data/bindings/procedural/interface/ProceduralRoot.i +23 -0
  20. data/bindings/procedural/interface/ProceduralRoundedBoxGenerator.i +12 -0
  21. data/bindings/procedural/interface/ProceduralShape.i +8 -0
  22. data/bindings/procedural/interface/ProceduralShapeGenerators.i +10 -0
  23. data/bindings/procedural/interface/ProceduralSphereGenerator.i +11 -0
  24. data/bindings/procedural/interface/ProceduralSplines.i +8 -0
  25. data/bindings/procedural/interface/ProceduralStableHeaders.i +8 -0
  26. data/bindings/procedural/interface/ProceduralTorusGenerator.i +12 -0
  27. data/bindings/procedural/interface/ProceduralTorusKnotGenerator.i +12 -0
  28. data/bindings/procedural/interface/ProceduralTrack.i +8 -0
  29. data/bindings/procedural/interface/ProceduralTriangleBuffer.i +13 -0
  30. data/bindings/procedural/interface/ProceduralTriangulator.i +8 -0
  31. data/bindings/procedural/interface/ProceduralTubeGenerator.i +12 -0
  32. data/bindings/procedural/interface/ProceduralUtils.i +8 -0
  33. data/bindings/procedural/interface/Rakefile +22 -0
  34. data/bindings/procedural/interface/procedural.i +41 -0
  35. data/bindings/procedural/interface/procedural_wrap.cpp +36079 -0
  36. data/bindings/procedural/interface/procedural_wrap.h +19 -0
  37. data/bindings/procedural/interface/procedural_wrap.o +0 -0
  38. data/deps/include/OgreProcedural/Procedural.h +54 -0
  39. data/deps/include/OgreProcedural/ProceduralBoxGenerator.h +110 -0
  40. data/deps/include/OgreProcedural/ProceduralCapsuleGenerator.h +103 -0
  41. data/deps/include/OgreProcedural/ProceduralConeGenerator.h +90 -0
  42. data/deps/include/OgreProcedural/ProceduralCylinderGenerator.h +99 -0
  43. data/deps/include/OgreProcedural/ProceduralExtruder.h +131 -0
  44. data/deps/include/OgreProcedural/ProceduralGeometryHelpers.h +171 -0
  45. data/deps/include/OgreProcedural/ProceduralIcoSphereGenerator.h +76 -0
  46. data/deps/include/OgreProcedural/ProceduralLathe.h +129 -0
  47. data/deps/include/OgreProcedural/ProceduralMeshGenerator.h +286 -0
  48. data/deps/include/OgreProcedural/ProceduralMultiShape.h +126 -0
  49. data/deps/include/OgreProcedural/ProceduralPath.h +322 -0
  50. data/deps/include/OgreProcedural/ProceduralPathGenerators.h +281 -0
  51. data/deps/include/OgreProcedural/ProceduralPlaneGenerator.h +93 -0
  52. data/deps/include/OgreProcedural/ProceduralPlatform.h +54 -0
  53. data/deps/include/OgreProcedural/ProceduralRoot.h +65 -0
  54. data/deps/include/OgreProcedural/ProceduralRoundedBoxGenerator.h +118 -0
  55. data/deps/include/OgreProcedural/ProceduralShape.h +532 -0
  56. data/deps/include/OgreProcedural/ProceduralShapeGenerators.h +362 -0
  57. data/deps/include/OgreProcedural/ProceduralSphereGenerator.h +80 -0
  58. data/deps/include/OgreProcedural/ProceduralSplines.h +168 -0
  59. data/deps/include/OgreProcedural/ProceduralStableHeaders.h +28 -0
  60. data/deps/include/OgreProcedural/ProceduralTorusGenerator.h +88 -0
  61. data/deps/include/OgreProcedural/ProceduralTorusKnotGenerator.h +106 -0
  62. data/deps/include/OgreProcedural/ProceduralTrack.h +122 -0
  63. data/deps/include/OgreProcedural/ProceduralTriangleBuffer.h +328 -0
  64. data/deps/include/OgreProcedural/ProceduralTriangulator.h +173 -0
  65. data/deps/include/OgreProcedural/ProceduralTubeGenerator.h +96 -0
  66. data/deps/include/OgreProcedural/ProceduralUtils.h +185 -0
  67. data/deps/lib/libOgreProcedural.so +0 -0
  68. data/lib/procedural.so +0 -0
  69. data/lib/ruby-procedural/version.rb +5 -0
  70. data/lib/ruby-procedural.rb +27 -0
  71. data/ruby-procedural.gemspec +33 -0
  72. metadata +138 -0
@@ -0,0 +1,286 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_MESH_GENERATOR_INCLUDED
29
+ #define PROCEDURAL_MESH_GENERATOR_INCLUDED
30
+
31
+ #include "OgreRectangle.h"
32
+ #include "OgreSceneManager.h"
33
+ #include "OgreMesh.h"
34
+ #include "OgreManualObject.h"
35
+ #include "ProceduralRoot.h"
36
+ #include "ProceduralPlatform.h"
37
+ #include "ProceduralTriangleBuffer.h"
38
+
39
+ namespace Procedural
40
+ {
41
+ /** Superclass of everything that builds meshes
42
+ */
43
+ template <typename T>
44
+ class MeshGenerator
45
+ {
46
+ protected:
47
+ /// A pointer to the default scene manager
48
+ Ogre::SceneManager* mSceneMgr;
49
+
50
+ /// U tile for texture coords generation
51
+ Ogre::Real mUTile;
52
+
53
+ /// V tile for texture coords generation
54
+ Ogre::Real mVTile;
55
+
56
+ /// Whether to produces normals or not
57
+ bool mEnableNormals;
58
+
59
+ /// The number of texture coordinate sets to include
60
+ unsigned char mNumTexCoordSet;
61
+
62
+ /// Rectangle in which the texture coordinates will be placed
63
+ Ogre::Vector2 mUVOrigin;
64
+
65
+ /// If set to true, the UV coordinates coming from the mesh generator will be switched.
66
+ /// It can be used, for example, if your texture doesn't fit the mesh generator's assumptions about UV.
67
+ /// If UV were to fit in a given rectangle, they still fit in it after the switch.
68
+ bool mSwitchUV;
69
+
70
+ /// Orientation to apply the mesh
71
+ Ogre::Quaternion mOrientation;
72
+
73
+ /// Scale to apply the mesh
74
+ Ogre::Vector3 mScale;
75
+
76
+ /// Position to apply to the mesh
77
+ Ogre::Vector3 mPosition;
78
+
79
+ // Whether a transform has been defined or not
80
+ bool mTransform;
81
+
82
+ // Debug output file
83
+ std::string mDumpFileName;
84
+
85
+ // Enable output to file or not
86
+ bool mEnableDumpToFile;
87
+
88
+ public:
89
+ /// Default constructor
90
+ MeshGenerator() : mUTile(1.f),
91
+ mVTile(1.f),
92
+ mEnableNormals(true),
93
+ mNumTexCoordSet(1),
94
+ mUVOrigin(0,0),
95
+ mSwitchUV(false),
96
+ mOrientation(Ogre::Quaternion::IDENTITY),
97
+ mScale(1,1,1),
98
+ mPosition(0,0,0),
99
+ mTransform(false),
100
+ mDumpFileName(""),
101
+ mEnableDumpToFile(false)
102
+ {
103
+ mSceneMgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second;
104
+ assert(mSceneMgr && "Scene Manager must be set in Root");
105
+ }
106
+
107
+ /**
108
+ * Builds a mesh.
109
+ * @param name of the mesh for the MeshManager
110
+ * @param group ressource group in which the mesh will be created
111
+ */
112
+ Ogre::MeshPtr realizeMesh(const std::string& name = "",
113
+ const Ogre::String& group = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
114
+ {
115
+ TriangleBuffer tbuffer;
116
+ addToTriangleBuffer(tbuffer);
117
+ if (mEnableDumpToFile)
118
+ tbuffer._dumpContentsToFile(mDumpFileName);
119
+ Ogre::MeshPtr mesh;
120
+ if (name == "")
121
+ mesh = tbuffer.transformToMesh(Utils::getName(), group);
122
+ else
123
+ mesh = tbuffer.transformToMesh(name, group);
124
+ return mesh;
125
+ }
126
+
127
+ /**
128
+ * Overloaded by each generator to implement the specifics
129
+ */
130
+ virtual void addToTriangleBuffer(TriangleBuffer& buffer) const=0;
131
+
132
+ /**
133
+ * Sets U Tile, ie the number by which u texture coordinates are multiplied (default=1)
134
+ */
135
+ inline T& setUTile(Ogre::Real uTile)
136
+ {
137
+ mUTile = uTile;
138
+ return static_cast<T&>(*this);
139
+ }
140
+
141
+ /**
142
+ * Sets V Tile, ie the number by which v texture coordinates are multiplied (default=1)
143
+ */
144
+ inline T & setVTile(Ogre::Real vTile)
145
+ {
146
+ mVTile = vTile;
147
+ return static_cast<T&>(*this);
148
+ }
149
+
150
+ /**
151
+ * Sets the texture rectangle
152
+ */
153
+ inline T & setTextureRectangle(Ogre::Rectangle textureRectangle)
154
+ {
155
+ mUVOrigin = Ogre::Vector2(textureRectangle.top, textureRectangle.left);
156
+ mUTile = textureRectangle.right-textureRectangle.left;
157
+ mVTile = textureRectangle.bottom-textureRectangle.top;
158
+ return static_cast<T&>(*this);
159
+ }
160
+
161
+ /**
162
+ * Sets whether normals are enabled or not (default=true)
163
+ */
164
+ inline T & setEnableNormals(bool enableNormals)
165
+ {
166
+ mEnableNormals = enableNormals;
167
+ return static_cast<T&>(*this);
168
+ }
169
+
170
+ /**
171
+ * Sets the number of texture coordintate sets (default=1)
172
+ */
173
+ inline T & setNumTexCoordSet(unsigned char numTexCoordSet)
174
+ {
175
+ mNumTexCoordSet = numTexCoordSet;
176
+ return static_cast<T&>(*this);
177
+ }
178
+
179
+ /// Sets whether to switch U and V texture coordinates
180
+ inline T& setSwitchUV(bool switchUV)
181
+ {
182
+ mSwitchUV = switchUV;
183
+ return static_cast<T&>(*this);
184
+ }
185
+
186
+ /// Sets an orientation to give when building the mesh
187
+ inline T& setOrientation(const Ogre::Quaternion& orientation)
188
+ {
189
+ mOrientation = orientation;
190
+ mTransform = true;
191
+ return static_cast<T&>(*this);
192
+ }
193
+
194
+ /// Sets a translation baked into the resulting mesh
195
+ inline T& setPosition(const Ogre::Vector3& position)
196
+ {
197
+ mPosition = position;
198
+ mTransform = true;
199
+ return static_cast<T&>(*this);
200
+ }
201
+
202
+ /// Sets a translation baked into the resulting mesh
203
+ inline T& setPosition(Ogre::Real x, Ogre::Real y, Ogre::Real z)
204
+ {
205
+ mPosition = Ogre::Vector3(x, y, z);
206
+ mTransform = true;
207
+ return static_cast<T&>(*this);
208
+ }
209
+
210
+
211
+ /// Sets a scale baked into the resulting mesh
212
+ inline T& setScale(const Ogre::Vector3& scale)
213
+ {
214
+ mScale = scale;
215
+ mTransform = true;
216
+ return static_cast<T&>(*this);
217
+ }
218
+
219
+ /// Sets a uniform scale baked into the resulting mesh
220
+ inline T& setScale(Ogre::Real scale)
221
+ {
222
+ mScale = Ogre::Vector3(scale);
223
+ mTransform = true;
224
+ return static_cast<T&>(*this);
225
+ }
226
+
227
+ /// Sets a scale baked into the resulting mesh
228
+ inline T& setScale(Ogre::Real x, Ogre::Real y, Ogre::Real z)
229
+ {
230
+ mScale = Ogre::Vector3(x, y, z);
231
+ mTransform = true;
232
+ return static_cast<T&>(*this);
233
+ }
234
+
235
+ /// Resets all transforms (orientation, position and scale) that would have been applied to the mesh to their default values
236
+ inline T& resetTransforms()
237
+ {
238
+ mTransform = false;
239
+ mPosition = Ogre::Vector3::ZERO;
240
+ mOrientation = Ogre::Quaternion::IDENTITY;
241
+ mScale = Ogre::Vector3(1);
242
+ return static_cast<T&>(*this);
243
+ }
244
+
245
+ /// Activate dump to file
246
+ inline T& _setDumpToFile(const std::string& fileName)
247
+ {
248
+ mEnableDumpToFile = true;
249
+ mDumpFileName = fileName;
250
+ return static_cast<T&>(*this);
251
+ }
252
+
253
+ /// Disable dump to file
254
+ inline T& _disableDumpToFile()
255
+ {
256
+ mEnableDumpToFile = false;
257
+ return static_cast<T&>(*this);
258
+ }
259
+
260
+
261
+ protected:
262
+ /// Adds a new point to a triangle buffer, using the format defined for that MeshGenerator
263
+ /// @arg buffer the triangle buffer to update
264
+ /// @arg position the position of the new point
265
+ /// @arg normal the normal of the new point
266
+ /// @arg uv the uv texcoord of the new point
267
+ inline void addPoint(TriangleBuffer& buffer, const Ogre::Vector3& position, const Ogre::Vector3& normal, const Ogre::Vector2& uv) const
268
+ {
269
+ if (mTransform)
270
+ buffer.position(mPosition + mOrientation * (mScale * position));
271
+ else
272
+ buffer.position(position);
273
+ if (mEnableNormals)
274
+ buffer.normal(normal);
275
+ if (mSwitchUV)
276
+ for (unsigned char i=0;i<mNumTexCoordSet;i++)
277
+ buffer.textureCoord(mUVOrigin.x + uv.y*mUTile, mUVOrigin.y+uv.x*mVTile);
278
+ else
279
+ for (unsigned char i=0;i<mNumTexCoordSet;i++)
280
+ buffer.textureCoord(mUVOrigin.x + uv.x*mUTile, mUVOrigin.y+uv.y*mVTile);
281
+ }
282
+
283
+ };
284
+ //
285
+ }
286
+ #endif
@@ -0,0 +1,126 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_MULTISHAPE_INCLUDED
29
+ #define PROCEDURAL_MULTISHAPE_INCLUDED
30
+
31
+ #include "ProceduralRoot.h"
32
+
33
+ namespace Procedural
34
+ {
35
+ class Shape;
36
+
37
+ /** Holds a bunch of shapes.
38
+ * There are a number of assumptions that are made and are not checked
39
+ * against : the shapes must not cross each other
40
+ *
41
+ */
42
+ class _ProceduralExport MultiShape
43
+ {
44
+ std::vector<Shape> mShapes;
45
+
46
+ public:
47
+ /// Default constructor
48
+ MultiShape()
49
+ {}
50
+
51
+ /// Constructor from a single shape
52
+ MultiShape(const Shape& shape)
53
+ {
54
+ mShapes.push_back(shape);
55
+ }
56
+
57
+ /// Constructor from a variable number of shapes
58
+ /// @arg count the number of shapes to add
59
+ /// @arg pointer to the shapes to add
60
+ MultiShape(int count, ...);
61
+
62
+ /// Adds a shape to the list of shapes
63
+ MultiShape& addShape(const Shape& shape)
64
+ {
65
+ mShapes.push_back(shape);
66
+ return *this;
67
+ }
68
+
69
+ /// Returns the i-th shape
70
+ const Shape& getShape(int i) const
71
+ {
72
+ return mShapes[i];
73
+ }
74
+
75
+ /// Returns the i-th shape
76
+ Shape& getShape(int i)
77
+ {
78
+ return mShapes[i];
79
+ }
80
+
81
+ /// Builds an aggregated list of all points contained in all shapes
82
+ std::vector<Ogre::Vector2> getPoints() const;
83
+
84
+ /// Returns the number of shapes in that MultiShape
85
+ int getShapeCount() const
86
+ {
87
+ return mShapes.size();
88
+ }
89
+
90
+ /// Append every shape of an other multishape to the current multiShape
91
+ void addMultiShape(const MultiShape& other)
92
+ {
93
+ for (std::vector<Shape>::const_iterator it = other.mShapes.begin(); it!=other.mShapes.end(); it++)
94
+ {
95
+ mShapes.push_back(*it);
96
+ }
97
+ }
98
+
99
+ /// Outputs the Multi Shape to a Mesh, mostly for visualisation or debugging purposes
100
+ Ogre::MeshPtr realizeMesh(const std::string& name="");
101
+
102
+ /// Tells whether a point is located inside that multishape
103
+ /// It assumes that all of the shapes in that multishape are closed,
104
+ /// and that they don't contradict each other,
105
+ /// ie a point cannot be outside and inside at the same time
106
+ bool isPointInside(const Ogre::Vector2& point) const;
107
+
108
+ /**
109
+ * Tells whether multishape is "closed" or not.
110
+ * MultiShape is considered to be closed if and only if all shapes are closed
111
+ */
112
+ bool isClosed() const;
113
+
114
+ /**
115
+ * Closes all shapes included in this multiShape
116
+ */
117
+ void close();
118
+
119
+ /**
120
+ * Determines whether the outside as defined by user equals "real" outside
121
+ */
122
+ bool isOutsideRealOutside() const;
123
+
124
+ };
125
+ }
126
+ #endif
@@ -0,0 +1,322 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_PATH_INCLUDED
29
+ #define PROCEDURAL_PATH_INCLUDED
30
+
31
+ #include "OgreVector3.h"
32
+ #include "OgreSimpleSpline.h"
33
+ #include "ProceduralUtils.h"
34
+ #include "ProceduralPlatform.h"
35
+ #include "ProceduralRoot.h"
36
+ #include "ProceduralTrack.h"
37
+
38
+ namespace Procedural
39
+ {
40
+ /** Succession of points in 3D space.
41
+ * Can be closed or not.
42
+ */
43
+ class _ProceduralExport Path
44
+ {
45
+ std::vector<Ogre::Vector3> mPoints;
46
+ bool mClosed;
47
+ public:
48
+ /// Default constructor
49
+ Path() : mClosed(false) {}
50
+
51
+ /** Adds a point to the path, as a Vector3 */
52
+ Path& addPoint(const Ogre::Vector3& pt)
53
+ {
54
+ mPoints.push_back(pt);
55
+ return *this;
56
+ }
57
+
58
+ /** Adds a point to the path, using its 3 coordinates */
59
+ Path& addPoint(Ogre::Real x, Ogre::Real y, Ogre::Real z)
60
+ {
61
+ mPoints.push_back(Ogre::Vector3(x,y,z));
62
+ return *this;
63
+ }
64
+
65
+ /// Inserts a point to the path
66
+ /// @arg index the index before the inserted point
67
+ /// @arg x new point's x coordinate
68
+ /// @arg y new point's y coordinate
69
+ /// @arg z new point's z coordinate
70
+ inline Path& insertPoint(size_t index, Ogre::Real x, Ogre::Real y, Ogre::Real z)
71
+ {
72
+ mPoints.insert(mPoints.begin()+index, Ogre::Vector3(x, y, z));
73
+ return *this;
74
+ }
75
+
76
+ /// Inserts a point to the path
77
+ /// @arg index the index before the inserted point
78
+ /// @arg pt new point's position
79
+ inline Path& insertPoint(size_t index, const Ogre::Vector3& pt)
80
+ {
81
+ mPoints.insert(mPoints.begin()+index, pt);
82
+ return *this;
83
+ }
84
+
85
+ /// Appends another path at the end of this one
86
+ inline Path& appendPath(const Path& other)
87
+ {
88
+ mPoints.insert(mPoints.end(), other.mPoints.begin(), other.mPoints.end());
89
+ return *this;
90
+ }
91
+
92
+ /// Appends another path at the end of this one, relative to the last point of this path
93
+ inline Path& appendPathRel(const Path& other)
94
+ {
95
+ if (mPoints.empty())
96
+ appendPath(other);
97
+ else
98
+ {
99
+ Ogre::Vector3 refVector = *(mPoints.end()-1);
100
+ std::vector<Ogre::Vector3> pointList(other.mPoints.begin(), other.mPoints.end());
101
+ for (std::vector<Ogre::Vector3>::iterator it = pointList.begin(); it!=pointList.end(); it++)
102
+ *it += refVector;
103
+ mPoints.insert(mPoints.end(), pointList.begin(), pointList.end());
104
+ }
105
+ return *this;
106
+ }
107
+
108
+ /** Clears the content of the Path */
109
+ Path& reset()
110
+ {
111
+ mPoints.clear();
112
+ return *this;
113
+ }
114
+
115
+ /** Define the path as being closed. Almost the same as adding a last point on the first point position */
116
+ Path& close()
117
+ {
118
+ assert(mPoints.size()>0 && "Cannot close an empty path");
119
+ mClosed = true;
120
+ return *this;
121
+ }
122
+
123
+ /** Tells if the path is closed or not */
124
+ bool isClosed()
125
+ {
126
+ return mClosed;
127
+ }
128
+
129
+ /** Gets the list of points as a vector of Vector3 */
130
+ std::vector<Ogre::Vector3> getPoints()
131
+ {
132
+ return mPoints;
133
+ }
134
+
135
+ /// Gets raw vector data of this path as a non-const reference
136
+ inline std::vector<Ogre::Vector3>& getPointsReference()
137
+ {
138
+ return mPoints;
139
+ }
140
+
141
+ /** Safely gets a given point.
142
+ * Takes into account whether the path is closed or not.
143
+ * @param i the index of the point.
144
+ * if it is <0 or >maxPoint, cycle through the list of points
145
+ */
146
+ const Ogre::Vector3& getPoint(int i) const
147
+ {
148
+ if (mClosed)
149
+ return mPoints[Utils::modulo(i,mPoints.size())];
150
+ return mPoints[Utils::cap(i,0,mPoints.size()-1)];
151
+ }
152
+
153
+ /** Gets the number of segments in the path
154
+ * Takes into accound whether path is closed or not
155
+ */
156
+ int getSegCount()
157
+ {
158
+ return (mPoints.size()-1) + (mClosed?1:0);
159
+ }
160
+
161
+ /**
162
+ * Returns local direction after the current point
163
+ */
164
+ Ogre::Vector3 getDirectionAfter(unsigned int i)
165
+ {
166
+ // If the path isn't closed, we get a different calculation at the end, because
167
+ // the tangent shall not be null
168
+ if (!mClosed && i == mPoints.size() - 1 && i > 0)
169
+ return (mPoints[i] - mPoints[i-1]).normalisedCopy();
170
+ else
171
+ return (getPoint(i+1) - getPoint(i)).normalisedCopy();
172
+ }
173
+
174
+ /**
175
+ * Returns local direction after the current point
176
+ */
177
+ Ogre::Vector3 getDirectionBefore(unsigned int i)
178
+ {
179
+ // If the path isn't closed, we get a different calculation at the end, because
180
+ // the tangent shall not be null
181
+ if (!mClosed && i == 1)
182
+ return (mPoints[1] - mPoints[0]).normalisedCopy();
183
+ else
184
+ return (getPoint(i) - getPoint(i-1)).normalisedCopy();
185
+ }
186
+
187
+ /**
188
+ * Returns the local direction at the current point.
189
+ * @param i index of the point
190
+ */
191
+ Ogre::Vector3 getAvgDirection(unsigned int i)
192
+ {
193
+ return (getDirectionAfter(i) + getDirectionBefore(i)).normalisedCopy();
194
+ }
195
+
196
+ /// Returns the total lineic length of that shape
197
+ Ogre::Real getTotalLength() const;
198
+
199
+ /// Gets a position on the shape with index of the point and a percentage of position on the segment
200
+ /// @arg i index of the segment
201
+ /// @arg coord a number between 0 and 1 meaning the percentage of position on the segment
202
+ inline Ogre::Vector3 getPosition(unsigned int i, Ogre::Real coord) const
203
+ {
204
+ assert(mClosed || (i < mPoints.size() - 1 && "Out of Bounds"));
205
+ assert(coord>=0. && coord<=1. && "Coord must be comprised between 0 and 1");
206
+ Ogre::Vector3 A = getPoint(i);
207
+ Ogre::Vector3 B = getPoint(i+1);
208
+ return A + coord*(B-A);
209
+ }
210
+
211
+ /// Gets a position on the shape from lineic coordinate
212
+ /// @arg coord lineic coordinate
213
+ Ogre::Vector3 getPosition(Ogre::Real coord) const;
214
+
215
+ /**
216
+ * Outputs a mesh representing the path.
217
+ * Mostly for debugging purposes
218
+ */
219
+ Ogre::MeshPtr realizeMesh(const std::string& name = "");
220
+
221
+ /// Creates a path with the keys of this path and extra keys coming from a track
222
+ Path mergeKeysWithTrack(const Track& track) const;
223
+
224
+ /**
225
+ * Applies the given translation to all the points already defined.
226
+ * Has strictly no effect on the points defined after that
227
+ * @param translation the translation vector
228
+ */
229
+ Path& translate(const Ogre::Vector3& translation)
230
+ {
231
+ for (std::vector<Ogre::Vector3>::iterator it = mPoints.begin(); it!=mPoints.end(); it++)
232
+ *it+=translation;
233
+ return *this;
234
+ }
235
+
236
+ /**
237
+ * Applies the given translation to all the points already defined.
238
+ * Has strictly no effect on the points defined after that
239
+ * @param translationX X component of the translation vector
240
+ * @param translationY Y component of the translation vector
241
+ * @param translationZ Z component of the translation vector
242
+ */
243
+ Path& translate(Ogre::Real translationX, Ogre::Real translationY, Ogre::Real translationZ)
244
+ {
245
+ return translate(Ogre::Vector3(translationX, translationY, translationZ));
246
+ }
247
+
248
+ /**
249
+ * Applies the given scale to all the points already defined.
250
+ * Has strictly no effect on the points defined after that
251
+ * @param amount amount of scale
252
+ */
253
+ Path& scale(Ogre::Real amount)
254
+ {
255
+ return scale(amount, amount, amount);
256
+ }
257
+
258
+ /**
259
+ * Applies the given scale to all the points already defined.
260
+ * Has strictly no effect on the points defined after that
261
+ * @param scaleX amount of scale in the X direction
262
+ * @param scaleY amount of scale in the Y direction
263
+ * @param scaleZ amount of scale in the Z direction
264
+ */
265
+ Path& scale(Ogre::Real scaleX, Ogre::Real scaleY, Ogre::Real scaleZ)
266
+ {
267
+ for (std::vector<Ogre::Vector3>::iterator it = mPoints.begin(); it!=mPoints.end(); it++)
268
+ {
269
+ it->x *= scaleX;
270
+ it->y *= scaleY;
271
+ it->z *= scaleZ;
272
+ }
273
+ return *this;
274
+ }
275
+
276
+ /**
277
+ * Applies the given scale to all the points already defined.
278
+ * Has strictly no effect on the points defined after that
279
+ * @param amount of scale
280
+ */
281
+ Path& scale(const Ogre::Vector3& amount)
282
+ {
283
+ return scale(amount.x, amount.y, amount.z);
284
+ }
285
+
286
+ /**
287
+ * Reflect all points in this path against a zero-origined plane with a given normal
288
+ * @param the normal
289
+ */
290
+ Path& reflect(const Ogre::Vector3& normal)
291
+ {
292
+ for (std::vector<Ogre::Vector3>::iterator it = mPoints.begin(); it!=mPoints.end(); it++)
293
+ {
294
+ *it = it->reflect(normal);
295
+ }
296
+ return *this;
297
+ }
298
+
299
+ /// Extracts a part of the shape as a new path
300
+ /// @arg first first index to be in the new path
301
+ /// @arg last last index to be in the new path
302
+ inline Path extractSubPath(unsigned int first, unsigned int last)
303
+ {
304
+ Path p;
305
+ for (unsigned int i=first;i<last;i++)
306
+ p.addPoint(mPoints[i]);
307
+ if (mClosed)
308
+ p.close();
309
+ return p;
310
+ }
311
+
312
+ /// Reverses direction of the path
313
+ inline Path& reverse()
314
+ {
315
+ std::reverse(mPoints.begin(), mPoints.end());
316
+ return *this;
317
+ }
318
+ };
319
+
320
+ }
321
+
322
+ #endif