GL Studio 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 _GLSPOLYLINE_H
41 #define _GLSPOLYLINE_H
42 #include "dynamic_array.h"
43 #include "glpolygon.h"
44 #include "gltrimesh.h"
45 #include "gls_cpp_lang_support.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) || \
53  defined(GLSGEN_IMPORT_GLSPOLYLINE) || \
54  defined(GLS_EXPORT_GENERATED) || \
55  defined(GLS_IMPORT_GENERATED)) \
56  && defined(_MSC_VER)
57 # if defined(GLSGEN_EXPORT_GLSPOLYLINE) || defined(GLS_EXPORT_GENERATED)
58 # define GLSGEN_GLSPOLYLINE_EXPORT __declspec(dllexport)
59 # else
60 # define GLSGEN_GLSPOLYLINE_EXPORT __declspec(dllimport)
61 # endif
62 #else
63 # define GLSGEN_GLSPOLYLINE_EXPORT
64 #endif
65 ///////////////////////////////////////////////////////////////////////////////
66 
67 #define LIB_BASE_NAME "gls_poly_line"
68 #include "gls_auto_lib.h"
69 #undef LIB_BASE_NAME
70 
71 namespace disti
72 {
73 
74 // SetValue enumerations
75 enum {
76  GLS_POLY_LINE_FIRST_VALUE = GLS_LAST_INITIALIZER+1,
77  GLS_POLY_LINE_THICKNESS,
78  GLS_POLY_LINE_HALO,
79  GLS_POLY_LINE_HALO_COLOR,
80  GLS_POLY_LINE_HALO_THICKNESS,
81  GLS_POLY_LINE_NORMAL,
82  GLS_POLY_LINE_LAST_INITIALIZER = GLS_POLY_LINE_NORMAL
83 };
84 
85 typedef struct
86 {
87  Vector vertex; /**< The vertex coordinate */
88  Vector texCoord; /**< The texture coordinate */
89  Vector normal; /**< The vertex normal */
91 
92 typedef struct
93 {
94  GlsPolyLineVertex a,b,c;
96 
97 /** Runtime implementation of a GlsPolyLine */
98 class GlsPolyLine : public GLPolygon
99 {
100  friend class GlsPolyLineEditor;
101 private:
102  GlsPolyLine& operator=( const GlsPolyLine& ) DISTI_SPECIAL_MEM_FUN_DELETE;
103  GlsPolyLine( const GlsPolyLine& ) DISTI_SPECIAL_MEM_FUN_DELETE;
104 
105 public:
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. */
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) { return _haloThickness; _needsRecalculate = true; }
201 
202 
203  /** Sets the vertex data for this polygon
204  * You should call UpdateBoundingVolume after changing an objects extents.
205  * \sa UpdateBoundingVolume
206  * \param nPoints The number of vertices in the object
207  * \param vertices The vertex data for the object
208  */
209  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetVertices(unsigned int nPoints,Vertex *vertices);
210 
211  /** see base class */
212  virtual GLSGEN_GLSPOLYLINE_EXPORT void DeleteVertex(unsigned int index);
213 
214  /** Set the recalculate flag for the object to force it to recalculate
215  */
216  virtual GLSGEN_GLSPOLYLINE_EXPORT void SetRecalculate(void);
217 
218 protected:
219 #ifdef GLES
220  // These are helper functions, only used for GLES, and should not be considered missing external api
221  void SetFromGloData( GlsGloFileAttribute& data );
222  void BakeVBO( GlsVertexArray &vbo, GlsPolyLineTriangleList& vertices, glsColor color );
223  GlsVertexArray _gles_triangles;
224  GlsVertexArray _gles_haloTriangles;
225 #endif
226 
227  GlsPolyLineTriangleList _triangles;
228  float _thickness;
229  Vector _normal;
230 
231  bool _halo;
232  glsColor _haloColor;
233  float _haloThickness;
234  GlsPolyLineTriangleList _haloTriangles;
235 
236  bool _needsRecalculate;
237 
238  unsigned int _endCapIndex;
239 
240  /** updates the end-cap hang over for the halos */
241  void UpdateHaloEndCaps();
242 
243  /** notify that vertices have changed
244  * updates bounding volume and sets recalculate for polyline
245  */
246  void VerticesChanged( void );
247 
248  /** Computes the geometry for the line segments and invokes the appropriate corner method */
249  void ComputeSegments(void);
250  /** ComputeSegments helper method */
251  void ComputeSegments(GlsPolyLineTriangleList &array, float thickness, bool calculatingHalos = false);
252  /** Compute a corner */
253  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);
254 
255 
256  void DrawTriangles(GlsPolyLineTriangleList &array);
257 };
258 
259 
260 } // namespace disti
261 
262 #endif
Definition: cull.h:50
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
void ComputeSegments(void)
Definition: vertex.h:365
Definition: gls_poly_line.h:85
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:289
Vector texCoord
Definition: gls_poly_line.h:88
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:56
virtual void SetVertices(unsigned int nPoints, Vertex *vertices)
Definition: display.h:98
glsColor HaloColor(void)
Definition: gls_poly_line.h:190
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:98
virtual void SetAvailableAttributes(unsigned int value)
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)
Vector vertex
Definition: gls_poly_line.h:87
float HaloThickness(void)
Definition: gls_poly_line.h:200
Definition: gls_poly_line.h:92
virtual void SetFillColor(const glsColor &color)
virtual void Rotate(float angle, int axis=Z_AXIS)
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
The gls_auto_lib.
Definition: gls_color.h:54
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:1111
virtual void Rotate(const Vector &orig, float angle, const Vector &axis)
Definition: vertex.h:84
virtual void SetColor(const glsColor &color)
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:663
virtual int PolygonEnd(void)
virtual void CopyGeometry(DisplayObject *srcArg)
virtual void SetColor(const glsColor &color)
virtual DisplayObject * CloneObject(bool generateNames=false)
Vector normal
Definition: gls_poly_line.h:89
The disti::GLTriMesh class. Implements Triangle Meshes.