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
50 #define DEF_SPHERE_SLICES 10
51 #define DEF_SPHERE_SLICE_START 0.0f
52 #define DEF_SPHERE_SLICE_END 360.0f
53 #define DEF_SPHERE_STACK_START 0.0f
54 #define DEF_SPHERE_STACK_END 180.0f
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 */
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
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, _sliceEndDeg; /** 0-180, where 0 is the bottom and 180 the top of the sphere */
97  float _stackStartDeg, _stackEndDeg; /** 0-360, where 0 is the positive x-axis of the sphere */
98 
99  unsigned int _stacks, /** Number of stacks used to draw the sphere */
100  _slices; /** Number of slices used to draw the sphere */
101 
102  bool _needsRecalculate; /** True when the sphere vertices need to be recalculated */
103  bool _needsResize; /** True when the sphere needs to be resized */
104 
105  glsSphereMapping_e _textureMappingType; /** Texture mapping method */
106 
107  /** Sets the resize and recalculate flags, causing the sphere to be resized and recalculated
108  * the next time the sphere draws
109  */
110  GLS_EXPORT void SetResizeRecalculate();
111 
112  /** Recalculates the sphere vertices values */
113  GLS_EXPORT void Recalculate( void );
114 
115  /** Reallocates the vertices of the sphere */
116  GLS_EXPORT void Resize( void );
117 
118  /* See base class */
119  virtual GLS_EXPORT void SetValue( int spec, va_list& args );
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  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
126 #endif
127 
128 private:
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 
148 public:
149  typedef DisplayObject _BaseClass;
150 
151  friend class GlsSphereEditor;
152 
153  /** Constructor. Creates a new GlsSphere object at given coordinates.
154  * \param x x-coordinate of new GlsSphere
155  * \param y y-coordinate of new GlsSphere
156  * \param z z-coordinate of new GlsSphere
157  */
158  GLS_EXPORT GlsSphere( float x, float y, float z );
159 
160  /** Allocate a (blank) GlsSphere object */
161  GLS_EXPORT GlsSphere( bool newGlsSphere = true );
162 
163  GLS_EXPORT GlsSphere( const GlsSphere& that, const bool generateNames );
164 
165  /** Destroy a GlsSphere object */
166  virtual GLS_EXPORT ~GlsSphere( void );
167 
168  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value );
169 
170  /** Gets the texture mapping method.
171  * \return Enumerative representation of texture mapping method
172  */
173  GLS_EXPORT glsSphereMapping_e TextureMappingType( void );
174 
175  /* Unhides base class implementation. */
177 
178  /** See base class */
179  virtual GLS_EXPORT void TextureIndex( int index );
180 
181  /** Sets the texture mapping type
182  * \param value The texture mapping value (e.g. cylindrical or spherical)
183  */
184  GLS_EXPORT void TextureMappingType( glsSphereMapping_e value );
185 
186  /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
187  * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
188  * \param p1 Returns a point on the plane
189  * \param p2 Returns a point on the plane
190  * \param p3 Returns a point on the plane
191  * \param planeVector Returns the surface normal of the plane
192  * \return True if 3 coplanar points were found
193  */
194  virtual GLS_EXPORT bool GetPlaneVectorPoints( Vertex& p1, Vertex& p2, Vertex& p3, Vertex& planeVector );
195 
196  /* See base class */
197  virtual GLS_EXPORT void CalculateTextureCoordinates( void );
198 
199  /* See base class */
200  virtual GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 );
201 
202  /* See base class */
203  virtual GLS_EXPORT void Draw( void );
204 
205  /* See base class */
206  virtual GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
207 
208  /* Unhides base class implementation. */
209  using _BaseClass::Scale;
210 
211  /* See base class */
212  virtual GLS_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar );
213 
214  /* Usually copies the attributes except for geometry attributes from one object to another.
215  * However, since the GlsSphere's geometry defines its properties, its geometry is copied.
216  * Used by the undo mechanism to undo most attribute change operations.
217  * \param src The object to copy properties from */
218  virtual GLS_EXPORT void CopyProperties( DisplayObject* src );
219 
220  /* See base class */
221  virtual GLS_EXPORT void CopyGeometry( DisplayObject* src );
222 
223  /* See base class */
224  virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false );
225 
226  /* Unhides base class implementation. */
227  using _BaseClass::Rotate;
228 
229  /* See base class */
230  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
231 
232  /* Unhides base class implementation. */
234 
235  /* See base class */
236  virtual GLS_EXPORT void SetFillColor( const GlsColor& color );
237 
238  /* Unhides base class implementation. */
240 
241  /* See base class */
242  virtual GLS_EXPORT GlsColor GetFillColor( void );
243 
244  /** Sets the starting degree value for the stacks
245  * \param deg Degree value to which to set _stackStartDeg
246  */
247  virtual GLS_EXPORT void StackStartAngle( float deg );
248 
249  /** Gets the starting degree value for the stacks
250  * \return Returns the value of _stackStartDeg
251  */
252  virtual GLS_EXPORT float StackStartAngle();
253 
254  /** Sets the ending degree value for the stacks
255  * \param deg Degree value to which to set _stackEndDeg
256  */
257  virtual GLS_EXPORT void StackEndAngle( float deg );
258 
259  /** Gets the ending degree value for the stacks
260  * \return Returns the value of _stackEndDeg
261  */
262  virtual GLS_EXPORT float StackEndAngle();
263 
264  /** Sets the starting degree value for the slices
265  * \param deg Degree value to which to set _sliceStartDeg
266  */
267  virtual GLS_EXPORT void SliceStartAngle( float deg );
268 
269  /** Gets the starting degree value for the slices
270  * \return Returns the value of _sliceStartDeg
271  */
272  virtual GLS_EXPORT float SliceStartAngle();
273 
274  /** Sets the ending degree value for the slices
275  * \param deg Degree value to which to set _sliceEndDeg
276  */
277  virtual GLS_EXPORT void SliceEndAngle( float deg );
278 
279  /** Gets the ending degree value for the slices
280  * \return Returns the value of _sliceEndDeg
281  */
282  virtual GLS_EXPORT float SliceEndAngle();
283 
284  /** Sets the number of horizontal slices
285  * \param slices Desired number of slices to which to set _slices
286  */
287  virtual GLS_EXPORT void Slices( unsigned int slices );
288 
289  /** Gets the number of horizontal slices
290  * \return Returns the value of _slices
291  */
292  virtual GLS_EXPORT unsigned int Slices();
293 
294  /** Sets the number of vertical stacks
295  * \param stacks Desired number of stacks to which to set _stacks
296  */
297  virtual GLS_EXPORT void Stacks( unsigned int stacks );
298 
299  /** Gets the number of vertical stacks
300  * \return Returns the value of _stacks
301  */
302  virtual GLS_EXPORT unsigned int Stacks();
303 
304  /** Gets the radii vectors for the sphere
305  * \param r1 First radius vector (width)
306  * \param r2 First radius vector (height)
307  * \param r3 First radius vector (depth)
308  */
309  virtual GLS_EXPORT void GetRadii( Vector& r1, Vector& r2, Vector& r3 );
310 
311  /** Sets the radii vectors for the sphere
312  * \param r1 First radius vector (width)
313  * \param r2 First radius vector (height)
314  * \param r3 First radius vector (depth)
315  */
316  virtual GLS_EXPORT void SetRadii( const Vector& r1, const Vector& r2, const Vector& r3 );
317 
318 #ifndef GLES
319  /* See base class */
320  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
321 
322  /* See base class */
323  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
324 #endif
325 };
326 
327 #define DEF_SPHERE_MAPPING GLS_SPHERE_SPHERICAL_MAP
328 
329 /** Defines metadata for glsSphereMapping_e */
330 class DistiAttributeSphereMappingTypeEnum : public DistiAttributeEnum<GlsSphere, glsSphereMapping_e, glsSphereMapping_e>
331 {
332 public:
333  GLS_EXPORT DistiAttributeSphereMappingTypeEnum( GlsSphere* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name );
334  virtual GLS_EXPORT ~DistiAttributeSphereMappingTypeEnum();
335 };
336 
337 } // namespace disti
338 
339 #endif
virtual void SetValue(int spec, va_list &args)
virtual float StackStartAngle()
Definition: vertex.h:408
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
glsSphereMapping_e
Definition: gls_sphere.h:59
virtual float SliceStartAngle()
virtual unsigned int Stacks()
Definition: dynamic_array.h:62
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
virtual unsigned int Slices()
glsSphereMapping_e TextureMappingType(void)
Definition: display.h:97
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector)
glsSphereMapping_e _textureMappingType
Definition: gls_sphere.h:105
virtual void SetFillColor(const GlsColor &color)
virtual void Draw(void)
virtual GlsColor GetFillColor(void)
The Color class: Implements a 4 component RGBA color.
virtual float StackEndAngle()
virtual void SetRadii(const Vector &r1, const Vector &r2, const Vector &r3)
unsigned int _stacks
Definition: gls_sphere.h:99
A file for all GL Studio files to include.
Definition: gls_glo_file.h:835
The disti::DisplayObject class and global enumerations.
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1)
float _sliceStartDeg
Definition: gls_sphere.h:96
virtual void SetAvailableAttributes(unsigned int value)
virtual GlsColor GetFillColor(void)
Definition: disti_metadata.h:898
virtual int TextureIndex(void)
virtual DisplayObject * CloneObject(bool generateNames=false)
void SetResizeRecalculate()
void Recalculate(void)
GLS_Sphere_Initializers
Definition: gls_sphere.h:68
Definition: gls_color.h:53
virtual void Rotate(float angle, int axis=Z_AXIS)
Definition: gls_sphere.h:330
GlsColor _objectColor
Definition: gls_sphere.h:94
virtual void CalculateTextureCoordinates(void)
bool _needsResize
Definition: gls_sphere.h:103
virtual void CopyGeometry(DisplayObject *src)
float _stackStartDeg
Definition: gls_sphere.h:97
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
void Scale(int handleBar, float px, float py, Vertex *anchor=NULL)
Definition: display.h:1111
Definition: vertex.h:83
Definition: gls_sphere.h:61
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
virtual void CopyProperties(DisplayObject *src)
unsigned int _slices
Definition: gls_sphere.h:99
Definition: gls_sphere.h:82
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual ~GlsSphere(void)
bool _needsRecalculate
Definition: gls_sphere.h:102
void Resize(void)
Definition: gls_sphere.h:62
Definition: disti_metadata.h:79
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
Definition: bmpimage.h:46
void SetFillColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: display.h:663
virtual float SliceEndAngle()
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)