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 ) 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  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data ) DISTI_METHOD_OVERRIDE;
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  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
150  typedef DisplayObject _BaseClass;
151  typedef DisplayObject BaseClass;
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  GLS_EXPORT GlsSphere( bool newGlsSphere = true );
164 
165  GLS_EXPORT GlsSphere( const GlsSphere& that, const bool generateNames );
166 
167  /** Destroy a GlsSphere object */
168  virtual GLS_EXPORT ~GlsSphere( void );
169 
170  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value ) DISTI_METHOD_OVERRIDE;
171 
172  /** Gets the texture mapping method.
173  * \return Enumerative representation of texture mapping method
174  */
175  GLS_EXPORT glsSphereMapping_e TextureMappingType( void );
176 
177  /* Unhides base class implementation. */
178  using BaseClass::TextureIndex;
179 
180  /** See base class */
181  virtual GLS_EXPORT void TextureIndex( int index ) DISTI_METHOD_OVERRIDE;
182 
183  /** Sets the texture mapping type
184  * \param value The texture mapping value (e.g. cylindrical or spherical)
185  */
186  GLS_EXPORT void TextureMappingType( glsSphereMapping_e value );
187 
188  /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
189  * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
190  * \param p1 Returns a point on the plane
191  * \param p2 Returns a point on the plane
192  * \param p3 Returns a point on the plane
193  * \param planeVector Returns the surface normal of the plane
194  * \return True if 3 coplanar points were found
195  */
196  virtual GLS_EXPORT bool GetPlaneVectorPoints( Vertex& p1, Vertex& p2, Vertex& p3, Vertex& planeVector ) DISTI_METHOD_OVERRIDE;
197 
198  /* See base class */
199  virtual GLS_EXPORT void CalculateTextureCoordinates( void ) DISTI_METHOD_OVERRIDE;
200 
201  /* See base class */
202  virtual GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 ) DISTI_METHOD_OVERRIDE;
203 
204  /* See base class */
205  virtual GLS_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
206 
207  /* See base class */
208  virtual GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
209 
210  /* Unhides base class implementation. */
211  using BaseClass::Scale;
212 
213  /* See base class */
214  virtual GLS_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar ) DISTI_METHOD_OVERRIDE;
215 
216  /* Usually copies the attributes except for geometry attributes from one object to another.
217  * However, since the GlsSphere's geometry defines its properties, its geometry is copied.
218  * Used by the undo mechanism to undo most attribute change operations.
219  * \param src The object to copy properties from */
220  virtual GLS_EXPORT void CopyProperties( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
221 
222  /* See base class */
223  virtual GLS_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
224 
225  /* See base class */
226  virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
227 
228  /* Unhides base class implementation. */
229  using BaseClass::Rotate;
230 
231  /* See base class */
232  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
233 
234  /* Unhides base class implementation. */
235  using BaseClass::SetFillColor;
236 
237  /* See base class */
238  virtual GLS_EXPORT void SetFillColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
239 
240  /* Unhides base class implementation. */
241  using BaseClass::GetFillColor;
242 
243  /* See base class */
244  virtual GLS_EXPORT GlsColor GetFillColor( void ) DISTI_METHOD_OVERRIDE;
245 
246  /** Sets the starting degree value for the stacks
247  * \param deg Degree value to which to set _stackStartDeg
248  */
249  virtual GLS_EXPORT void StackStartAngle( float deg );
250 
251  /** Gets the starting degree value for the stacks
252  * \return Returns the value of _stackStartDeg
253  */
254  virtual GLS_EXPORT float StackStartAngle();
255 
256  /** Sets the ending degree value for the stacks
257  * \param deg Degree value to which to set _stackEndDeg
258  */
259  virtual GLS_EXPORT void StackEndAngle( float deg );
260 
261  /** Gets the ending degree value for the stacks
262  * \return Returns the value of _stackEndDeg
263  */
264  virtual GLS_EXPORT float StackEndAngle();
265 
266  /** Sets the starting degree value for the slices
267  * \param deg Degree value to which to set _sliceStartDeg
268  */
269  virtual GLS_EXPORT void SliceStartAngle( float deg );
270 
271  /** Gets the starting degree value for the slices
272  * \return Returns the value of _sliceStartDeg
273  */
274  virtual GLS_EXPORT float SliceStartAngle();
275 
276  /** Sets the ending degree value for the slices
277  * \param deg Degree value to which to set _sliceEndDeg
278  */
279  virtual GLS_EXPORT void SliceEndAngle( float deg );
280 
281  /** Gets the ending degree value for the slices
282  * \return Returns the value of _sliceEndDeg
283  */
284  virtual GLS_EXPORT float SliceEndAngle();
285 
286  /** Sets the number of horizontal slices
287  * \param slices Desired number of slices to which to set _slices
288  */
289  virtual GLS_EXPORT void Slices( unsigned int slices );
290 
291  /** Gets the number of horizontal slices
292  * \return Returns the value of _slices
293  */
294  virtual GLS_EXPORT unsigned int Slices();
295 
296  /** Sets the number of vertical stacks
297  * \param stacks Desired number of stacks to which to set _stacks
298  */
299  virtual GLS_EXPORT void Stacks( unsigned int stacks );
300 
301  /** Gets the number of vertical stacks
302  * \return Returns the value of _stacks
303  */
304  virtual GLS_EXPORT unsigned int Stacks();
305 
306  /** Gets the radii vectors for the sphere
307  * \param r1 First radius vector (width)
308  * \param r2 First radius vector (height)
309  * \param r3 First radius vector (depth)
310  */
311  virtual GLS_EXPORT void GetRadii( Vector& r1, Vector& r2, Vector& r3 );
312 
313  /** Sets the radii vectors for the sphere
314  * \param r1 First radius vector (width)
315  * \param r2 First radius vector (height)
316  * \param r3 First radius vector (depth)
317  */
318  virtual GLS_EXPORT void SetRadii( const Vector& r1, const Vector& r2, const Vector& r3 );
319 
320 #ifndef GLES
321  /* See base class */
322  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
323 
324  /* See base class */
325  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
326 #endif
327 };
328 
329 #define DEF_SPHERE_MAPPING GLS_SPHERE_SPHERICAL_MAP
330 
331 /** Defines metadata for glsSphereMapping_e */
332 class DistiAttributeSphereMappingTypeEnum : public DistiAttributeEnum<GlsSphere, glsSphereMapping_e, glsSphereMapping_e>
333 {
334 public:
335  GLS_EXPORT DistiAttributeSphereMappingTypeEnum( GlsSphere* frame, SetMethodType setMethod, GetMethodType getMethod, const AttributeName& name );
336  virtual GLS_EXPORT ~DistiAttributeSphereMappingTypeEnum();
337 };
338 
339 } // namespace disti
340 
341 #endif
virtual float StackStartAngle()
Definition: vertex.h:409
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
glsSphereMapping_e
Definition: gls_sphere.h:59
virtual float SliceStartAngle()
virtual unsigned int Stacks()
Definition: dynamic_array.h:66
virtual void CalculateTextureCoordinates(void) override
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
virtual void SetFillColor(const GlsColor &color) override
virtual unsigned int Slices()
glsSphereMapping_e TextureMappingType(void)
virtual void CopyProperties(DisplayObject *src) override
Definition: display.h:98
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) override
glsSphereMapping_e _textureMappingType
Definition: gls_sphere.h:105
virtual void CopyGeometry(DisplayObject *src) override
virtual DisplayObject * CloneObject(bool generateNames=false) override
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:988
The disti::DisplayObject class and global enumerations.
virtual void SetAvailableAttributes(unsigned int value) override
float _sliceStartDeg
Definition: gls_sphere.h:96
Definition: disti_metadata.h:894
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) override
virtual int TextureIndex(void)
virtual void Draw(void) override
void SetResizeRecalculate()
void Recalculate(void)
GLS_Sphere_Initializers
Definition: gls_sphere.h:68
Definition: gls_color.h:53
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1) override
Definition: gls_sphere.h:332
GlsColor _objectColor
Definition: gls_sphere.h:94
bool _needsResize
Definition: gls_sphere.h:103
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector) override
virtual GlsColor GetFillColor(void) override
virtual void SetValue(int spec, va_list &args) override
float _stackStartDeg
Definition: gls_sphere.h:97
Definition: vertex.h:84
Definition: gls_sphere.h:61
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) override
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
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.
bool _needsRecalculate
Definition: gls_sphere.h:102
void Resize(void)
Definition: gls_sphere.h:62
Definition: disti_metadata.h:85
Definition: bmpimage.h:46
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar) override
virtual float SliceEndAngle()
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) override