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  typedef GLPolygon _BaseClass;
106 
107  /** Create a new GlsPolyLine.*/
108  GLSGEN_GLSPOLYLINE_EXPORT GlsPolyLine();
109 
110  GLSGEN_GLSPOLYLINE_EXPORT GlsPolyLine( const GlsPolyLine& that, const bool generateNames );
111 
112  /** Destructs a GlsPolyLine object */
113  virtual GLSGEN_GLSPOLYLINE_EXPORT ~GlsPolyLine();
114 
115  static GLSGEN_GLSPOLYLINE_EXPORT DisplayObject* CreateInstance();
116 
117  virtual GLSGEN_GLSPOLYLINE_EXPORT DisplayObject* CloneObject( bool generateNames = false );
118 
119  virtual GLSGEN_GLSPOLYLINE_EXPORT void GetExtents( float& minx, float& miny, float& minz, float& maxx, float& maxy, float& maxz );
120 
121  using _BaseClass::SetColor;
122  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetColor( const GlsColor& color );
123 
125  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetFillColor( const GlsColor& color );
126 
127  virtual GLSGEN_GLSPOLYLINE_EXPORT void CopyProperties( DisplayObject* src );
128  virtual GLSGEN_GLSPOLYLINE_EXPORT void CopyGeometry( DisplayObject* srcArg );
129 
130  virtual GLSGEN_GLSPOLYLINE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
131  virtual GLSGEN_GLSPOLYLINE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
132 
133  virtual GLSGEN_GLSPOLYLINE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
134  virtual GLSGEN_GLSPOLYLINE_EXPORT void Draw( void );
135 
136  /* Unhides base class implementation. */
137  using _BaseClass::Scale;
138 
139  virtual GLSGEN_GLSPOLYLINE_EXPORT void Scale( float px, float py, float pz, Vertex* anchor, int handleBar );
140 
141  /* Unhides base class implementation. */
142  using _BaseClass::Rotate;
143 
144  virtual GLSGEN_GLSPOLYLINE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
145 
146  virtual GLSGEN_GLSPOLYLINE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
147 
148  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetValue( int spec, va_list& args );
149 
150  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetAvailableAttributes( unsigned int value );
151 
152  /* Unhides base class implementation. */
154 
155  /** Sets the polygon end mode (Open or Closed) for the polygon
156  * \param end Enumeration indicating open or closed mode
157  * \sa PolygonClose_e
158  */
159  virtual GLSGEN_GLSPOLYLINE_EXPORT void PolygonEnd( const int end );
160 
161  //////////////////////////////////////////////////
162  // GlsPolyLine specific operations
163  //////////////////////////////////////////////////
164 
165  /** Sets the line thickness
166  * \param val The new line thickness in logical units
167  */
168  GLSGEN_GLSPOLYLINE_EXPORT void Thickness( const float& val );
169 
170  /** Gets the line thickness
171  * \return The line thickness in logical units
172  */
173  GLSGEN_GLSPOLYLINE_EXPORT float Thickness( void ) { return _thickness; }
174 
175  /** Get the normal for the polyline **/
176  GLSGEN_GLSPOLYLINE_EXPORT Vector GlobalNormal( void ) { return _normal; }
177 
178  /** Enable/Disable halo */
179  GLSGEN_GLSPOLYLINE_EXPORT void Halo( const bool& val );
180 
181  /** Get the halo setting */
182  GLSGEN_GLSPOLYLINE_EXPORT bool Halo( void ) { return _halo; }
183 
184  /** Set the halo color */
185  GLSGEN_GLSPOLYLINE_EXPORT void HaloColor( const GlsColor& val );
186 
187  /** Get the halo color */
188  GLSGEN_GLSPOLYLINE_EXPORT GlsColor HaloColor( void ) { return _haloColor; }
189 
190  /** Set the halo thickness
191  * \param val The new halo thickness in logical units
192  */
193  GLSGEN_GLSPOLYLINE_EXPORT void HaloThickness( const float& val );
194 
195  /** Get the halo thickness
196  * \return The line thickness in logical units
197  */
198  GLSGEN_GLSPOLYLINE_EXPORT float HaloThickness( void )
199  {
200  return _haloThickness;
201  _needsRecalculate = true;
202  }
203 
204  /** Sets the vertex data for this polygon
205  * You should call UpdateBoundingVolume after changing an objects extents.
206  * \sa UpdateBoundingVolume
207  * \param nPoints The number of vertices in the object
208  * \param vertices The vertex data for the object
209  */
210  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices );
211 
212  /** see base class */
213  virtual GLSGEN_GLSPOLYLINE_EXPORT void DeleteVertex( unsigned int index );
214 
215  /** Set the recalculate flag for the object to force it to recalculate
216  */
217  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetRecalculate( void );
218 
219 protected:
220 #ifdef GLES
221  // These are helper functions, only used for GLES, and should not be considered missing external api
222  GLSGEN_GLSPOLYLINE_EXPORT void SetFromGloData( GlsGloFileAttribute& data );
223  void BakeVBO( GlsVertexArray& vbo, GlsPolyLineTriangleList& vertices, GlsColor color );
224  GlsVertexArray _gles_triangles;
225  GlsVertexArray _gles_haloTriangles;
226 #endif
227 
228  GlsPolyLineTriangleList _triangles;
229  float _thickness;
230  Vector _normal;
231 
232  bool _halo;
233  GlsColor _haloColor;
234  float _haloThickness;
235  GlsPolyLineTriangleList _haloTriangles;
236 
237  bool _needsRecalculate;
238 
239  unsigned int _endCapIndex;
240 
241  /** updates the end-cap hang over for the halos */
242  void UpdateHaloEndCaps();
243 
244  /** notify that vertices have changed
245  * updates bounding volume and sets recalculate for polyline
246  */
247  void VerticesChanged( void );
248 
249  /** Computes the geometry for the line segments and invokes the appropriate corner method */
250  void ComputeSegments( void );
251  /** ComputeSegments helper method */
252  void ComputeSegments( GlsPolyLineTriangleList& array, float thickness, bool calculatingHalos = false );
253  /** Compute a corner */
254  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 );
255 
256  void DrawTriangles( GlsPolyLineTriangleList& array );
257 };
258 
259 } // namespace disti
260 
261 #endif
Definition: cull.h:49
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
void ComputeSegments(void)
Definition: vertex.h:408
Definition: gls_poly_line.h:82
GlsColor HaloColor(void)
Definition: gls_poly_line.h:188
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:276
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:176
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:982
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:198
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 DeleteVertex(unsigned int index)
virtual void Draw(void)
void Scale(int handleBar, float px, float py, Vertex *anchor=NULL)
Definition: display.h:1112
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:83
bool Halo(void)
Definition: gls_poly_line.h:182
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:173
Definition: bmpimage.h:46
void SetFillColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: display.h:664
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.