GL Studio C++ Runtime API
gls_sphere.h
Go to the documentation of this file.
1/// \file gls_sphere.h
2/// \brief The disti::GlsSphere class.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef DISTI_INCLUDED_GLS_SPHERE_H
40#define DISTI_INCLUDED_GLS_SPHERE_H
41
42#include "display.h"
43#include "dynamic_array.h"
44#include "gls_color.h"
46#include "gls_include.h"
47
48#define DEF_SPHERE_STACKS 10 ///< The default number of stacks for a new GlsSphere.
49#define DEF_SPHERE_SLICES 10 ///< The default number of slices for a new GlsSphere.
50#define DEF_SPHERE_SLICE_START 0.0f ///< The default slice start angle in degrees for a new GlsSphere.
51#define DEF_SPHERE_SLICE_END 360.0f ///< The default slice end angle in degrees for a new GlsSphere.
52#define DEF_SPHERE_STACK_START 0.0f ///< The default stack start angle in degrees for a new GlsSphere.
53#define DEF_SPHERE_STACK_END 180.0f ///< The default stack end angle in degrees for a new GlsSphere.
54
55namespace disti
56{
57/** gls Sphere Mapping */
58typedef enum
59{
60 GLS_SPHERE_SPHERICAL_MAP, /**< Spherical texture map */
61 GLS_SPHERE_CYLINDER_MAP /**< Cylindrical texture map */
63
64/**
65 Sphere Initializers
66*/
67typedef enum
68{
69 GLS_SPHERE_MAPPING = GLS_LAST_INITIALIZER + 1,
70 GLS_SPHERE_COLOR,
71 GLS_SPHERE_STACKS,
72 GLS_SPHERE_SLICES,
73 GLS_SPHERE_SLICE_START,
74 GLS_SPHERE_SLICE_END,
75 GLS_SPHERE_STACK_START,
76 GLS_SPHERE_STACK_END,
77 GLS_SPHERE_RADII
79
80/** The Sphere class. Implements Sphere primitive */
82{
83private:
84 /** Factors out common code shared by the various glsSphere constructors */
85 void CommonConstructorInit();
86 /** Assignment operator not implemented. Use CloneObject() or the copy constructor instead. */
89
90protected:
91 Vector _radii[ 3 ]; ///< Sphere radii
92
93 GlsColor _objectColor; ///< Fill color of object.
94
95 float _sliceStartDeg; ///< 0-180, where 0 is the bottom and 180 the top of the sphere.
96 float _sliceEndDeg; ///< 0-180, where 0 is the bottom and 180 the top of the sphere.
97 float _stackStartDeg; ///< 0-360, where 0 is the positive x-axis of the sphere.
98 float _stackEndDeg; ///< 0-360, where 0 is the positive x-axis of the sphere.
99
100 unsigned int _stacks; ///< Number of stacks used to draw the sphere.
101 unsigned int _slices; ///< Number of slices used to draw the sphere.
102
103 bool _needsRecalculate; ///< True when the sphere vertices need to be recalculated.
104 bool _needsResize; ///< True when the sphere needs to be resized.
105
106 glsSphereMapping_e _textureMappingType; ///< Texture mapping method.
107
108 /** Sets the resize and recalculate flags, causing the sphere to be resized and recalculated
109 * the next time the sphere draws
110 */
112
113 /** Recalculates the sphere vertices values */
115
116 /** Reallocates the vertices of the sphere */
118
119 GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
120
121#ifdef GLES
122 /** Set a single attribute from the GLO file.
123 * \param data The attribute to set and its associated data.
124 */
125 GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
126#endif
127
128private:
129 /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
130 * but does not guarantee that the collision point returned by Hit is the closest collision point
131 * to the observer
132 * \param point The logical coordinate of the click, relative to the object
133 * \param directionVector The direction of the pick vector
134 * \param collisionPoint Set to the point on the object hit by directionVector
135 * \return boolean indicating if the object was hit by the mouse
136 */
137 bool FirstHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
138
139 /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
140 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
141 * \param point The logical coordinate of the click, relative to the object
142 * \param directionVector The direction of the pick vector
143 * \param collisionPoint Set to the point on the object hit by directionVector
144 * \return boolean indicating if the object was hit by the mouse
145 */
146 bool BestHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
147
148public:
149 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
150 typedef DisplayObject _BaseClass; ///< Deprecated typedef for the base class.
151 typedef DisplayObject BaseClass; ///< Typedef for the base class.
152
153 friend class GlsSphereEditor;
154
155 /** Constructor. Creates a new GlsSphere object at given coordinates.
156 * \param x x-coordinate of new GlsSphere
157 * \param y y-coordinate of new GlsSphere
158 * \param z z-coordinate of new GlsSphere
159 */
160 GLS_EXPORT GlsSphere( float x, float y, float z );
161
162 /// Allocate a (blank) GlsSphere object.
163 /// \param newGlsSphere Unused, kept for backward compatibility.
164 GLS_EXPORT GlsSphere( bool newGlsSphere = true );
165
166 /// Copy constructor
167 /// \param that The object to copy from.
168 /// \param generateNames Whether or not to generate an instance name for this object.
169 GLS_EXPORT GlsSphere( const GlsSphere& that, const bool generateNames );
170
171 /** Destroy a GlsSphere object */
173
175
176 /** Gets the texture mapping method.
177 * \return Enumerative representation of texture mapping method
178 */
180
181 /* Unhides base class implementation. */
182 using BaseClass::TextureIndex;
184
185 /** Sets the texture mapping type
186 * \param value The texture mapping value (e.g. cylindrical or spherical)
187 */
189
190 /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
191 * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
192 * \param p1 Returns a point on the plane
193 * \param p2 Returns a point on the plane
194 * \param p3 Returns a point on the plane
195 * \param planeVector Returns the surface normal of the plane
196 * \return True if 3 coplanar points were found
197 */
199
201 GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 ) DISTI_METHOD_OVERRIDE;
203 GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
204
205 /* Unhides base class implementation. */
206 using BaseClass::Scale;
207 GLS_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar ) DISTI_METHOD_OVERRIDE;
208
209 /* Usually copies the attributes except for geometry attributes from one object to another.
210 * However, since the GlsSphere's geometry defines its properties, its geometry is copied.
211 * Used by the undo mechanism to undo most attribute change operations.
212 * \param src The object to copy properties from */
214
217
218 /* Unhides base class implementation. */
219 using BaseClass::Rotate;
220 GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
221
222 /* Unhides base class implementation. */
223 using BaseClass::SetFillColor;
224
226
227 /* Unhides base class implementation. */
228 using BaseClass::GetFillColor;
229
231
232 /** Sets the starting degree value for the stacks
233 * \param deg Degree value to which to set _stackStartDeg
234 */
235 virtual GLS_EXPORT void StackStartAngle( float deg );
236
237 /** Gets the starting degree value for the stacks
238 * \return Returns the value of _stackStartDeg
239 */
241
242 /** Sets the ending degree value for the stacks
243 * \param deg Degree value to which to set _stackEndDeg
244 */
245 virtual GLS_EXPORT void StackEndAngle( float deg );
246
247 /** Gets the ending degree value for the stacks
248 * \return Returns the value of _stackEndDeg
249 */
250 virtual GLS_EXPORT float StackEndAngle();
251
252 /** Sets the starting degree value for the slices
253 * \param deg Degree value to which to set _sliceStartDeg
254 */
255 virtual GLS_EXPORT void SliceStartAngle( float deg );
256
257 /** Gets the starting degree value for the slices
258 * \return Returns the value of _sliceStartDeg
259 */
261
262 /** Sets the ending degree value for the slices
263 * \param deg Degree value to which to set _sliceEndDeg
264 */
265 virtual GLS_EXPORT void SliceEndAngle( float deg );
266
267 /** Gets the ending degree value for the slices
268 * \return Returns the value of _sliceEndDeg
269 */
270 virtual GLS_EXPORT float SliceEndAngle();
271
272 /** Sets the number of horizontal slices
273 * \param slices Desired number of slices to which to set _slices
274 */
275 virtual GLS_EXPORT void Slices( unsigned int slices );
276
277 /** Gets the number of horizontal slices
278 * \return Returns the value of _slices
279 */
280 virtual GLS_EXPORT unsigned int Slices();
281
282 /** Sets the number of vertical stacks
283 * \param stacks Desired number of stacks to which to set _stacks
284 */
285 virtual GLS_EXPORT void Stacks( unsigned int stacks );
286
287 /** Gets the number of vertical stacks
288 * \return Returns the value of _stacks
289 */
290 virtual GLS_EXPORT unsigned int Stacks();
291
292 /** Gets the radii vectors for the sphere
293 * \param r1 First radius vector (width)
294 * \param r2 First radius vector (height)
295 * \param r3 First radius vector (depth)
296 */
297 virtual GLS_EXPORT void GetRadii( Vector& r1, Vector& r2, Vector& r3 );
298
299 /** Sets the radii vectors for the sphere
300 * \param r1 First radius vector (width)
301 * \param r2 First radius vector (height)
302 * \param r3 First radius vector (depth)
303 */
304 virtual GLS_EXPORT void SetRadii( const Vector& r1, const Vector& r2, const Vector& r3 );
305
306#ifndef GLES
309#endif
310};
311
312#define DEF_SPHERE_MAPPING GLS_SPHERE_SPHERICAL_MAP ///< The default texture mapping behavior for a new GlsSphere.
313
314/** Defines metadata for glsSphereMapping_e */
315class DistiAttributeSphereMappingTypeEnum : public DistiAttributeEnum<GlsSphere, glsSphereMapping_e, glsSphereMapping_e>
316{
317public:
318 /// Constructor
319 /// \param frame The object containing the property.
320 /// \param setMethod The set method function pointer.
321 /// \param getMethod The get method function pointer.
322 /// \param name The name of the associated property.
324
326
327 std::string Type() const DISTI_METHOD_OVERRIDE;
328};
329
330} // namespace disti
331
332#endif
Definition: disti_metadata.h:87
Definition: display.h:95
Definition: disti_metadata.h:1021
void(containerClass::* SetMethodType)(glsSphereMapping_e)
Typedef for the set method function pointer.
Definition: disti_metadata.h:1023
glsSphereMapping_e(containerClass::* GetMethodType)()
Typedef for the get method function pointer.
Definition: disti_metadata.h:1024
Definition: gls_sphere.h:316
std::string Type() const override
DistiAttributeSphereMappingTypeEnum(GlsSphere *frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName &name)
Definition: dynamic_array.h:79
Definition: gls_color.h:53
Definition: gls_glo_file.h:1241
Definition: gls_sphere.h:82
void Scale(float px, float py, float pz, Vertex *anchor, int handleBar) override
float _stackEndDeg
0-360, where 0 is the positive x-axis of the sphere.
Definition: gls_sphere.h:98
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
glsSphereMapping_e _textureMappingType
Texture mapping method.
Definition: gls_sphere.h:106
void SetAvailableAttributes(unsigned int value) override
bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override
Vector _radii[3]
Sphere radii.
Definition: gls_sphere.h:91
virtual float SliceStartAngle()
virtual float SliceEndAngle()
void CopyProperties(DisplayObject *src) override
bool _needsResize
True when the sphere needs to be resized.
Definition: gls_sphere.h:104
virtual void SetRadii(const Vector &r1, const Vector &r2, const Vector &r3)
virtual float StackStartAngle()
virtual unsigned int Slices()
virtual float StackEndAngle()
void CopyGeometry(DisplayObject *src) override
void SetValue(int spec, va_list &args) override
void SetResizeRecalculate()
InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
void SetFillColor(const GlsColor &color) override
GlsColor _objectColor
Fill color of object.
Definition: gls_sphere.h:93
unsigned int _stacks
Number of stacks used to draw the sphere.
Definition: gls_sphere.h:100
DisplayObject * CloneObject(bool generateNames=false) override
GlsColor GetFillColor() override
void CalculateTextureCoordinates() override
float _sliceEndDeg
0-180, where 0 is the bottom and 180 the top of the sphere.
Definition: gls_sphere.h:96
void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
void Rotate(const Vector &orig, float angle, const Vector &axis) override
virtual int TextureIndex()
float _stackStartDeg
0-360, where 0 is the positive x-axis of the sphere.
Definition: gls_sphere.h:97
bool _needsRecalculate
True when the sphere vertices need to be recalculated.
Definition: gls_sphere.h:103
unsigned int _slices
Number of slices used to draw the sphere.
Definition: gls_sphere.h:101
glsSphereMapping_e TextureMappingType()
bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector) override
virtual unsigned int Stacks()
void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1) override
void Draw() override
float _sliceStartDeg
0-180, where 0 is the bottom and 180 the top of the sphere.
Definition: gls_sphere.h:95
Definition: vertex.h:84
Definition: vertex.h:419
The disti::DisplayObject class and global enumerations.
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
The Color class: Implements a 4 component RGBA color.
Macros and helper code to determine what subset of C++11/14/17 is available.
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:245
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:487
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:221
A file for all GL Studio files to include.
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:50
Definition: bmpimage.h:46
GLS_Sphere_Initializers
Definition: gls_sphere.h:68
glsSphereMapping_e
Definition: gls_sphere.h:59
@ GLS_SPHERE_CYLINDER_MAP
Definition: gls_sphere.h:61
@ GLS_SPHERE_SPHERICAL_MAP
Definition: gls_sphere.h:60