ruby-procedural 0.0.1-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/README.md +29 -0
- data/Rakefile +65 -0
- data/bindings/procedural/interface/ProceduralBoxGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralCapsuleGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralConeGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralCylinderGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralExtruder.i +8 -0
- data/bindings/procedural/interface/ProceduralGeometryHelpers.i +15 -0
- data/bindings/procedural/interface/ProceduralHeader.i +8 -0
- data/bindings/procedural/interface/ProceduralIcoSphereGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralLathe.i +8 -0
- data/bindings/procedural/interface/ProceduralMeshGenerator.i +9 -0
- data/bindings/procedural/interface/ProceduralMultiShape.i +8 -0
- data/bindings/procedural/interface/ProceduralPath.i +8 -0
- data/bindings/procedural/interface/ProceduralPathGenerators.i +10 -0
- data/bindings/procedural/interface/ProceduralPlaneGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralPlatform.i +8 -0
- data/bindings/procedural/interface/ProceduralRoot.i +23 -0
- data/bindings/procedural/interface/ProceduralRoundedBoxGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralShape.i +8 -0
- data/bindings/procedural/interface/ProceduralShapeGenerators.i +10 -0
- data/bindings/procedural/interface/ProceduralSphereGenerator.i +11 -0
- data/bindings/procedural/interface/ProceduralSplines.i +8 -0
- data/bindings/procedural/interface/ProceduralStableHeaders.i +8 -0
- data/bindings/procedural/interface/ProceduralTorusGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralTorusKnotGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralTrack.i +8 -0
- data/bindings/procedural/interface/ProceduralTriangleBuffer.i +13 -0
- data/bindings/procedural/interface/ProceduralTriangulator.i +8 -0
- data/bindings/procedural/interface/ProceduralTubeGenerator.i +12 -0
- data/bindings/procedural/interface/ProceduralUtils.i +8 -0
- data/bindings/procedural/interface/Rakefile +22 -0
- data/bindings/procedural/interface/procedural.i +41 -0
- data/bindings/procedural/interface/procedural_wrap.cpp +36079 -0
- data/bindings/procedural/interface/procedural_wrap.h +19 -0
- data/bindings/procedural/interface/procedural_wrap.o +0 -0
- data/deps/include/OgreProcedural/Procedural.h +54 -0
- data/deps/include/OgreProcedural/ProceduralBoxGenerator.h +110 -0
- data/deps/include/OgreProcedural/ProceduralCapsuleGenerator.h +103 -0
- data/deps/include/OgreProcedural/ProceduralConeGenerator.h +90 -0
- data/deps/include/OgreProcedural/ProceduralCylinderGenerator.h +99 -0
- data/deps/include/OgreProcedural/ProceduralExtruder.h +131 -0
- data/deps/include/OgreProcedural/ProceduralGeometryHelpers.h +171 -0
- data/deps/include/OgreProcedural/ProceduralIcoSphereGenerator.h +76 -0
- data/deps/include/OgreProcedural/ProceduralLathe.h +129 -0
- data/deps/include/OgreProcedural/ProceduralMeshGenerator.h +286 -0
- data/deps/include/OgreProcedural/ProceduralMultiShape.h +126 -0
- data/deps/include/OgreProcedural/ProceduralPath.h +322 -0
- data/deps/include/OgreProcedural/ProceduralPathGenerators.h +281 -0
- data/deps/include/OgreProcedural/ProceduralPlaneGenerator.h +93 -0
- data/deps/include/OgreProcedural/ProceduralPlatform.h +54 -0
- data/deps/include/OgreProcedural/ProceduralRoot.h +65 -0
- data/deps/include/OgreProcedural/ProceduralRoundedBoxGenerator.h +118 -0
- data/deps/include/OgreProcedural/ProceduralShape.h +532 -0
- data/deps/include/OgreProcedural/ProceduralShapeGenerators.h +362 -0
- data/deps/include/OgreProcedural/ProceduralSphereGenerator.h +80 -0
- data/deps/include/OgreProcedural/ProceduralSplines.h +168 -0
- data/deps/include/OgreProcedural/ProceduralStableHeaders.h +28 -0
- data/deps/include/OgreProcedural/ProceduralTorusGenerator.h +88 -0
- data/deps/include/OgreProcedural/ProceduralTorusKnotGenerator.h +106 -0
- data/deps/include/OgreProcedural/ProceduralTrack.h +122 -0
- data/deps/include/OgreProcedural/ProceduralTriangleBuffer.h +328 -0
- data/deps/include/OgreProcedural/ProceduralTriangulator.h +173 -0
- data/deps/include/OgreProcedural/ProceduralTubeGenerator.h +96 -0
- data/deps/include/OgreProcedural/ProceduralUtils.h +185 -0
- data/deps/lib/libOgreProcedural.so +0 -0
- data/lib/procedural.so +0 -0
- data/lib/ruby-procedural/version.rb +5 -0
- data/lib/ruby-procedural.rb +27 -0
- data/ruby-procedural.gemspec +33 -0
- metadata +138 -0
@@ -0,0 +1,362 @@
|
|
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_SHAPE_GENERATORS_INCLUDED
|
29
|
+
#define PROCEDURAL_SHAPE_GENERATORS_INCLUDED
|
30
|
+
|
31
|
+
#include "ProceduralShape.h"
|
32
|
+
#include "ProceduralSplines.h"
|
33
|
+
|
34
|
+
namespace Procedural
|
35
|
+
{
|
36
|
+
//-----------------------------------------------------------------------
|
37
|
+
/// Base class for Shape generators
|
38
|
+
template<class T>
|
39
|
+
class BaseSpline2
|
40
|
+
{
|
41
|
+
protected:
|
42
|
+
/// The number of segments between 2 control points
|
43
|
+
unsigned int mNumSeg;
|
44
|
+
/// Whether the shape will be closed or not
|
45
|
+
bool mClosed;
|
46
|
+
/// The "out" side of the shape
|
47
|
+
Side mOutSide;
|
48
|
+
public:
|
49
|
+
/// Default constructor
|
50
|
+
BaseSpline2() : mNumSeg(4), mClosed(false), mOutSide(SIDE_RIGHT) {}
|
51
|
+
|
52
|
+
/// Sets the out side of the shape
|
53
|
+
inline T& setOutSide(Side outSide)
|
54
|
+
{
|
55
|
+
mOutSide = outSide;
|
56
|
+
return (T&)*this;
|
57
|
+
}
|
58
|
+
|
59
|
+
/// Gets the out side of the shape
|
60
|
+
inline Side getOutSide() const
|
61
|
+
{
|
62
|
+
return mOutSide;
|
63
|
+
}
|
64
|
+
|
65
|
+
/// Sets the number of segments between 2 control points
|
66
|
+
inline T& setNumSeg(unsigned int numSeg)
|
67
|
+
{
|
68
|
+
assert(numSeg>=1);
|
69
|
+
mNumSeg = numSeg;
|
70
|
+
return (T&)*this;
|
71
|
+
}
|
72
|
+
|
73
|
+
/// Closes the spline
|
74
|
+
inline T& close()
|
75
|
+
{
|
76
|
+
mClosed = true;
|
77
|
+
return (T&)*this;
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
//-----------------------------------------------------------------------
|
82
|
+
/**
|
83
|
+
* Produces a shape from Cubic Hermite control points
|
84
|
+
*/
|
85
|
+
class _ProceduralExport CubicHermiteSpline2 : public BaseSpline2<CubicHermiteSpline2>
|
86
|
+
{
|
87
|
+
typedef CubicHermiteSplineControlPoint<Ogre::Vector2> ControlPoint;
|
88
|
+
|
89
|
+
std::vector<ControlPoint> mPoints;
|
90
|
+
|
91
|
+
public:
|
92
|
+
/// Adds a control point
|
93
|
+
inline CubicHermiteSpline2& addPoint(const Ogre::Vector2& p, const Ogre::Vector2& before, const Ogre::Vector2& after)
|
94
|
+
{
|
95
|
+
mPoints.push_back(ControlPoint(p, before, after));
|
96
|
+
return *this;
|
97
|
+
}
|
98
|
+
/// Adds a control point
|
99
|
+
inline CubicHermiteSpline2& addPoint(const Ogre::Vector2& p, const Ogre::Vector2& tangent)
|
100
|
+
{
|
101
|
+
mPoints.push_back(ControlPoint(p, tangent, tangent));
|
102
|
+
return *this;
|
103
|
+
}
|
104
|
+
/// Adds a control point
|
105
|
+
inline CubicHermiteSpline2& addPoint(const Ogre::Vector2& p, CubicHermiteSplineAutoTangentMode autoTangentMode = AT_CATMULL)
|
106
|
+
{
|
107
|
+
ControlPoint cp;
|
108
|
+
cp.position = p;
|
109
|
+
cp.autoTangentBefore = autoTangentMode;
|
110
|
+
cp.autoTangentAfter = autoTangentMode;
|
111
|
+
mPoints.push_back(cp);
|
112
|
+
return *this;
|
113
|
+
}
|
114
|
+
|
115
|
+
/// Adds a control point
|
116
|
+
inline CubicHermiteSpline2& addPoint(Ogre::Real x, Ogre::Real y, CubicHermiteSplineAutoTangentMode autoTangentMode = AT_CATMULL)
|
117
|
+
{
|
118
|
+
ControlPoint cp;
|
119
|
+
cp.position = Ogre::Vector2(x,y);
|
120
|
+
cp.autoTangentBefore = autoTangentMode;
|
121
|
+
cp.autoTangentAfter = autoTangentMode;
|
122
|
+
mPoints.push_back(cp);
|
123
|
+
return *this;
|
124
|
+
}
|
125
|
+
|
126
|
+
/// Safely gets a control point
|
127
|
+
inline const ControlPoint& safeGetPoint(unsigned int i) const
|
128
|
+
{
|
129
|
+
if (mClosed)
|
130
|
+
return mPoints[Utils::modulo(i,mPoints.size())];
|
131
|
+
return mPoints[Utils::cap(i,0,mPoints.size()-1)];
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Builds a shape from control points
|
136
|
+
*/
|
137
|
+
Shape realizeShape();
|
138
|
+
};
|
139
|
+
|
140
|
+
//-----------------------------------------------------------------------
|
141
|
+
/**
|
142
|
+
* Builds a shape from a Catmull-Rom Spline.
|
143
|
+
* A catmull-rom smoothly interpolates position between control points
|
144
|
+
*/
|
145
|
+
class _ProceduralExport CatmullRomSpline2 : public BaseSpline2<CatmullRomSpline2>
|
146
|
+
{
|
147
|
+
std::vector<Ogre::Vector2> mPoints;
|
148
|
+
public:
|
149
|
+
/// Adds a control point
|
150
|
+
inline CatmullRomSpline2& addPoint(const Ogre::Vector2& pt)
|
151
|
+
{
|
152
|
+
mPoints.push_back(pt);
|
153
|
+
return *this;
|
154
|
+
}
|
155
|
+
|
156
|
+
/// Adds a control point
|
157
|
+
inline CatmullRomSpline2& addPoint(Ogre::Real x, Ogre::Real y)
|
158
|
+
{
|
159
|
+
mPoints.push_back(Ogre::Vector2(x,y));
|
160
|
+
return *this;
|
161
|
+
}
|
162
|
+
|
163
|
+
/// Safely gets a control point
|
164
|
+
inline const Ogre::Vector2& safeGetPoint(unsigned int i) const
|
165
|
+
{
|
166
|
+
if (mClosed)
|
167
|
+
return mPoints[Utils::modulo(i,mPoints.size())];
|
168
|
+
return mPoints[Utils::cap(i,0,mPoints.size()-1)];
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Build a shape from bezier control points
|
173
|
+
*/
|
174
|
+
Shape realizeShape();
|
175
|
+
};
|
176
|
+
|
177
|
+
//-----------------------------------------------------------------------
|
178
|
+
/**
|
179
|
+
* Builds a shape from a Kochanek Bartels spline.
|
180
|
+
*
|
181
|
+
* More details here : http://en.wikipedia.org/wiki/Kochanek%E2%80%93Bartels_spline
|
182
|
+
*/
|
183
|
+
class _ProceduralExport KochanekBartelsSpline2 : public BaseSpline2<KochanekBartelsSpline2>
|
184
|
+
{
|
185
|
+
typedef KochanekBartelsSplineControlPoint<Ogre::Vector2> ControlPoint;
|
186
|
+
|
187
|
+
std::vector<ControlPoint> mPoints;
|
188
|
+
|
189
|
+
public:
|
190
|
+
/// Adds a control point
|
191
|
+
inline KochanekBartelsSpline2& addPoint(Ogre::Real x, Ogre::Real y)
|
192
|
+
{
|
193
|
+
mPoints.push_back(ControlPoint(Ogre::Vector2(x,y)));
|
194
|
+
return *this;
|
195
|
+
}
|
196
|
+
|
197
|
+
/// Adds a control point
|
198
|
+
inline KochanekBartelsSpline2& addPoint(Ogre::Vector2 p)
|
199
|
+
{
|
200
|
+
mPoints.push_back(ControlPoint(p));
|
201
|
+
return *this;
|
202
|
+
}
|
203
|
+
|
204
|
+
/// Safely gets a control point
|
205
|
+
inline const ControlPoint& safeGetPoint(unsigned int i) const
|
206
|
+
{
|
207
|
+
if (mClosed)
|
208
|
+
return mPoints[Utils::modulo(i,mPoints.size())];
|
209
|
+
return mPoints[Utils::cap(i,0,mPoints.size()-1)];
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Adds a control point to the spline
|
214
|
+
* @arg p Point position
|
215
|
+
* @arg t Tension +1 = Tight -1 = Round
|
216
|
+
* @arg b Bias +1 = Post-shoot -1 = Pre-shoot
|
217
|
+
* @arg c Continuity +1 = Inverted Corners -1 = Box Corners
|
218
|
+
*/
|
219
|
+
inline KochanekBartelsSpline2& addPoint(Ogre::Vector2 p, Ogre::Real t, Ogre::Real b, Ogre::Real c)
|
220
|
+
{
|
221
|
+
mPoints.push_back(ControlPoint(p,t,b,c));
|
222
|
+
return *this;
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Builds a shape from control points
|
227
|
+
*/
|
228
|
+
Shape realizeShape();
|
229
|
+
|
230
|
+
};
|
231
|
+
|
232
|
+
//-----------------------------------------------------------------------
|
233
|
+
/**
|
234
|
+
* Builds a rectangular shape
|
235
|
+
*/
|
236
|
+
class _ProceduralExport RectangleShape
|
237
|
+
{
|
238
|
+
Ogre::Real mWidth,mHeight;
|
239
|
+
|
240
|
+
public:
|
241
|
+
/// Default constructor
|
242
|
+
RectangleShape() : mWidth(1.0), mHeight(1.0) {}
|
243
|
+
|
244
|
+
/// Sets width
|
245
|
+
inline RectangleShape& setWidth(Ogre::Real width)
|
246
|
+
{
|
247
|
+
mWidth = width;
|
248
|
+
return *this;
|
249
|
+
}
|
250
|
+
|
251
|
+
/// Sets height
|
252
|
+
inline RectangleShape& setHeight(Ogre::Real height)
|
253
|
+
{
|
254
|
+
mHeight = height;
|
255
|
+
return *this;
|
256
|
+
}
|
257
|
+
|
258
|
+
/// Builds the shape
|
259
|
+
Shape realizeShape()
|
260
|
+
{
|
261
|
+
Shape s;
|
262
|
+
s.addPoint(-.5f*mWidth,-.5f*mHeight)
|
263
|
+
.addPoint(.5f*mWidth,-.5f*mHeight)
|
264
|
+
.addPoint(.5f*mWidth,.5f*mHeight)
|
265
|
+
.addPoint(-.5f*mWidth,.5f*mHeight)
|
266
|
+
.close();
|
267
|
+
return s;
|
268
|
+
}
|
269
|
+
};
|
270
|
+
|
271
|
+
//-----------------------------------------------------------------------
|
272
|
+
/**
|
273
|
+
* Builds a circular shape
|
274
|
+
*/
|
275
|
+
class _ProceduralExport CircleShape
|
276
|
+
{
|
277
|
+
Ogre::Real mRadius;
|
278
|
+
unsigned int mNumSeg;
|
279
|
+
|
280
|
+
public:
|
281
|
+
/// Default constructor
|
282
|
+
CircleShape() : mRadius(1.0), mNumSeg(8) {}
|
283
|
+
|
284
|
+
/// Sets radius
|
285
|
+
inline CircleShape& setRadius(Ogre::Real radius)
|
286
|
+
{
|
287
|
+
mRadius = radius;
|
288
|
+
return *this;
|
289
|
+
}
|
290
|
+
|
291
|
+
/// Sets number of segments
|
292
|
+
inline CircleShape& setNumSeg(unsigned int numSeg)
|
293
|
+
{
|
294
|
+
mNumSeg = numSeg;
|
295
|
+
return *this;
|
296
|
+
}
|
297
|
+
|
298
|
+
/// Builds the shape
|
299
|
+
Shape realizeShape()
|
300
|
+
{
|
301
|
+
Shape s;
|
302
|
+
Ogre::Real deltaAngle = Ogre::Math::TWO_PI/(Ogre::Real)mNumSeg;
|
303
|
+
for (unsigned int i = 0; i < mNumSeg; ++i)
|
304
|
+
{
|
305
|
+
s.addPoint(mRadius*cosf(i*deltaAngle), mRadius*sinf(i*deltaAngle));
|
306
|
+
}
|
307
|
+
s.close();
|
308
|
+
return s;
|
309
|
+
}
|
310
|
+
};
|
311
|
+
//-----------------------------------------------------------------------
|
312
|
+
/**
|
313
|
+
* Produces a shape from Cubic Hermite control points
|
314
|
+
*/
|
315
|
+
class _ProceduralExport RoundedCornerSpline2 : public BaseSpline2<RoundedCornerSpline2>
|
316
|
+
{
|
317
|
+
Ogre::Real mRadius;
|
318
|
+
|
319
|
+
std::vector<Ogre::Vector2> mPoints;
|
320
|
+
|
321
|
+
public:
|
322
|
+
RoundedCornerSpline2() : mRadius(.1f) {}
|
323
|
+
|
324
|
+
/// Sets the radius of the corners
|
325
|
+
inline RoundedCornerSpline2& setRadius(Ogre::Real radius)
|
326
|
+
{
|
327
|
+
mRadius = radius;
|
328
|
+
return *this;
|
329
|
+
}
|
330
|
+
|
331
|
+
/// Adds a control point
|
332
|
+
inline RoundedCornerSpline2& addPoint(const Ogre::Vector2& p)
|
333
|
+
{
|
334
|
+
mPoints.push_back(p);
|
335
|
+
return *this;
|
336
|
+
}
|
337
|
+
|
338
|
+
/// Adds a control point
|
339
|
+
inline RoundedCornerSpline2& addPoint(Ogre::Real x, Ogre::Real y)
|
340
|
+
{
|
341
|
+
mPoints.push_back(Ogre::Vector2(x,y));
|
342
|
+
return *this;
|
343
|
+
}
|
344
|
+
|
345
|
+
/// Safely gets a control point
|
346
|
+
inline const Ogre::Vector2& safeGetPoint(unsigned int i) const
|
347
|
+
{
|
348
|
+
if (mClosed)
|
349
|
+
return mPoints[Utils::modulo(i,mPoints.size())];
|
350
|
+
return mPoints[Utils::cap(i,0,mPoints.size()-1)];
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Builds a shape from control points
|
355
|
+
*/
|
356
|
+
Shape realizeShape();
|
357
|
+
};
|
358
|
+
|
359
|
+
|
360
|
+
}
|
361
|
+
|
362
|
+
#endif
|
@@ -0,0 +1,80 @@
|
|
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_SPHERE_GENERATOR_INCLUDED
|
29
|
+
#define PROCEDURAL_SPHERE_GENERATOR_INCLUDED
|
30
|
+
|
31
|
+
#include "ProceduralMeshGenerator.h"
|
32
|
+
#include "ProceduralPlatform.h"
|
33
|
+
|
34
|
+
namespace Procedural
|
35
|
+
{
|
36
|
+
/** Builds an UV sphere mesh
|
37
|
+
*/
|
38
|
+
class _ProceduralExport SphereGenerator : public MeshGenerator<SphereGenerator>
|
39
|
+
{
|
40
|
+
Ogre::Real mRadius;
|
41
|
+
unsigned int mNumRings;
|
42
|
+
unsigned int mNumSegments;
|
43
|
+
|
44
|
+
public:
|
45
|
+
/// Constructor with arguments
|
46
|
+
SphereGenerator(Ogre::Real radius = 1.f, int numRings = 16, int numSegments = 16) :
|
47
|
+
mRadius(radius),mNumRings(numRings), mNumSegments(numSegments)
|
48
|
+
|
49
|
+
{}
|
50
|
+
|
51
|
+
/** Sets the radius of the sphere (default=1) */
|
52
|
+
inline SphereGenerator & setRadius(Ogre::Real radius)
|
53
|
+
{
|
54
|
+
mRadius = radius;
|
55
|
+
return *this;
|
56
|
+
}
|
57
|
+
|
58
|
+
/** Sets the number of rings (default=16) */
|
59
|
+
inline SphereGenerator & setNumRings(unsigned int numRings)
|
60
|
+
{
|
61
|
+
mNumRings = numRings;
|
62
|
+
return *this;
|
63
|
+
}
|
64
|
+
|
65
|
+
/** Sets the number of segments (default=16) */
|
66
|
+
inline SphereGenerator & setNumSegments(unsigned int numSegments)
|
67
|
+
{
|
68
|
+
mNumSegments = numSegments;
|
69
|
+
return *this;
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Builds the mesh into the given TriangleBuffer
|
74
|
+
* @param buffer The TriangleBuffer on where to append the mesh.
|
75
|
+
*/
|
76
|
+
void addToTriangleBuffer(TriangleBuffer& buffer) const;
|
77
|
+
|
78
|
+
};
|
79
|
+
}
|
80
|
+
#endif
|
@@ -0,0 +1,168 @@
|
|
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_SPLINES_INCLUDED
|
29
|
+
#define PROCEDURAL_SPLINES_INCLUDED
|
30
|
+
|
31
|
+
#include "Ogre.h"
|
32
|
+
|
33
|
+
namespace Procedural
|
34
|
+
{
|
35
|
+
enum CubicHermiteSplineAutoTangentMode
|
36
|
+
{
|
37
|
+
AT_NONE, AT_STRAIGHT, AT_CATMULL
|
38
|
+
};
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Template control point for Cubic Hermite splines.
|
42
|
+
*/
|
43
|
+
template <class T>
|
44
|
+
struct CubicHermiteSplineControlPoint
|
45
|
+
{
|
46
|
+
/// Position of the control point
|
47
|
+
T position;
|
48
|
+
/// Tangent just before the control point
|
49
|
+
T tangentBefore;
|
50
|
+
/// Tangent just after the control point
|
51
|
+
T tangentAfter;
|
52
|
+
/// Auto tangent mode for the tangent just before the control point
|
53
|
+
CubicHermiteSplineAutoTangentMode autoTangentBefore;
|
54
|
+
/// Auto tangent mode for the tangent just after the control point
|
55
|
+
CubicHermiteSplineAutoTangentMode autoTangentAfter;
|
56
|
+
|
57
|
+
/// Default constructor
|
58
|
+
CubicHermiteSplineControlPoint() {}
|
59
|
+
|
60
|
+
/// Constructor with arguments
|
61
|
+
CubicHermiteSplineControlPoint(const T& p, const T& before, const T& after) : position(p), tangentBefore(before), tangentAfter(after), autoTangentBefore(AT_NONE), autoTangentAfter(AT_NONE) {}
|
62
|
+
};
|
63
|
+
|
64
|
+
template <class T>
|
65
|
+
void computeTangents(CubicHermiteSplineControlPoint<T>& point, const T& pointBefore, const T& pointAfter)
|
66
|
+
{
|
67
|
+
switch (point.autoTangentBefore)
|
68
|
+
{
|
69
|
+
case AT_STRAIGHT:
|
70
|
+
point.tangentBefore = point.position - pointBefore;
|
71
|
+
break;
|
72
|
+
case AT_CATMULL:
|
73
|
+
point.tangentBefore = pointAfter - pointBefore;
|
74
|
+
break;
|
75
|
+
case AT_NONE:
|
76
|
+
break;
|
77
|
+
}
|
78
|
+
|
79
|
+
switch (point.autoTangentAfter)
|
80
|
+
{
|
81
|
+
case AT_STRAIGHT:
|
82
|
+
point.tangentAfter = pointAfter - point.position;
|
83
|
+
break;
|
84
|
+
case AT_CATMULL:
|
85
|
+
point.tangentAfter = pointAfter - pointBefore;
|
86
|
+
break;
|
87
|
+
case AT_NONE:
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
// Computes the Cubic Hermite interpolation between 2 control points
|
93
|
+
// Warning : does not compute auto-tangents, as AUTOTANGENT_CATMULL depend on context
|
94
|
+
// Auto-Tangents should be computed before that call
|
95
|
+
template<class T>
|
96
|
+
void computeCubicHermitePoints(const CubicHermiteSplineControlPoint<T>& pointBefore, const CubicHermiteSplineControlPoint<T>& pointAfter, unsigned int numSeg, std::vector<T>& pointList)
|
97
|
+
{
|
98
|
+
const T& p0 = pointBefore.position;
|
99
|
+
const T& m0 = pointBefore.tangentAfter;
|
100
|
+
const T& p1 = pointAfter.position;
|
101
|
+
const T& m1 = pointAfter.tangentBefore;
|
102
|
+
|
103
|
+
for (unsigned int j = 0; j < numSeg; ++j)
|
104
|
+
{
|
105
|
+
Ogre::Real t = (Ogre::Real)j/(Ogre::Real)numSeg;
|
106
|
+
Ogre::Real t2 = t*t;
|
107
|
+
Ogre::Real t3 = t2*t;
|
108
|
+
T P = (2*t3-3*t2+1)*p0+(t3-2*t2+t)*m0+(-2*t3+3*t2)*p1+(t3-t2)*m1;
|
109
|
+
pointList.push_back(P);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
template<class T>
|
114
|
+
void computeCatmullRomPoints(const T& P1, const T& P2, const T& P3, const T& P4, unsigned int numSeg, std::vector<T>& pointList)
|
115
|
+
{
|
116
|
+
for (unsigned int j = 0; j < numSeg; ++j)
|
117
|
+
{
|
118
|
+
Ogre::Real t = (Ogre::Real)j/(Ogre::Real)numSeg;
|
119
|
+
Ogre::Real t2 = t*t;
|
120
|
+
Ogre::Real t3 = t*t2;
|
121
|
+
T P = 0.5f*((-t3+2.f*t2-t)*P1 + (3.f*t3-5.f*t2+2.f)*P2 + (-3.f*t3+4.f*t2+t)*P3 + (t3-t2)*P4);
|
122
|
+
pointList.push_back(P);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Template control point for KochanekBartels's splines
|
128
|
+
*/
|
129
|
+
template <class T>
|
130
|
+
struct KochanekBartelsSplineControlPoint
|
131
|
+
{
|
132
|
+
/// Position of the control point
|
133
|
+
T position;
|
134
|
+
|
135
|
+
/// Tension of the control point
|
136
|
+
Ogre::Real tension;
|
137
|
+
|
138
|
+
/// Bias of the control point
|
139
|
+
Ogre::Real bias;
|
140
|
+
|
141
|
+
/// Continuity of the control point
|
142
|
+
Ogre::Real continuity;
|
143
|
+
|
144
|
+
/// Constructor with arguments
|
145
|
+
KochanekBartelsSplineControlPoint(const T& p, Ogre::Real t, Ogre::Real b, Ogre::Real c) : position(p), tension(t), bias(b), continuity(c) {}
|
146
|
+
/// Constructor with tension=bias=continuity=0
|
147
|
+
KochanekBartelsSplineControlPoint(const T& p) : position(p), tension(0.), bias(0.), continuity(0.) {}
|
148
|
+
};
|
149
|
+
|
150
|
+
template<class T>
|
151
|
+
void computeKochanekBartelsPoints(const KochanekBartelsSplineControlPoint<T>& P1, const KochanekBartelsSplineControlPoint<T>& P2,
|
152
|
+
const KochanekBartelsSplineControlPoint<T>& P3, const KochanekBartelsSplineControlPoint<T>& P4, unsigned int numSeg, std::vector<T>& pointList)
|
153
|
+
{
|
154
|
+
Ogre::Vector2 m0 = (1-P2.tension)*(1+P2.bias)*(1+P2.continuity)/2.f*(P2.position-P1.position)+(1-P2.tension)*(1-P2.bias)*(1-P2.continuity)/2.f*(P3.position-P2.position);
|
155
|
+
Ogre::Vector2 m1 = (1-P3.tension)*(1+P3.bias)*(1-P3.continuity)/2.f*(P3.position-P2.position)+(1-P3.tension)*(1-P3.bias)*(1+P3.continuity)/2.f*(P4.position-P3.position);
|
156
|
+
|
157
|
+
for (unsigned int j = 0;j < numSeg; ++j)
|
158
|
+
{
|
159
|
+
Ogre::Real t = (Ogre::Real)j/(Ogre::Real)numSeg;
|
160
|
+
Ogre::Real t2 = t*t;
|
161
|
+
Ogre::Real t3 = t2*t;
|
162
|
+
T P = (2*t3-3*t2+1)*P2.position+(t3-2*t2+t)*m0+(-2*t3+3*t2)*P3.position+(t3-t2)*m1;
|
163
|
+
pointList.push_back(P);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
#endif
|