GL Studio 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) 2015 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 "gls_color.h"
45 #include "gls_include.h"
46 #include "dynamic_array.h"
47 #include "gls_cpp_lang_support.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 
59 /** gls Sphere Mapping */
60 typedef enum
61 {
62  GLS_SPHERE_SPHERICAL_MAP, /**< Spherical texture map */
63  GLS_SPHERE_CYLINDER_MAP /**< Cylindrical texture map */
65 
66 /**
67  Sphere Initializers
68 */
69 typedef enum
70 {
71  GLS_SPHERE_MAPPING=GLS_LAST_INITIALIZER+1,
72  GLS_SPHERE_COLOR,
73  GLS_SPHERE_STACKS,
74  GLS_SPHERE_SLICES,
75  GLS_SPHERE_SLICE_START,
76  GLS_SPHERE_SLICE_END,
77  GLS_SPHERE_STACK_START,
78  GLS_SPHERE_STACK_END,
79  GLS_SPHERE_RADII
81 
82 /** The Sphere class. Implements Sphere primitive */
83 class GlsSphere : public DisplayObject
84 {
85 private:
86 
87  /** Factors out common code shared by the various glsSphere constructors */
88  void CommonConstructorInit();
89  /** Assignment operator not implemented. Use CloneObject() or the copy constructor instead. */
90  GlsSphere& operator=( const GlsSphere& ) DISTI_SPECIAL_MEM_FUN_DELETE;
91  GlsSphere( const GlsSphere& ) DISTI_SPECIAL_MEM_FUN_DELETE;
92 
93 protected:
94 
95  Vector _radii[3]; /** Sphere radii */
96 
97  glsColor _objectColor; /** Fill color of object */
98 
99  float _sliceStartDeg,_sliceEndDeg; /** 0-180, where 0 is the bottom and 180 the top of the sphere */
100  float _stackStartDeg,_stackEndDeg; /** 0-360, where 0 is the positive x-axis of the sphere */
101 
102  unsigned int _stacks, /** Number of stacks used to draw the sphere */
103  _slices; /** Number of slices used to draw the sphere */
104 
105  bool _needsRecalculate; /** True when the sphere vertices need to be recalculated */
106  bool _needsResize; /** True when the sphere needs to be resized */
107 
108  glsSphereMapping_e _textureMappingType; /** Texture mapping method */
109 
110 
111  /** Sets the resize and recalculate flags, causing the sphere to be resized and recalculated
112  * the next time the sphere draws
113  */
114  GLS_EXPORT void SetResizeRecalculate();
115 
116  /** Recalculates the sphere vertices values */
117  GLS_EXPORT void Recalculate(void);
118 
119  /** Reallocates the vertices of the sphere */
120  GLS_EXPORT void Resize(void);
121 
122  /* See base class */
123  virtual GLS_EXPORT void SetValue(int spec,va_list &args);
124 
125 #ifdef GLES
126  /** Set a single attribute from the GLO file.
127  * \param data The attribute to set and its associated data.
128  */
129  virtual GLS_EXPORT void SetFromGloData(GlsGloFileAttribute &data);
130 #endif
131 
132 private:
133  /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
134  * but does not guarantee that the collision point returned by Hit is the closest collision point
135  * to the observer
136  * \param point The logical coordinate of the click, relative to the object
137  * \param directionVector The direction of the pick vector
138  * \param collisionPoint Set to the point on the object hit by directionVector
139  * \return boolean indicating if the object was hit by the mouse
140  */
141  bool FirstHit(const Vector &point,const Vector& directionVector,Vector *collisionPoint);
142 
143  /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
144  * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
145  * \param point The logical coordinate of the click, relative to the object
146  * \param directionVector The direction of the pick vector
147  * \param collisionPoint Set to the point on the object hit by directionVector
148  * \return boolean indicating if the object was hit by the mouse
149  */
150  bool BestHit(const Vector &point,const Vector& directionVector,Vector *collisionPoint);
151 public:
152  typedef DisplayObject _BaseClass;
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  GLS_EXPORT GlsSphere(bool newGlsSphere = true);
165 
166  GLS_EXPORT GlsSphere( const GlsSphere& that, const bool generateNames );
167 
168  /** Destroy a GlsSphere object */
169  virtual GLS_EXPORT ~GlsSphere(void);
170 
171  virtual GLS_EXPORT void SetAvailableAttributes(unsigned int value);
172 
173  /** Gets the texture mapping method.
174  * \return Enumerative representation of texture mapping method
175  */
176  GLS_EXPORT glsSphereMapping_e TextureMappingType(void);
177 
178  /* Unhides base class implementation. */
180 
181  /** See base class */
182  virtual GLS_EXPORT void TextureIndex(int index);
183 
184  /** Sets the texture mapping type
185  * \param value The texture mapping value (e.g. cylindrical or spherical)
186  */
187  GLS_EXPORT void TextureMappingType(glsSphereMapping_e value);
188 
189  /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
190  * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
191  * \param p1 Returns a point on the plane
192  * \param p2 Returns a point on the plane
193  * \param p3 Returns a point on the plane
194  * \param planeVector Returns the surface normal of the plane
195  * \return True if 3 coplanar points were found
196  */
197  virtual GLS_EXPORT bool GetPlaneVectorPoints(Vertex &p1,Vertex &p2,Vertex &p3,Vertex &planeVector);
198 
199  /* See base class */
200  virtual GLS_EXPORT void CalculateTextureCoordinates(void);
201 
202  /* See base class */
203  virtual GLS_EXPORT void GetExtents(float &x,float &y,float &z,float &x1,float &y1,float &z1);
204 
205  /* See base class */
206  virtual GLS_EXPORT void Draw(void);
207 
208  /* See base class */
209  virtual GLS_EXPORT bool Hit(float x,float y,float z,float scale, const Vector& directionVector,Vector *collisionPoint);
210 
211  /* Unhides base class implementation. */
212  using _BaseClass::Scale;
213 
214  /* See base class */
215  virtual GLS_EXPORT void Scale(float px, float py, float pz, Vertex *anchor, int handleBar);
216 
217  /* Usually copies the attributes except for geometry attributes from one object to another.
218  * However, since the GlsSphere's geometry defines its properties, its geometry is copied.
219  * Used by the undo mechanism to undo most attribute change operations.
220  * \param src The object to copy properties from */
221  virtual GLS_EXPORT void CopyProperties(DisplayObject *src);
222 
223  /* See base class */
224  virtual GLS_EXPORT void CopyGeometry(DisplayObject *src);
225 
226  /* See base class */
227  virtual GLS_EXPORT DisplayObject* CloneObject(bool generateNames = false);
228 
229  /* Unhides base class implementation. */
230  using _BaseClass::Rotate;
231 
232  /* See base class */
233  virtual GLS_EXPORT void Rotate(const Vector &orig,float angle, const Vector &axis);
234 
235  /* Unhides base class implementation. */
237 
238  /* See base class */
239  virtual GLS_EXPORT void SetFillColor(const glsColor &color);
240 
241  /* Unhides base class implementation. */
243 
244  /* See base class */
245  virtual GLS_EXPORT glsColor GetFillColor(void);
246 
247  /** Sets the starting degree value for the stacks
248  * \param deg Degree value to which to set _stackStartDeg
249  */
250  virtual GLS_EXPORT void StackStartAngle(float deg);
251 
252  /** Gets the starting degree value for the stacks
253  * \return Returns the value of _stackStartDeg
254  */
255  virtual GLS_EXPORT float StackStartAngle();
256 
257  /** Sets the ending degree value for the stacks
258  * \param deg Degree value to which to set _stackEndDeg
259  */
260  virtual GLS_EXPORT void StackEndAngle(float deg);
261 
262  /** Gets the ending degree value for the stacks
263  * \return Returns the value of _stackEndDeg
264  */
265  virtual GLS_EXPORT float StackEndAngle();
266 
267  /** Sets the starting degree value for the slices
268  * \param deg Degree value to which to set _sliceStartDeg
269  */
270  virtual GLS_EXPORT void SliceStartAngle(float deg);
271 
272  /** Gets the starting degree value for the slices
273  * \return Returns the value of _sliceStartDeg
274  */
275  virtual GLS_EXPORT float SliceStartAngle();
276 
277  /** Sets the ending degree value for the slices
278  * \param deg Degree value to which to set _sliceEndDeg
279  */
280  virtual GLS_EXPORT void SliceEndAngle(float deg);
281 
282  /** Gets the ending degree value for the slices
283  * \return Returns the value of _sliceEndDeg
284  */
285  virtual GLS_EXPORT float SliceEndAngle();
286 
287  /** Sets the number of horizontal slices
288  * \param slices Desired number of slices to which to set _slices
289  */
290  virtual GLS_EXPORT void Slices(unsigned int slices);
291 
292  /** Gets the number of horizontal slices
293  * \return Returns the value of _slices
294  */
295  virtual GLS_EXPORT unsigned int Slices();
296 
297  /** Sets the number of vertical stacks
298  * \param stacks Desired number of stacks to which to set _stacks
299  */
300  virtual GLS_EXPORT void Stacks(unsigned int stacks);
301 
302  /** Gets the number of vertical stacks
303  * \return Returns the value of _stacks
304  */
305  virtual GLS_EXPORT unsigned int Stacks();
306 
307  /** Gets the radii vectors for the sphere
308  * \param r1 First radius vector (width)
309  * \param r2 First radius vector (height)
310  * \param r3 First radius vector (depth)
311  */
312  virtual GLS_EXPORT void GetRadii(Vector &r1,Vector &r2,Vector &r3);
313 
314  /** Sets the radii vectors for the sphere
315  * \param r1 First radius vector (width)
316  * \param r2 First radius vector (height)
317  * \param r3 First radius vector (depth)
318  */
319  virtual GLS_EXPORT void SetRadii(const Vector &r1,const Vector &r2,const Vector &r3);
320 
321 #ifndef GLES
322  /* See base class */
323  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription(InterfaceListType* addToThisList= NULL );
324 
325  /* See base class */
326  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree(InterfaceListType* array);
327 #endif
328 };
329 
330 #define DEF_SPHERE_MAPPING GLS_SPHERE_SPHERICAL_MAP
331 
332 /** Defines metadata for glsSphereMapping_e */
333 class DistiAttributeSphereMappingTypeEnum : public DistiAttributeEnum<GlsSphere,glsSphereMapping_e,glsSphereMapping_e>
334 {
335 public:
336  GLS_EXPORT DistiAttributeSphereMappingTypeEnum(GlsSphere* frame,SetMethodType setMethod, GetMethodType getMethod,const AttributeName &name);
337  virtual GLS_EXPORT ~DistiAttributeSphereMappingTypeEnum();
338 };
339 
340 } // namespace disti
341 
342 
343 #endif
virtual void SetValue(int spec, va_list &args)
virtual float StackStartAngle()
virtual void SetFillColor(const glsColor &color)
Definition: vertex.h:365
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
glsSphereMapping_e
Definition: gls_sphere.h:60
glsColor _objectColor
Definition: gls_sphere.h:97
virtual float SliceStartAngle()
virtual unsigned int Stacks()
Definition: dynamic_array.h:63
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
virtual unsigned int Slices()
glsSphereMapping_e TextureMappingType(void)
virtual glsColor GetFillColor(void)
Definition: display.h:98
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector)
glsSphereMapping_e _textureMappingType
Definition: gls_sphere.h:108
virtual void Draw(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)
virtual glsColor GetFillColor(void)
unsigned int _stacks
Definition: gls_sphere.h:102
A file for all GL Studio files to include.
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:99
virtual void SetAvailableAttributes(unsigned int value)
Definition: disti_metadata.h:902
virtual int TextureIndex(void)
virtual DisplayObject * CloneObject(bool generateNames=false)
void SetResizeRecalculate()
void Recalculate(void)
GLS_Sphere_Initializers
Definition: gls_sphere.h:69
virtual void Rotate(float angle, int axis=Z_AXIS)
Definition: gls_sphere.h:333
Definition: gls_color.h:54
virtual void CalculateTextureCoordinates(void)
bool _needsResize
Definition: gls_sphere.h:106
virtual void CopyGeometry(DisplayObject *src)
float _stackStartDeg
Definition: gls_sphere.h:100
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
void Scale(int handleBar, float px, float py, Vertex *anchor=NULL)
Definition: display.h:1111
Definition: vertex.h:84
Definition: gls_sphere.h:62
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
virtual void CopyProperties(DisplayObject *src)
unsigned int _slices
Definition: gls_sphere.h:102
Definition: gls_sphere.h:83
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual ~GlsSphere(void)
bool _needsRecalculate
Definition: gls_sphere.h:105
void Resize(void)
Definition: gls_sphere.h:63
Definition: disti_metadata.h:83
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)