Spinning Topp Logo BlackTopp Studios
inc
cycloidmodifier.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU 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  The Mezzanine Engine 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 General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 /*
41  -----------------------------------------------------------------------------
42  This source file is part of ogre-procedural
43 
44  For the latest info, see http://code.google.com/p/ogre-procedural/
45 
46  Copyright (c) 2010-2013 Michael Broutin
47 
48  Permission is hereby granted, free of charge, to any person obtaining a copy
49  of this software and associated documentation files (the "Software"), to deal
50  in the Software without restriction, including without limitation the rights
51  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52  copies of the Software, and to permit persons to whom the Software is
53  furnished to do so, subject to the following conditions:
54 
55  The above copyright notice and this permission notice shall be included in
56  all copies or substantial portions of the Software.
57 
58  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64  THE SOFTWARE.
65  -----------------------------------------------------------------------------
66  */
67 #ifndef _graphicsproceduralcycloidmodifier_h
68 #define _graphicsproceduralcycloidmodifier_h
69 
70 #include "Graphics/Procedural/Texture/texturemodifier.h"
71 
72 #include "vector2.h"
73 
74 namespace Mezzanine
75 {
76  namespace Graphics
77  {
78  namespace Procedural
79  {
80  ///////////////////////////////////////////////////////////////////////////////
81  /// @brief A modifier that will draw a series of curved line segments.
82  /// @details Wikipedia says this about Cycloids: "A cycloid is the curve traced by a point on the rim of a circular wheel as the wheel rolls along a
83  /// line without slippage. It is an example of a roulette, a curve generated by a curve rolling on another curve." @n
84  /// Currently this modifier supports 6 types of curves that can be drawn: @n
85  /// Hypocyloid - http://en.wikipedia.org/wiki/Hypocycloid @n
86  /// Hypotrochoid - http://en.wikipedia.org/wiki/Hypotrochoid @n
87  /// Epicycloid - http://en.wikipedia.org/wiki/Epicycloid @n
88  /// Epitrochoid - http://en.wikipedia.org/wiki/Epitrochoid @n
89  /// Rose Curve - http://en.wikipedia.org/wiki/Rose_(mathematics) @n
90  /// Lissajous Curve - http://en.wikipedia.org/wiki/Lissajous_curve @n @n
91  /// Setting the type will also set sane defaults for that type of Cycloid, but those default parameters are not strictly required and can be tinkered
92  /// with, although you may get odd results depending on which parameter you alter and by how much. Consult the documentation on the types of Cycloids
93  /// if you feel adventurous. The default parameters are as follows: @n
94  /// @par Default parameters
95  /// <table><tr><th>Name</th><th>Parameter <em>R</em></th><th>Parameter <em>r</em></th><th>Parameter <em>d</em></th><th>Parameter <em>e</em></th><th colspan="2">Parameter <em>k</em></th></tr>
96  /// <tr><td>Hypocycloid</td><td>3/6 * Size</td><td>1/6 * Size</td><td align="center"><em>unsused</em></td><td align="center" rowspan="5"><em>unsused</em><td rowspan="4">k = R / r</td><td>3</td></tr>
97  /// <tr><td>Hypotrochoid</td><td>5/14 * Size</td><td>3/14 * Size</td><td>5/14 * Size</td><td>2</td></tr>
98  /// <tr><td>Epicycloid</td><td>3/10 * Size</td><td>1/10 * Size</td><td align="center"><em>unsused</em><td>3</td></tr>
99  /// <tr><td>Epitrochoid</td><td>3/10 * Size</td><td>1/10 * Size</td><td>1/20 * Size</td><td>3</td></tr>
100  /// <tr><td>Rose curve</td><td>1/2 * Size</td><td>4</td><td>1</td><td rowspan="2">k = r / d</td><td>4</td></tr>
101  /// <tr><td>Lissajous curve</td><td>1/2 * Size</td><td>5</td><td>4</td><td>&pi;/2</td><td>5/4</td></tr></table>
102  ///////////////////////////////////////
104  {
105  public:
106  /// @brief The type of Cycloid to draw.
108  {
109  CT_Hypocycloid = 1, ///< Sets defaults for drawing a Hypocyloid. See class detailed description for more information.
110  CT_Hypotrochoid = 2, ///< Sets defaults for drawing a Hypotrochoid. See class detailed description for more information.
111  CT_Epicycloid = 3, ///< Sets defaults for drawing a Epicycloid. See class detailed description for more information.
112  CT_Epitrochoid = 4, ///< Sets defaults for drawing a Epitrochoid. See class detailed description for more information.
113  CT_RoseCurve = 5, ///< Sets defaults for drawing a Rose Curve. See class detailed description for more information.
114  CT_LissajousCurve = 6 ///< Sets defaults for drawing a Lissajous Curve. See class detailed description for more information.
115  };
116  /// @brief An enum describing the parameters that can be altered for each type of Cycloid.
118  {
119  CP_Param_R = 1, ///< Generally this is altering the radius of the base circle that the drawing circle rotates around.
120  CP_Param_r = 2, ///< Generally this is altering the radius of the drawing circle.
121  CP_Param_d = 3, ///< Generally this is altering the distance of the drawing pen from the center of the drawing circle.
122  CP_Param_e = 4, ///< This is exclusively used by a Lissajous Curve and skews the angle at which the drawing perspective is done, usually making it look more compressed.
123  CP_Param_k = 5, ///< In a Rose Curve this will generate k petals if 2*k is even. If k is odd then it will generate k petals.
124 
125  CP_LargeCircleRadius = CP_Param_R, ///< Generally this is altering the radius of the base circle that the drawing circle rotates around.
126  CP_SmallCircleRadius = CP_Param_r, ///< Generally this is altering the radius of the drawing circle.
127  CP_DistanceFromCenter = CP_Param_d, ///< Generally this is altering the distance of the drawing pen from the center of the drawing circle.
128  CP_RotationAngle = CP_Param_e, ///< This is exclusively used by a Lissajous Curve and skews the angle at which the drawing perspective is done, usually making it look more compressed.
129  CP_BasePetals = CP_Param_k ///< In a Rose Curve this will generate k petals if 2*k is even. If k is odd then it will generate k petals.
130  };
131  protected:
132  /// @internal
133  /// @brief The colour of the curve line to draw.
135  /// @internal
136  /// @brief The center of the cycloid on the target texture.
138  /// @internal
139  /// @brief The size of the curved line to draw.
141  /// @internal
142  /// @brief See CycloidParameter enum for details.
144  /// @internal
145  /// @brief See CycloidParameter enum for details.
147  /// @internal
148  /// @brief See CycloidParameter enum for details.
150  /// @internal
151  /// @brief See CycloidParameter enum for details.
153  /// @internal
154  /// @brief The type of Cycloid to draw.
156 
157  /// @internal
158  /// @brief Draws a Hypocycloid to the texture.
159  /// @param XPos The central position on the X axis of the shape to draw on the texture.
160  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
161  /// @param Step The pixel distance at which to end the current drawing segment.
162  /// @param Buffer The buffer being drawn to.
163  void ProcessHypocycloid(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
164  /// @internal
165  /// @brief Draws a Hypotrochoid to the texture.
166  /// @param XPos The central position on the X axis of the shape to draw on the texture.
167  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
168  /// @param Step The pixel distance at which to end the current drawing segment.
169  /// @param Buffer The buffer being drawn to.
170  void ProcessHypotrochoid(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
171  /// @internal
172  /// @brief Draws a Epicycloid to the texture.
173  /// @param XPos The central position on the X axis of the shape to draw on the texture.
174  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
175  /// @param Step The pixel distance at which to end the current drawing segment.
176  /// @param Buffer The buffer being drawn to.
177  void ProcessEpicycloid(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
178  /// @internal
179  /// @brief Draws a Epitrochoid to the texture.
180  /// @param XPos The central position on the X axis of the shape to draw on the texture.
181  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
182  /// @param Step The pixel distance at which to end the current drawing segment.
183  /// @param Buffer The buffer being drawn to.
184  void ProcessEpitrochoid(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
185  /// @internal
186  /// @brief Draws a Rose Curve to the texture.
187  /// @param XPos The central position on the X axis of the shape to draw on the texture.
188  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
189  /// @param Step The pixel distance at which to end the current drawing segment.
190  /// @param Buffer The buffer being drawn to.
191  void ProcessRoseCurve(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
192  /// @internal
193  /// @brief Draws a Lissajous Curve to the texture.
194  /// @param XPos The central position on the X axis of the shape to draw on the texture.
195  /// @param YPos The central position on the Y axis of the shape to draw on the texture.
196  /// @param Step The pixel distance at which to end the current drawing segment.
197  /// @param Buffer The buffer being drawn to.
198  void ProcessLissajousCurve(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
199  /// @internal
200  /// @brief Convenience method for the setting of the actual pixels being drawn.
201  /// @param XPos The position on the X axis of the pixel to paint to the texture.
202  /// @param YPos The position on the Y axis of the pixel to paint to the texture.
203  /// @param Step The pixel distance at which to end the current drawing segment.
204  /// @param Buffer The buffer being drawn to.
205  void Paint(const Integer XPos, const Integer YPos, const Real Step, TextureBuffer& Buffer);
206  public:
207  /// @brief Blank constructor.
208  CycloidModifier();
209  /// @brief Class destructor.
210  virtual ~CycloidModifier();
211 
212  ///////////////////////////////////////////////////////////////////////////////
213  // Utility
214 
215  /// @copydoc TextureModifier::Modify(TextureBuffer&)
216  virtual void Modify(TextureBuffer& Buffer);
217  /// @copydoc TextureModifier::GetName() const
218  virtual String GetName() const;
219 
220  ///////////////////////////////////////////////////////////////////////////////
221  // Configuration
222 
223  /// @brief Sets the type of Cycloid that will be rendered.
224  /// @param ToDraw The type of Cycloid to draw. Initial Value: CT_Hypocycloid.
225  /// @return Returns a reference to this.
226  CycloidModifier& SetCycloidType(const CycloidType ToDraw);
227  /// @brief Sets the default values for every parameter.
228  /// @param SquareSize The pixel width and height of the texture to draw to.
229  /// @return Returns a reference to this.
230  CycloidModifier& SetDefaultParameters(const Whole SquareSize);
231  /// @brief Sets the default values for every parameter.
232  /// @param TextureWidth The pixel width of the texture to draw to.
233  /// @param TextureHeight The pixel height of the texture to draw to.
234  /// @return Returns a reference to this.
235  CycloidModifier& SetDefaultParameters(const Whole TextureWidth, const Whole TextureHeight);
236  /// @brief Sets the colour of the lines to be drawn for the Cycloid.
237  /// @param Colour The colour of the Cycloid to draw. Initial Value: (1.0,1.0,1.0,1.0).
238  /// @return Returns a reference to this.
239  CycloidModifier& SetColour(const ColourValue& Colour);
240  /// @brief Sets the colour of the lines to be drawn for the Cycloid.
241  /// @param Red The amount of red in the Cycloid that will be drawn. Initial Value: 1.0.
242  /// @param Green The amount of green in the Cycloid that will be drawn. Initial Value: 1.0.
243  /// @param Blue The amount of blue in the Cycloid that will be drawn. Initial Value: 1.0.
244  /// @param Alpha The amount of alpha in the Cycloid that will be drawn. Initial Value: 1.0.
245  /// @return Returns a reference to this.
246  CycloidModifier& SetColour(const Real Red, const Real Green, const Real Blue, const Real Alpha = 1.0);
247  /// @brief Sets the center position of the Cycloid.
248  /// @param Center The center position of the Cycloid on the texture in relative units. Initial Value: (0.5,0.5).
249  /// @return Returns a reference to this.
250  CycloidModifier& SetCycloidCenter(const Vector2& Center);
251  /// @brief Sets the center position of the Cycloid.
252  /// @param CenterX The center position of the Cycloid on the texture on the X axis in relative units. Initial Value: 0.5.
253  /// @param CenterY The center position of the Cycloid on the texture on the Y axis in relative units. Initial Value: 0.5.
254  /// @return Returns a reference to this.
255  CycloidModifier& SetCycloidCenter(const Real CenterX, const Real CenterY);
256  /// @brief Sets the center position of the Cycloid on the X axis.
257  /// @param X The center position of the Cycloid on the texture on the X axis in relative units. Initial Value: 0.5.
258  /// @return Returns a reference to this.
259  CycloidModifier& SetCycloidCenterX(const Real X);
260  /// @brief Sets the center position of the Cycloid on the Y axis.
261  /// @param Y The center position of the Cycloid on the texture on the Y axis in relative units. Initial Value: 0.5.
262  /// @return Returns a reference to this.
263  CycloidModifier& SetCycloidCenterY(const Real Y);
264  /// @brief Sets a Cycloid parameter.
265  /// @param Param The parameter to be altered. See the CycloidParameter enum for more details.
266  /// @param Value The value to be assigned to the specified parameter. See Default Parameters table in the class detailed description for more information.
267  /// @return Returns a reference to this.
268  CycloidModifier& SetCycloidParameter(const CycloidParameter Param, const Real Value);
269  /// @brief Sets the size of the line to draw for the Cycloid.
270  /// @param Size The pixel width of the lines drawn for the Cycloid. Initial Value: 1.
271  /// @return Returns a reference to this.
272  CycloidModifier& SetCycloidPenSize(const Real Size);
273  };//CycloidModifier
274  }//Procedural
275  }//Graphics
276 }//Mezzanine
277 
278 #endif
Real Parameter_R
See CycloidParameter enum for details.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Real Parameter_e
See CycloidParameter enum for details.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
CycloidType Type
The type of Cycloid to draw.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
CycloidParameter
An enum describing the parameters that can be altered for each type of Cycloid.
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
Vector2 CycloidCenter
The center of the cycloid on the target texture.
Whole CycloidPenSize
The size of the curved line to draw.
Real Parameter_r
See CycloidParameter enum for details.
ColourValue CycloidColour
The colour of the curve line to draw.
A convenience buffer that stores pixel colour values of a texture to be generated.
Definition: texturebuffer.h:86
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
Real Parameter_d
See CycloidParameter enum for details.
A base class for modifying the contents of an already populated texture buffer.
A modifier that will draw a series of curved line segments.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159