GL Studio C++ Runtime API
gls_poly_line.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsPolyLine class.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2016 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 INCLUDED_GLS_POLYLINE_H
41 #define INCLUDED_GLS_POLYLINE_H
42 #include "dynamic_array.h"
43 #include "glpolygon.h"
44 #include "gls_cpp_lang_support.h"
45 #include "gltrimesh.h"
46 
47 #ifdef GLES
48 # include "gls_vertex_array.h"
49 #endif
50 
51 //////////////////// Provides support for creating DLLs ////////////////////////
52 #if( defined( GLSGEN_EXPORT_GLSPOLYLINE ) || defined( GLSGEN_IMPORT_GLSPOLYLINE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
53  && defined( _MSC_VER )
54 # if defined( GLSGEN_EXPORT_GLSPOLYLINE ) || defined( GLS_EXPORT_GENERATED )
55 # define GLSGEN_GLSPOLYLINE_EXPORT __declspec( dllexport )
56 # else
57 # define GLSGEN_GLSPOLYLINE_EXPORT __declspec( dllimport )
58 # endif
59 #else
60 # define GLSGEN_GLSPOLYLINE_EXPORT
61 #endif
62 ///////////////////////////////////////////////////////////////////////////////
63 
64 #define LIB_BASE_NAME "gls_poly_line"
65 #include "gls_auto_lib.h"
66 #undef LIB_BASE_NAME
67 
68 namespace disti
69 {
70 // SetValue enumerations
71 enum
72 {
73  GLS_POLY_LINE_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
74  GLS_POLY_LINE_THICKNESS,
75  GLS_POLY_LINE_HALO,
76  GLS_POLY_LINE_HALO_COLOR,
77  GLS_POLY_LINE_HALO_THICKNESS,
78  GLS_POLY_LINE_NORMAL,
79  GLS_POLY_LINE_LAST_INITIALIZER = GLS_POLY_LINE_NORMAL
80 };
81 
82 typedef struct
83 {
84  Vector vertex; /**< The vertex coordinate */
85  Vector texCoord; /**< The texture coordinate */
86  Vector normal; /**< The vertex normal */
88 
89 typedef struct
90 {
91  GlsPolyLineVertex a, b, c;
93 
94 /** Runtime implementation of a GlsPolyLine */
95 class GlsPolyLine : public GLPolygon
96 {
97  friend class GlsPolyLineEditor;
98 
99 private:
100  GlsPolyLine& operator=( const GlsPolyLine& ) DISTI_SPECIAL_MEM_FUN_DELETE;
101  GlsPolyLine( const GlsPolyLine& ) DISTI_SPECIAL_MEM_FUN_DELETE;
102 
103 public:
104  DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
105  typedef GLPolygon _BaseClass;
106  typedef GLPolygon BaseClass;
108 
109  /** Create a new GlsPolyLine.*/
110  GLSGEN_GLSPOLYLINE_EXPORT GlsPolyLine();
111 
112  GLSGEN_GLSPOLYLINE_EXPORT GlsPolyLine( const GlsPolyLine& that, const bool generateNames );
113 
114  /** Destructs a GlsPolyLine object */
115  virtual GLSGEN_GLSPOLYLINE_EXPORT ~GlsPolyLine();
116 
117  static GLSGEN_GLSPOLYLINE_EXPORT DisplayObject* CreateInstance();
118 
119  virtual GLSGEN_GLSPOLYLINE_EXPORT DisplayObject* CloneObject( bool generateNames = false );
120 
121  virtual GLSGEN_GLSPOLYLINE_EXPORT void GetExtents( float& minx, float& miny, float& minz, float& maxx, float& maxy, float& maxz );
122 
123  using BaseClass::SetColor;
124  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetColor( const GlsColor& color );
125 
127  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetFillColor( const GlsColor& color );
128 
129  virtual GLSGEN_GLSPOLYLINE_EXPORT void CopyProperties( DisplayObject* src );
130  virtual GLSGEN_GLSPOLYLINE_EXPORT void CopyGeometry( DisplayObject* srcArg );
131 
132  virtual GLSGEN_GLSPOLYLINE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
133  virtual GLSGEN_GLSPOLYLINE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
134 
135  virtual GLSGEN_GLSPOLYLINE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
136  virtual GLSGEN_GLSPOLYLINE_EXPORT void Draw( void );
137 
138  /* Unhides base class implementation. */
139  using BaseClass::Scale;
140 
141  virtual GLSGEN_GLSPOLYLINE_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar );
142 
143  /* Unhides base class implementation. */
144  using BaseClass::Rotate;
145 
146  virtual GLSGEN_GLSPOLYLINE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
147 
148  virtual GLSGEN_GLSPOLYLINE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
149 
150  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetValue( int spec, va_list& args );
151 
152  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetAvailableAttributes( unsigned int value );
153 
154  /* Unhides base class implementation. */
155  using BaseClass::PolygonEnd;
156 
157  /** Sets the polygon end mode (Open or Closed) for the polygon
158  * \param end Enumeration indicating open or closed mode
159  * \sa PolygonClose_e
160  */
161  virtual GLSGEN_GLSPOLYLINE_EXPORT void PolygonEnd( const int end );
162 
163  //////////////////////////////////////////////////
164  // GlsPolyLine specific operations
165  //////////////////////////////////////////////////
166 
167  /** Sets the line thickness
168  * \param val The new line thickness in logical units
169  */
170  GLSGEN_GLSPOLYLINE_EXPORT void Thickness( const float& val );
171 
172  /** Gets the line thickness
173  * \return The line thickness in logical units
174  */
175  GLSGEN_GLSPOLYLINE_EXPORT float Thickness( void ) { return _thickness; }
176 
177  /** Get the normal for the polyline **/
178  GLSGEN_GLSPOLYLINE_EXPORT Vector GlobalNormal( void ) { return _normal; }
179 
180  /** Enable/Disable halo */
181  GLSGEN_GLSPOLYLINE_EXPORT void Halo( const bool& val );
182 
183  /** Get the halo setting */
184  GLSGEN_GLSPOLYLINE_EXPORT bool Halo( void ) { return _halo; }
185 
186  /** Set the halo color */
187  GLSGEN_GLSPOLYLINE_EXPORT void HaloColor( const GlsColor& val );
188 
189  /** Get the halo color */
190  GLSGEN_GLSPOLYLINE_EXPORT GlsColor HaloColor( void ) { return _haloColor; }
191 
192  /** Set the halo thickness
193  * \param val The new halo thickness in logical units
194  */
195  GLSGEN_GLSPOLYLINE_EXPORT void HaloThickness( const float& val );
196 
197  /** Get the halo thickness
198  * \return The line thickness in logical units
199  */
200  GLSGEN_GLSPOLYLINE_EXPORT float HaloThickness( void )
201  {
202  return _haloThickness;
203  _needsRecalculate = true;
204  }
205 
206  /** Sets the vertex data for this polygon
207  * You should call UpdateBoundingVolume after changing an objects extents.
208  * \sa UpdateBoundingVolume
209  * \param nPoints The number of vertices in the object
210  * \param vertices The vertex data for the object
211  */
212  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices );
213 
214  /** see base class */
215  GLSGEN_GLSPOLYLINE_EXPORT void DeleteVertexAt( unsigned int index ) DISTI_METHOD_OVERRIDE;
216 
217  /** Set the recalculate flag for the object to force it to recalculate
218  */
219  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetRecalculate( void );
220 
221 protected:
222 #ifdef GLES
223  // These are helper functions, only used for GLES, and should not be considered missing external api
224  GLSGEN_GLSPOLYLINE_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
225  void BakeVBO( GlsVertexArray& vbo, GlsPolyLineTriangleList& vertices, GlsColor color );
226  GlsVertexArray _gles_triangles;
227  GlsVertexArray _gles_haloTriangles;
228 #endif
229 
230  GlsPolyLineTriangleList _triangles;
231  float _thickness;
232  Vector _normal;
233 
234  bool _halo;
235  GlsColor _haloColor;
236  float _haloThickness;
237  GlsPolyLineTriangleList _haloTriangles;
238 
239  bool _needsRecalculate;
240 
241  unsigned int _endCapIndex;
242 
243  /** updates the end-cap hang over for the halos */
244  void UpdateHaloEndCaps();
245 
246  /** notify that vertices have changed
247  * updates bounding volume and sets recalculate for polyline
248  */
249  void VerticesChanged( void );
250 
251  /** Computes the geometry for the line segments and invokes the appropriate corner method */
252  void ComputeSegments( void );
253  /** ComputeSegments helper method */
254  void ComputeSegments( GlsPolyLineTriangleList& array, float thickness, bool calculatingHalos = false );
255  /** Compute a corner */
256  void ComputeCorner( GlsPolyLineTriangleList& array, float thickness, float cornerRadius, const Vector& refVert, const Vector& v1, const Vector& v2, const Vector& v3, const Vector& v4, const Vector& l1, const Vector& l2, bool calculatingHalos = false );
257 
258  void DrawTriangles( GlsPolyLineTriangleList& array );
259 };
260 
261 } // namespace disti
262 
263 #endif
Definition: cull.h:49
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
void ComputeSegments(void)
Definition: vertex.h:409
Definition: gls_poly_line.h:82
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
GlsColor HaloColor(void)
Definition: gls_poly_line.h:190
The disti::DynamicArray class. A templated array of objects capable of dynamically growing...
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:296
Vector texCoord
Definition: gls_poly_line.h:85
virtual void GetExtents(float &minx, float &miny, float &minz, float &maxx, float &maxy, float &maxz)
virtual void SetRecalculate(void)
The Polygon class. Implements Polygons.
Definition: glpolygon.h:55
virtual void SetVertices(unsigned int nPoints, Vertex *vertices)
virtual void SetFillColor(const GlsColor &color)
Definition: display.h:98
Vector GlobalNormal(void)
Definition: gls_poly_line.h:178
virtual ~GlsPolyLine()
The disti::GLPolygon class. Implements Polygons.
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
virtual void SetValue(int spec, va_list &args)
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar)
Definition: gls_poly_line.h:95
virtual void SetAvailableAttributes(unsigned int value)
Definition: gls_glo_file.h:988
void ComputeCorner(GlsPolyLineTriangleList &array, float thickness, float cornerRadius, const Vector &refVert, const Vector &v1, const Vector &v2, const Vector &v3, const Vector &v4, const Vector &l1, const Vector &l2, bool calculatingHalos=false)
virtual void CopyProperties(DisplayObject *src)
virtual void SetColor(const GlsColor &color)
Vector vertex
Definition: gls_poly_line.h:84
float HaloThickness(void)
Definition: gls_poly_line.h:200
Definition: gls_poly_line.h:89
Definition: gls_vertex_array.h:58
Definition: gls_color.h:53
virtual void Rotate(float angle, int axis=Z_AXIS)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
The gls_auto_lib.
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
virtual void Draw(void)
virtual void Scale(float px, float py, float pz, Vertex *anchor, int handleBar=0)
void DeleteVertexAt(unsigned int index) DISTI_METHOD_OVERRIDE
virtual void SetColor(const GlsColor &color)
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
An object for managing vertices, texture coordinates, colors and normals for GLPolygon and other disp...
Definition: vertex.h:84
bool Halo(void)
Definition: gls_poly_line.h:184
void VerticesChanged(void)
Macros and helper code to determine what subset of C++11/14/17 is available.
float Thickness(void)
Definition: gls_poly_line.h:175
Definition: bmpimage.h:46
void SetFillColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: display.h:678
virtual int PolygonEnd(void)
virtual void CopyGeometry(DisplayObject *srcArg)
virtual DisplayObject * CloneObject(bool generateNames=false)
Vector normal
Definition: gls_poly_line.h:86
The disti::GLTriMesh class. Implements Triangle Meshes.