GL Studio API
gls_cylinder.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsCylinder 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_CYLINDER_H
41 #define _GLS_CYLINDER_H
42 
43 #include "display.h"
44 #include "gls_color.h"
45 #include "gls_include.h"
46 #include "dynamic_array.h"
47 #include "timer.h"
48 #include "glpolygon.h"
49 #include "group.h"
50 #include "gls_cpp_lang_support.h"
51 
52 #define DEF_CYLINDER_SEGMENTS 1
53 #define DEF_CYLINDER_FACES 30
54 #define DEF_CYLINDER_FACE_START 0.0f
55 #define DEF_CYLINDER_FACE_END 360.0f
56 #define DEF_CYLINDER_TOP_SIZE 1.0f
57 #define DEF_CYLINDER_BOTTOM_SIZE 1.0f
58 #define DEF_CYLINDER_TOP_FACE false
59 #define DEF_CYLINDER_BOTTOM_FACE false
60 
61 namespace disti
62 {
63 
64 /**
65  Cylinder Initializers
66 */
67 typedef enum
68 {
69  GLS_CYLINDER_COLOR=GLS_LAST_INITIALIZER+1,
70  GLS_CYLINDER_SEGMENTS,
71  GLS_CYLINDER_FACES,
72  GLS_CYLINDER_FACE_START,
73  GLS_CYLINDER_FACE_END,
74  GLS_CYLINDER_TOP_SIZE,
75  GLS_CYLINDER_BOTTOM_SIZE,
76  GLS_CYLINDER_TOP_FACE,
77  GLS_CYLINDER_BOTTOM_FACE,
78  GLS_CYLINDER_RADII
80 
81 /**
82  The Cylinder class. Implements Cylinder primitive
83 */
84 
85 class GlsCylinder : public DisplayObject
86 {
87 public:
88  typedef DisplayObject _BaseClass;
89  friend class GlsCylinderEditor;
90 
91 private:
92 
93  /** Initialize data to default values */
94  void CommonConstructorInit(void);
95  /** Disabling default implicit assignment and copy constructors */
96  GlsCylinder& operator=( const GlsCylinder& that ) DISTI_SPECIAL_MEM_FUN_DELETE;
97  GlsCylinder( const GlsCylinder& ) DISTI_SPECIAL_MEM_FUN_DELETE;
98 
99  void CopyGeometryInternal( GlsCylinder* src );
100  void CopyPropertiesInternal( GlsCylinder* src );
101 
102  /* Utility routine used by Hit. Performs a "FirstHit" test, which performs a hit test on the object
103  * but does not guarantee that the collision point returned by Hit is the closest collision point
104  * to the observer
105  * \param point The logical coordinate of the click, relative to the object
106  * \param directionVector The direction of the pick vector
107  * \param collisionPoint Set to the point on the object hit by directionVector
108  * \return boolean indicating if the object was hit by the mouse
109  */
110  bool FirstHit(const Vector &point,const Vector& directionVector,Vector *collisionPoint);
111 
112  /* Utility routine used by Hit. Performs a "BestHit" test, which performs a hit test on the object
113  * and guarantees that the collision point returned by Hit is the closest collision point to the observer.
114  * \param point The logical coordinate of the click, relative to the object
115  * \param directionVector The direction of the pick vector
116  * \param collisionPoint Set to the point on the object hit by directionVector
117  * \return boolean indicating if the object was hit by the mouse
118  */
119  bool BestHit(const Vector &point,const Vector& directionVector,Vector *collisionPoint);
120 
121  bool EndCapFirstPick(unsigned int startIndex,const Vector &point,const Vector& directionVector,Vector *collisionPoint);
122 
123  void UpdateBestPickStatus(const Vector &point,const Vector &directionVector, Vector &tempCollisionPoint,Vector &closestPoint,float &pickDistance);
124 
125 protected:
126 
127  Vector _radii[3]; /** Cylinder radii. 3 vectors */
128 
129  glsColor _objectColor; /** Fill color of object */
130 
131  float _faceStartDeg,_faceEndDeg; /** 0-360, where 0 is positive x-axis of cylinder */
132  float _topSize, _bottomSize; /** 0 - 1, scale of top and bottom ends */
133 
134  unsigned int _segments, /** Number of segments used to draw the cylinder */
135  _faces; /** Number of faces used to draw the cylinder */
136 
137  bool _needsRecalculate; /** True when the cylinder vertices need to be recalculated */
138  bool _needsResize; /** True when the cylinder needs to be resized */
139  bool _topFace; /** True when there is a circle on top of the cylinder */
140  bool _bottomFace; /** True when there is a circle on bottom of the cylinder */
141 
142 
143  /** Sets the resize and recalculate flags, causing the cylinder to be resized and recalculated
144  * the next time the cylinder draws
145  */
146  GLS_EXPORT void SetResizeRecalculate();
147 
148  /** Recalculates the cylinder vertices values */
149  GLS_EXPORT void Recalculate(void);
150 
151  /** Reallocates the vertices of the cylinder */
152  GLS_EXPORT void Resize(void);
153 
154  /* See base class */
155  virtual GLS_EXPORT void SetValue(int spec,va_list &args);
156 
157 #ifdef GLES
158  /** Set a single attribute from the GLO file.
159  * \param data The attribute to set and its associated data.
160  */
161  virtual GLS_EXPORT void SetFromGloData(GlsGloFileAttribute &data);
162 #endif
163 
164 public:
165 
166  /** Constructor. Creates a new GlsCylinder object at given coordinates.
167  * \param x x-coordinate of new GlsCylinder
168  * \param y y-coordinate of new GlsCylinder
169  * \param z z-coordinate of new GlsCylinder
170  */
171  GLS_EXPORT GlsCylinder(float x,float y,float z);
172 
173  /** Allocate a (blank) GlsCylinder object */
174  GLS_EXPORT GlsCylinder(bool newGlsCylinder = true);
175 
176  /** The copy constructor for GlsCylinder
177  *
178  * \param that The GlsCylinder object that is being copied
179  * \param generateName Whether or not to generate a new instance name
180  */
181  GLS_EXPORT GlsCylinder( const GlsCylinder& that, const bool generateName );
182 
183  /** Destroy a GlsCylinder object */
184  virtual GLS_EXPORT ~GlsCylinder(void);
185 
186  virtual GLS_EXPORT void SetAvailableAttributes(unsigned int 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);
197 
198  /* See base class. */
199  virtual GLS_EXPORT void CalculateTextureCoordinates(void);
200 
201  /* See base class */
202  virtual GLS_EXPORT void GetExtents(float &x,float &y,float &z,float &x1,float &y1,float &z1);
203 
204  /* See base class */
205  virtual GLS_EXPORT void Draw(void);
206 
207  /* See base class */
208  virtual GLS_EXPORT bool Hit(float x,float y,float z,float scale, const Vector& directionVector,Vector *collisionPoint);
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 = 0);
215 
216  /* Unhides base class implementation. */
218 
219  /** See base class */
220  virtual GLS_EXPORT void TextureIndex(int index);
221 
222  /* Usually copies the attributes except for geometry attributes from one object to another.
223  * However, since the GlsCylinder's geometry defines its properties, its geometry is copied.
224  * Used by the undo mechanism to undo most attribute change operations.
225  * \param src The object to copy properties from
226  */
227  virtual GLS_EXPORT void CopyProperties(DisplayObject *src);
228 
229  /* See base class */
230  virtual GLS_EXPORT void CopyGeometry(DisplayObject *src);
231 
232  /* See base class */
233  virtual GLS_EXPORT DisplayObject* CloneObject(bool generateNames = false);
234 
235  /* Unhides base class implementation. */
236  using _BaseClass::Rotate;
237 
238  /* See base class */
239  virtual GLS_EXPORT void Rotate(const Vector &orig,float angle, const Vector &axis);
240 
241  /* Unhides base class implementation. */
243 
244  /* See base class */
245  virtual GLS_EXPORT void SetFillColor(const glsColor &color);
246 
248 
249  /* See base class */
250  virtual GLS_EXPORT glsColor GetFillColor(void);
251 
252  /** Sets the starting degree value for the cylinder
253  * \param deg Degree value to which to set _faceStartDeg
254  */
255  virtual GLS_EXPORT void FaceStartAngle(float deg);
256 
257  /** Gets the starting degree value for the cylinder
258  * \return Returns the value of _faceStartDeg
259  */
260  virtual GLS_EXPORT float FaceStartAngle();
261 
262  /** Sets the ending degree value for the cylinder
263  * \param deg Degree value to which to set _faceEndDeg
264  */
265  virtual GLS_EXPORT void FaceEndAngle(float deg);
266 
267  /** Gets the ending degree value for the cylinder
268  * \return Returns the value of _faceEndDeg
269  */
270  virtual GLS_EXPORT float FaceEndAngle();
271 
272  /** Sets the size factor for the top of the cylinder
273  * \param size Factor to which to set _topSize
274  */
275  virtual GLS_EXPORT void TopSizeFactor(float size);
276 
277  /** Gets the size factor for the top of the cylinder
278  * \return Returns the value of _topSize
279  */
280  virtual GLS_EXPORT float TopSizeFactor();
281 
282  /** Sets the size factor for the bottom of the cylinder
283  * \param size Factor to which to set _bottomSize
284  */
285  virtual GLS_EXPORT void BottomSizeFactor(float size);
286 
287  /** Gets the size factor for the bottom of the cylinder
288  * \return Returns the value of _bottomSize
289  */
290  virtual GLS_EXPORT float BottomSizeFactor();
291 
292  /** Sets the number of vertical segments per face
293  * \param segments Desired number of segments to which to set _segments
294  */
295  virtual GLS_EXPORT void Segments(unsigned int segments);
296 
297  /** Gets the number of vertical segments per face
298  * \return Returns the value of _segments
299  */
300  virtual GLS_EXPORT unsigned int Segments();
301 
302  /** Sets the number of faces around the cylinder
303  * \param faces Desired number of faces to which to set _faces
304  */
305  virtual GLS_EXPORT void Faces(unsigned int faces);
306 
307  /** Gets the number of faces around the cylinder
308  * \return Returns the value of _faces
309  */
310  virtual GLS_EXPORT unsigned int Faces();
311 
312  /** Sets whether or not to draw a top face on the cylinder
313  * \param top Presences of a top face, value assigned to _topFace
314  */
315  virtual GLS_EXPORT void TopFace(bool top);
316 
317  /** Gets whether or not to draw a top face on the cylinder
318  * \return Presences of a top face, returns the value of to _topFace
319  */
320  virtual GLS_EXPORT bool TopFace();
321 
322  /** Sets whether or not to draw a bottom face on the cylinder
323  * \param bottom Presences of a bottom face, value assigned to _bottomFace
324  */
325  virtual GLS_EXPORT void BottomFace(bool bottom);
326 
327  /** Gets whether or not to draw a bottom face on the cylinder
328  * \return Presences of a bottom face, returns the value of to _bottomFace
329  */
330  virtual GLS_EXPORT bool BottomFace();
331 
332  /** Gets the radii vectors for the cylinder
333  * \param r1 First radius vector (width)
334  * \param r2 First radius vector (height)
335  * \param r3 First radius vector (depth)
336  */
337  virtual GLS_EXPORT void GetRadii(Vector &r1,Vector &r2,Vector &r3);
338 
339  /** Sets the radii vectors for the cylinder
340  * \param r1 First radius vector (width)
341  * \param r2 First radius vector (height)
342  * \param r3 First radius vector (depth)
343  */
344  virtual GLS_EXPORT void SetRadii(const Vector &r1,const Vector &r2,const Vector &r3);
345 
346 #ifndef GLES
347  /* See base class */
348  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription(InterfaceListType* addToThisList= NULL );
349 
350  /* See base class */
351  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree(InterfaceListType* array);
352 #endif
353 };
354 
355 } // namespace disti
356 
357 #endif
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0)
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual ~GlsCylinder(void)
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector)
Definition: vertex.h:365
virtual void SetRadii(const Vector &r1, const Vector &r2, const Vector &r3)
Definition: dynamic_array.h:63
The disti::Group class. Implements groups of objects.
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
virtual void SetFillColor(const glsColor &color)
virtual void SetAvailableAttributes(unsigned int value)
virtual void GetRadii(Vector &r1, Vector &r2, Vector &r3)
bool _topFace
Definition: gls_cylinder.h:139
virtual glsColor GetFillColor(void)
virtual void CopyProperties(DisplayObject *src)
virtual unsigned int Segments()
Definition: display.h:98
void Recalculate(void)
The disti::GLPolygon class. Implements Polygons.
The disti::Timer class. An OS portable timing class.
virtual void Draw(void)
The Color class: Implements a 4 component RGBA color.
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1)
A file for all GL Studio files to include.
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
The disti::DisplayObject class and global enumerations.
virtual float TopSizeFactor()
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
virtual void SetValue(int spec, va_list &args)
virtual void CopyGeometry(DisplayObject *src)
virtual int TextureIndex(void)
bool _needsRecalculate
Definition: gls_cylinder.h:137
virtual glsColor GetFillColor(void)
virtual bool TopFace()
virtual unsigned int Faces()
unsigned int _faces
Definition: gls_cylinder.h:134
float _topSize
Definition: gls_cylinder.h:132
virtual bool BottomFace()
virtual void Rotate(float angle, int axis=Z_AXIS)
float _faceStartDeg
Definition: gls_cylinder.h:131
unsigned int _segments
Definition: gls_cylinder.h:134
Definition: gls_color.h:54
void Scale(int handleBar, float px, float py, Vertex *anchor=NULL)
Definition: display.h:1111
bool _needsResize
Definition: gls_cylinder.h:138
virtual float FaceStartAngle()
Definition: vertex.h:84
virtual void CalculateTextureCoordinates(void)
Definition: gls_cylinder.h:85
virtual float BottomSizeFactor()
GLS_Cylinder_Initializers
Definition: gls_cylinder.h:67
bool _bottomFace
Definition: gls_cylinder.h:140
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
virtual float FaceEndAngle()
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
glsColor _objectColor
Definition: gls_cylinder.h:129
Definition: bmpimage.h:46
void SetFillColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: display.h:663
void SetResizeRecalculate()