| GL Studio C++ Runtime API

gls_sphere.h
Go to the documentation of this file.
1/*! \file
2 \brief The disti::GlsSphere class.
3
4 \par Copyright Information
5
6 Copyright (c) 2017 by The DiSTI Corporation.<br>
7 11301 Corporate Blvd; Suite 100<br>
8 Orlando, Florida 32817<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*/
40#ifndef _GLS_SPHERE_H
41#define _GLS_SPHERE_H
42
43#include "display.h"
44#include "dynamic_array.h"
45#include "gls_color.h"
46#include "gls_cpp_lang_support.h"
47#include "gls_include.h"
48
49#define DEF_SPHERE_STACKS 10 ///< The default number of stacks for a new GlsSphere.
50#define DEF_SPHERE_SLICES 10 ///< The default number of slices for a new GlsSphere.
51#define DEF_SPHERE_SLICE_START 0.0f ///< The default slice start angle in degrees for a new GlsSphere.
52#define DEF_SPHERE_SLICE_END 360.0f ///< The default slice end angle in degrees for a new GlsSphere.
53#define DEF_SPHERE_STACK_START 0.0f ///< The default stack start angle in degrees for a new GlsSphere.
54#define DEF_SPHERE_STACK_END 180.0f ///< The default stack end angle in degrees for a new GlsSphere.
55
56 namespace disti
57{
58/** gls Sphere Mapping */
59 typedef enum
60{
61 GLS_SPHERE_SPHERICAL_MAP, /**< Spherical texture map */
62 GLS_SPHERE_CYLINDER_MAP /**< Cylindrical texture map */
63} glsSphereMapping_e;
64
65/**
66 Sphere Initializers
67*/
68 typedef enum
69{
70 GLS_SPHERE_MAPPING = GLS_LAST_INITIALIZER + 1,
71 GLS_SPHERE_COLOR,
72 GLS_SPHERE_STACKS,
73 GLS_SPHERE_SLICES,
74 GLS_SPHERE_SLICE_START,
75 GLS_SPHERE_SLICE_END,
76 GLS_SPHERE_STACK_START,
77 GLS_SPHERE_STACK_END,
78 GLS_SPHERE_RADII
79} GLS_Sphere_Initializers;
80
81/** The Sphere class. Implements Sphere primitive */
82 class GlsSphere : public DisplayObject
83{
84 private:
85 /** Factors out common code shared by the various glsSphere constructors */
86 void CommonConstructorInit();
87 /** Assignment operator not implemented. Use CloneObject() or the copy constructor instead. */
88 GlsSphere& operator=( const GlsSphere& ) DISTI_SPECIAL_MEM_FUN_DELETE;
89 GlsSphere( const GlsSphere& ) DISTI_SPECIAL_MEM_FUN_DELETE;
90
91 protected:
92 Vector _radii[ 3 ]; ///< Sphere radii
93
94 GlsColor _objectColor; ///< Fill color of object.
95
96 float _sliceStartDeg; ///< 0-180, where 0 is the bottom and 180 the top of the sphere.
97 float _sliceEndDeg; ///< 0-180, where 0 is the bottom and 180 the top of the sphere.
98 float _stackStartDeg; ///< 0-360, where 0 is the positive x-axis of the sphere.
99 float _stackEndDeg; ///< 0-360, where 0 is the positive x-axis of the sphere.
100
101 unsigned int _stacks; ///< Number of stacks used to draw the sphere.
102 unsigned int _slices; ///< Number of slices used to draw the sphere.
103
104 bool _needsRecalculate; ///< True when the sphere vertices need to be recalculated.
105 bool _needsResize; ///< True when the sphere needs to be resized.
106
107 glsSphereMapping_e _textureMappingType; ///< Texture mapping method.
108
109 /** Sets the resize and recalculate flags, causing the sphere to be resized and recalculated
110 * the next time the sphere draws
111 */
112 GLS_EXPORT void SetResizeRecalculate();
113
114 /** Recalculates the sphere vertices values */
115 GLS_EXPORT void Recalculate();
116
117 /** Reallocates the vertices of the sphere */
118 GLS_EXPORT void Resize();
119
120 virtual GLS_EXPORT void SetValue( int spec, va_list& args ) DISTI_METHOD_OVERRIDE;
121
122#ifdef GLES
123 /** Set a single attribute from the GLO file.
124 * \param data The attribute to set and its associated data.
125 */
126 virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
127#endif
128
129 private:
130 /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
131 * but does not guarantee that the collision point returned by Hit is the closest collision point
132 * to the observer
133 * \param point The logical coordinate of the click, relative to the object
134 * \param directionVector The direction of the pick vector
135 * \param collisionPoint Set to the point on the object hit by directionVector
136 * \return boolean indicating if the object was hit by the mouse
137 */
138 bool FirstHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
139
140 /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
141 * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
142 * \param point The logical coordinate of the click, relative to the object
143 * \param directionVector The direction of the pick vector
144 * \param collisionPoint Set to the point on the object hit by directionVector
145 * \return boolean indicating if the object was hit by the mouse
146 */
147 bool BestHit( const Vector& point, const Vector& directionVector, Vector* collisionPoint );
148
149 public:
150 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
151 typedef DisplayObject _BaseClass; ///< Deprecated typedef for the base class.
152 typedef DisplayObject BaseClass; ///< Typedef for the base class.
153
154 friend class GlsSphereEditor;
155
156 /** Constructor. Creates a new GlsSphere object at given coordinates.
157 * \param x x-coordinate of new GlsSphere
158 * \param y y-coordinate of new GlsSphere
159 * \param z z-coordinate of new GlsSphere
160 */
161 GLS_EXPORT GlsSphere( float x, float y, float z );
162
163 /// Allocate a (blank) GlsSphere object.
164 /// \param newGlsSphere Unused, kept for backward compatibility.
165 GLS_EXPORT GlsSphere( bool newGlsSphere = true );
166
167 /// Copy constructor
168 /// \param that The object to copy from.
169 /// \param generateNames Whether or not to generate an instance name for this object.
170 GLS_EXPORT GlsSphere( const GlsSphere& that, const bool generateNames );
171
172 /** Destroy a GlsSphere object */
173 virtual GLS_EXPORT ~GlsSphere();
174
175 virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
176
177 /** Gets the texture mapping method.
178 * \return Enumerative representation of texture mapping method
179 */
180 GLS_EXPORT glsSphereMapping_e TextureMappingType();
181
182 /* Unhides base class implementation. */
183 using BaseClass::TextureIndex;
184 virtual GLS_EXPORT void TextureIndex( int index ) DISTI_METHOD_OVERRIDE;
185
186 /** Sets the texture mapping type
187 * \param value The texture mapping value (e.g. cylindrical or spherical)
188 */
189 GLS_EXPORT void TextureMappingType( glsSphereMapping_e value );
190
191 /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
192 * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
193 * \param p1 Returns a point on the plane
194 * \param p2 Returns a point on the plane
195 * \param p3 Returns a point on the plane
196 * \param planeVector Returns the surface normal of the plane
197 * \return True if 3 coplanar points were found
198 */
199 virtual GLS_EXPORT bool GetPlaneVectorPoints( Vertex& p1, Vertex& p2, Vertex& p3, Vertex& planeVector ) DISTI_METHOD_OVERRIDE;
200
201 virtual GLS_EXPORT void CalculateTextureCoordinates() DISTI_METHOD_OVERRIDE;
202 virtual GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 ) DISTI_METHOD_OVERRIDE;
203 virtual GLS_EXPORT void Draw() DISTI_METHOD_OVERRIDE;
204 virtual GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
205
206 /* Unhides base class implementation. */
207 using BaseClass::Scale;
208 virtual GLS_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar ) DISTI_METHOD_OVERRIDE;
209
210 /* Usually copies the attributes except for geometry attributes from one object to another.
211 * However, since the GlsSphere's geometry defines its properties, its geometry is copied.
212 * Used by the undo mechanism to undo most attribute change operations.
213 * \param src The object to copy properties from */
214 virtual GLS_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
215
216 virtual GLS_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
217 virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
218
219 /* Unhides base class implementation. */
220 using BaseClass::Rotate;
221 virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
222
223 /* Unhides base class implementation. */
224 using BaseClass::SetFillColor;
225
226 virtual GLS_EXPORT void SetFillColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
227
228 /* Unhides base class implementation. */
229 using BaseClass::GetFillColor;
230
231 virtual GLS_EXPORT GlsColor GetFillColor() DISTI_METHOD_OVERRIDE;
232
233 /** Sets the starting degree value for the stacks
234 * \param deg Degree value to which to set _stackStartDeg
235 */
236 virtual GLS_EXPORT void StackStartAngle( float deg );
237
238 /** Gets the starting degree value for the stacks
239 * \return Returns the value of _stackStartDeg
240 */
241 virtual GLS_EXPORT float StackStartAngle();
242
243 /** Sets the ending degree value for the stacks
244 * \param deg Degree value to which to set _stackEndDeg
245 */
246 virtual GLS_EXPORT void StackEndAngle( float deg );
247
248 /** Gets the ending degree value for the stacks
249 * \return Returns the value of _stackEndDeg
250 */
251 virtual GLS_EXPORT float StackEndAngle();
252
253 /** Sets the starting degree value for the slices
254 * \param deg Degree value to which to set _sliceStartDeg
255 */
256 virtual GLS_EXPORT void SliceStartAngle( float deg );
257
258 /** Gets the starting degree value for the slices
259 * \return Returns the value of _sliceStartDeg
260 */
261 virtual GLS_EXPORT float SliceStartAngle();
262
263 /** Sets the ending degree value for the slices
264 * \param deg Degree value to which to set _sliceEndDeg
265 */
266 virtual GLS_EXPORT void SliceEndAngle( float deg );
267
268 /** Gets the ending degree value for the slices
269 * \return Returns the value of _sliceEndDeg
270 */
271 virtual GLS_EXPORT float SliceEndAngle();
272
273 /** Sets the number of horizontal slices
274 * \param slices Desired number of slices to which to set _slices
275 */
276 virtual GLS_EXPORT void Slices( unsigned int slices );
277
278 /** Gets the number of horizontal slices
279 * \return Returns the value of _slices
280 */
281 virtual GLS_EXPORT unsigned int Slices();
282
283 /** Sets the number of vertical stacks
284 * \param stacks Desired number of stacks to which to set _stacks
285 */
286 virtual GLS_EXPORT void Stacks( unsigned int stacks );
287
288 /** Gets the number of vertical stacks
289 * \return Returns the value of _stacks
290 */
291 virtual GLS_EXPORT unsigned int Stacks();
292
293 /** Gets the radii vectors for the sphere
294 * \param r1 First radius vector (width)
295 * \param r2 First radius vector (height)
296 * \param r3 First radius vector (depth)
297 */
298 virtual GLS_EXPORT void GetRadii( Vector& r1, Vector& r2, Vector& r3 );
299
300 /** Sets the radii vectors for the sphere
301 * \param r1 First radius vector (width)
302 * \param r2 First radius vector (height)
303 * \param r3 First radius vector (depth)
304 */
305 virtual GLS_EXPORT void SetRadii( const Vector& r1, const Vector& r2, const Vector& r3 );
306
307#ifndef GLES
308 virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
309 virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
310#endif
311};
312
313#define DEF_SPHERE_MAPPING GLS_SPHERE_SPHERICAL_MAP ///< The default texture mapping behavior for a new GlsSphere.
314
315/** Defines metadata for glsSphereMapping_e */
316 class DistiAttributeSphereMappingTypeEnum : public DistiAttributeEnum<GlsSphere, glsSphereMapping_e, glsSphereMapping_e>
317{
318 public:
319 /// Constructor
320 /// \param frame The object containing the property.
321 /// \param setMethod The set method function pointer.
322 /// \param getMethod The get method function pointer.
323 /// \param name The name of the associated property.
324 GLS_EXPORT DistiAttributeSphereMappingTypeEnum( GlsSphere* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name );
325
326 virtual GLS_EXPORT ~DistiAttributeSphereMappingTypeEnum();
327
328 std::string Type() const DISTI_METHOD_OVERRIDE;
329};
330
331} // namespace disti
332
333#endif
disti::AttributeName
Definition: disti_metadata.h:87
disti::DisplayObject
Definition: display.h:96
disti::DistiAttributeEnum
Definition: disti_metadata.h:1021
disti::DistiAttributeEnum< GlsSphere, glsSphereMapping_e, glsSphereMapping_e >::SetMethodType
void(containerClass::* SetMethodType)(glsSphereMapping_e)
Typedef for the set method function pointer.
Definition: disti_metadata.h:1023
disti::DistiAttributeEnum< GlsSphere, glsSphereMapping_e, glsSphereMapping_e >::GetMethodType
glsSphereMapping_e(containerClass::* GetMethodType)()
Typedef for the get method function pointer.
Definition: disti_metadata.h:1024
disti::DistiAttributeSphereMappingTypeEnum
Definition: gls_sphere.h:317
disti::DistiAttributeSphereMappingTypeEnum::Type
std::string Type() const override
disti::DistiAttributeSphereMappingTypeEnum::DistiAttributeSphereMappingTypeEnum
DistiAttributeSphereMappingTypeEnum(GlsSphere *frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName &name)
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GlsColor
Definition: gls_color.h:54
disti::GlsGloFileAttribute
Definition: gls_glo_file.h:1243
disti::GlsSphere
Definition: gls_sphere.h:83
disti::GlsSphere::Recalculate
void Recalculate()
disti::GlsSphere::Resize
void Resize()
disti::GlsSphere::_stackEndDeg
float _stackEndDeg
0-360, where 0 is the positive x-axis of the sphere.
Definition: gls_sphere.h:99
disti::GlsSphere::GetRadii
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
disti::GlsSphere::_textureMappingType
glsSphereMapping_e _textureMappingType
Texture mapping method.
Definition: gls_sphere.h:107
disti::GlsSphere::CloneObject
virtual DisplayObject * CloneObject(bool generateNames=false) override
disti::GlsSphere::SetFromGloData
virtual void SetFromGloData(GlsGloFileAttribute &data) override
disti::GlsSphere::_radii
Vector _radii[3]
Sphere radii.
Definition: gls_sphere.h:92
disti::GlsSphere::SliceStartAngle
virtual float SliceStartAngle()
disti::GlsSphere::SliceEndAngle
virtual float SliceEndAngle()
disti::GlsSphere::_needsResize
bool _needsResize
True when the sphere needs to be resized.
Definition: gls_sphere.h:105
disti::GlsSphere::SetRadii
virtual void SetRadii(const Vector &r1, const Vector &r2, const Vector &r3)
disti::GlsSphere::StackStartAngle
virtual float StackStartAngle()
disti::GlsSphere::Rotate
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) override
disti::GlsSphere::Slices
virtual unsigned int Slices()
disti::GlsSphere::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int value) override
disti::GlsSphere::GetPlaneVectorPoints
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector) override
disti::GlsSphere::StackEndAngle
virtual float StackEndAngle()
disti::GlsSphere::SetValue
virtual void SetValue(int spec, va_list &args) override
disti::GlsSphere::GetFillColor
virtual GlsColor GetFillColor() override
disti::GlsSphere::SetResizeRecalculate
void SetResizeRecalculate()
disti::GlsSphere::CalculateTextureCoordinates
virtual void CalculateTextureCoordinates() override
disti::GlsSphere::SetFillColor
virtual void SetFillColor(const GlsColor &color) override
disti::GlsSphere::_objectColor
GlsColor _objectColor
Fill color of object.
Definition: gls_sphere.h:94
disti::GlsSphere::_stacks
unsigned int _stacks
Number of stacks used to draw the sphere.
Definition: gls_sphere.h:101
disti::GlsSphere::GetExtents
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1) override
disti::GlsSphere::Hit
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override
disti::GlsSphere::CopyProperties
virtual void CopyProperties(DisplayObject *src) override
disti::GlsSphere::Scale
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar) override
disti::GlsSphere::Draw
virtual void Draw() override
disti::GlsSphere::_sliceEndDeg
float _sliceEndDeg
0-180, where 0 is the bottom and 180 the top of the sphere.
Definition: gls_sphere.h:97
disti::GlsSphere::TextureIndex
virtual int TextureIndex()
disti::GlsSphere::_stackStartDeg
float _stackStartDeg
0-360, where 0 is the positive x-axis of the sphere.
Definition: gls_sphere.h:98
disti::GlsSphere::_needsRecalculate
bool _needsRecalculate
True when the sphere vertices need to be recalculated.
Definition: gls_sphere.h:104
disti::GlsSphere::CopyGeometry
virtual void CopyGeometry(DisplayObject *src) override
disti::GlsSphere::_slices
unsigned int _slices
Number of slices used to draw the sphere.
Definition: gls_sphere.h:102
disti::GlsSphere::TextureMappingType
glsSphereMapping_e TextureMappingType()
disti::GlsSphere::Stacks
virtual unsigned int Stacks()
disti::GlsSphere::_sliceStartDeg
float _sliceStartDeg
0-180, where 0 is the bottom and 180 the top of the sphere.
Definition: gls_sphere.h:96
disti::VertexNoColor
Definition: vertex.h:85
disti::Vertex
Definition: vertex.h:420
display.h
The disti::DisplayObject class and global enumerations.
dynamic_array.h
The disti::DynamicArray class. A templated array of objects capable of dynamically growing.
gls_color.h
The Color class: Implements a 4 component RGBA color.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#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:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
gls_include.h
A file for all GL Studio files to include.
GLS_EXPORT
#define GLS_EXPORT
Macro denoting which functions should be visible from the runtime library.
Definition: gls_include.h:52
disti
Definition: bmpimage.h:47
disti::GLS_Sphere_Initializers
GLS_Sphere_Initializers
Definition: gls_sphere.h:69
disti::glsSphereMapping_e
glsSphereMapping_e
Definition: gls_sphere.h:60
disti::GLS_SPHERE_CYLINDER_MAP
@ GLS_SPHERE_CYLINDER_MAP
Definition: gls_sphere.h:62
disti::GLS_SPHERE_SPHERICAL_MAP
@ GLS_SPHERE_SPHERICAL_MAP
Definition: gls_sphere.h:61