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  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
88  typedef DisplayObject _BaseClass;
89  typedef DisplayObject BaseClass;
90  friend class GlsCylinderEditor;
91 
92 private:
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  Vector _radii[ 3 ]; /** Cylinder radii. 3 vectors */
127 
128  GlsColor _objectColor; /** Fill color of object */
129 
130  float _faceStartDeg, _faceEndDeg; /** 0-360, where 0 is positive x-axis of cylinder */
131  float _topSize, _bottomSize; /** 0 - 1, scale of top and bottom ends */
132 
133  unsigned int _segments, /** Number of segments used to draw the cylinder */
134  _faces; /** Number of faces used to draw the cylinder */
135 
136  bool _needsRecalculate; /** True when the cylinder vertices need to be recalculated */
137  bool _needsResize; /** True when the cylinder needs to be resized */
138  bool _topFace; /** True when there is a circle on top of the cylinder */
139  bool _bottomFace; /** True when there is a circle on bottom of the cylinder */
140 
141  /** Sets the resize and recalculate flags, causing the cylinder to be resized and recalculated
142  * the next time the cylinder draws
143  */
144  GLS_EXPORT void SetResizeRecalculate();
145 
146  /** Recalculates the cylinder vertices values */
147  GLS_EXPORT void Recalculate( void );
148 
149  /** Reallocates the vertices of the cylinder */
150  GLS_EXPORT void Resize( void );
151 
152  /* See base class */
153  virtual GLS_EXPORT void SetValue( int spec, va_list& args );
154 
155 #ifdef GLES
156  /** Set a single attribute from the GLO file.
157  * \param data The attribute to set and its associated data.
158  */
159  virtual GLS_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
160 #endif
161 
162 public:
163  /** Constructor. Creates a new GlsCylinder object at given coordinates.
164  * \param x x-coordinate of new GlsCylinder
165  * \param y y-coordinate of new GlsCylinder
166  * \param z z-coordinate of new GlsCylinder
167  */
168  GLS_EXPORT GlsCylinder( float x, float y, float z );
169 
170  /** Allocate a (blank) GlsCylinder object */
171  GLS_EXPORT GlsCylinder( bool newGlsCylinder = true );
172 
173  /** The copy constructor for GlsCylinder
174  *
175  * \param that The GlsCylinder object that is being copied
176  * \param generateName Whether or not to generate a new instance name
177  */
178  GLS_EXPORT GlsCylinder( const GlsCylinder& that, const bool generateName );
179 
180  /** Destroy a GlsCylinder object */
181  virtual GLS_EXPORT ~GlsCylinder( void );
182 
183  virtual GLS_EXPORT void SetAvailableAttributes( unsigned int value );
184 
185  /** Finds three coplanar points and the surface normal, if possible. This calculation is performed using the
186  * Vertices() of this object. Used in the editor to determine how to map a texture onto an object.
187  * \param p1 Returns a point on the plane
188  * \param p2 Returns a point on the plane
189  * \param p3 Returns a point on the plane
190  * \param planeVector Returns the surface normal of the plane
191  * \return True if 3 coplanar points were found
192  */
193  virtual GLS_EXPORT bool GetPlaneVectorPoints( Vertex& p1, Vertex& p2, Vertex& p3, Vertex& planeVector );
194 
195  /* See base class. */
196  virtual GLS_EXPORT void CalculateTextureCoordinates( void );
197 
198  /* See base class */
199  virtual GLS_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 );
200 
201  /* See base class */
202  virtual GLS_EXPORT void Draw( void );
203 
204  /* See base class */
205  virtual GLS_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
206 
207  /* Unhides base class implementation. */
208  using BaseClass::Scale;
209 
210  /* See base class */
211  virtual GLS_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar = 0 );
212 
213  /* Unhides base class implementation. */
215 
216  /** See base class */
217  virtual GLS_EXPORT void TextureIndex( int index );
218 
219  /* Usually copies the attributes except for geometry attributes from one object to another.
220  * However, since the GlsCylinder's geometry defines its properties, its geometry is copied.
221  * Used by the undo mechanism to undo most attribute change operations.
222  * \param src The object to copy properties from
223  */
224  virtual GLS_EXPORT void CopyProperties( DisplayObject* src );
225 
226  /* See base class */
227  virtual GLS_EXPORT void CopyGeometry( DisplayObject* src );
228 
229  /* See base class */
230  virtual GLS_EXPORT DisplayObject* CloneObject( bool generateNames = false );
231 
232  /* Unhides base class implementation. */
233  using BaseClass::Rotate;
234 
235  /* See base class */
236  virtual GLS_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
237 
238  /* Unhides base class implementation. */
240 
241  /* See base class */
242  virtual GLS_EXPORT void SetFillColor( const GlsColor& color );
243 
245 
246  /* See base class */
247  virtual GLS_EXPORT GlsColor GetFillColor( void );
248 
249  /** Sets the starting degree value for the cylinder
250  * \param deg Degree value to which to set _faceStartDeg
251  */
252  virtual GLS_EXPORT void FaceStartAngle( float deg );
253 
254  /** Gets the starting degree value for the cylinder
255  * \return Returns the value of _faceStartDeg
256  */
257  virtual GLS_EXPORT float FaceStartAngle();
258 
259  /** Sets the ending degree value for the cylinder
260  * \param deg Degree value to which to set _faceEndDeg
261  */
262  virtual GLS_EXPORT void FaceEndAngle( float deg );
263 
264  /** Gets the ending degree value for the cylinder
265  * \return Returns the value of _faceEndDeg
266  */
267  virtual GLS_EXPORT float FaceEndAngle();
268 
269  /** Sets the size factor for the top of the cylinder
270  * \param size Factor to which to set _topSize
271  */
272  virtual GLS_EXPORT void TopSizeFactor( float size );
273 
274  /** Gets the size factor for the top of the cylinder
275  * \return Returns the value of _topSize
276  */
277  virtual GLS_EXPORT float TopSizeFactor();
278 
279  /** Sets the size factor for the bottom of the cylinder
280  * \param size Factor to which to set _bottomSize
281  */
282  virtual GLS_EXPORT void BottomSizeFactor( float size );
283 
284  /** Gets the size factor for the bottom of the cylinder
285  * \return Returns the value of _bottomSize
286  */
287  virtual GLS_EXPORT float BottomSizeFactor();
288 
289  /** Sets the number of vertical segments per face
290  * \param segments Desired number of segments to which to set _segments
291  */
292  virtual GLS_EXPORT void Segments( unsigned int segments );
293 
294  /** Gets the number of vertical segments per face
295  * \return Returns the value of _segments
296  */
297  virtual GLS_EXPORT unsigned int Segments();
298 
299  /** Sets the number of faces around the cylinder
300  * \param faces Desired number of faces to which to set _faces
301  */
302  virtual GLS_EXPORT void Faces( unsigned int faces );
303 
304  /** Gets the number of faces around the cylinder
305  * \return Returns the value of _faces
306  */
307  virtual GLS_EXPORT unsigned int Faces();
308 
309  /** Sets whether or not to draw a top face on the cylinder
310  * \param top Presences of a top face, value assigned to _topFace
311  */
312  virtual GLS_EXPORT void TopFace( bool top );
313 
314  /** Gets whether or not to draw a top face on the cylinder
315  * \return Presences of a top face, returns the value of to _topFace
316  */
317  virtual GLS_EXPORT bool TopFace();
318 
319  /** Sets whether or not to draw a bottom face on the cylinder
320  * \param bottom Presences of a bottom face, value assigned to _bottomFace
321  */
322  virtual GLS_EXPORT void BottomFace( bool bottom );
323 
324  /** Gets whether or not to draw a bottom face on the cylinder
325  * \return Presences of a bottom face, returns the value of to _bottomFace
326  */
327  virtual GLS_EXPORT bool BottomFace();
328 
329  /** Gets the radii vectors for the cylinder
330  * \param r1 First radius vector (width)
331  * \param r2 First radius vector (height)
332  * \param r3 First radius vector (depth)
333  */
334  virtual GLS_EXPORT void GetRadii( Vector& r1, Vector& r2, Vector& r3 );
335 
336  /** Sets the radii vectors for the cylinder
337  * \param r1 First radius vector (width)
338  * \param r2 First radius vector (height)
339  * \param r3 First radius vector (depth)
340  */
341  virtual GLS_EXPORT void SetRadii( const Vector& r1, const Vector& r2, const Vector& r3 );
342 
343 #ifndef GLES
344  /* See base class */
345  virtual GLS_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
346 
347  /* See base class */
348  virtual GLS_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
349 #endif
350 };
351 
352 } // namespace disti
353 
354 #endif
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0)
GlsColor _objectColor
Definition: gls_cylinder.h:128
virtual DisplayObject * CloneObject(bool generateNames=false)
virtual ~GlsCylinder(void)
virtual bool GetPlaneVectorPoints(Vertex &p1, Vertex &p2, Vertex &p3, Vertex &planeVector)
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
virtual void SetRadii(const Vector &r1, const Vector &r2, const Vector &r3)
Definition: dynamic_array.h:66
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:138
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.
Definition: gls_glo_file.h:982
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:136
virtual bool TopFace()
virtual GlsColor GetFillColor(void)
virtual unsigned int Faces()
unsigned int _faces
Definition: gls_cylinder.h:133
float _topSize
Definition: gls_cylinder.h:131
Definition: gls_color.h:53
virtual bool BottomFace()
virtual void Rotate(float angle, int axis=Z_AXIS)
float _faceStartDeg
Definition: gls_cylinder.h:130
unsigned int _segments
Definition: gls_cylinder.h:133
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0)
bool _needsResize
Definition: gls_cylinder.h:137
virtual float FaceStartAngle()
Definition: vertex.h:84
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:139
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:678
virtual void SetFillColor(const GlsColor &color)
void SetResizeRecalculate()