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