GL Studio C++ Runtime API
gls_nurb_curve.h
Go to the documentation of this file.
1 /*! \file
2  \brief The disti::GlsNurbCurve 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 _GLSNURBCURVE_H
41 #define _GLSNURBCURVE_H
42 
43 #include "display.h"
44 #include "glpolygon.h"
45 #include "gls_cpp_lang_support.h"
46 
47 //////////////////// Provides support for creating DLLs ////////////////////////
48 #if( defined( GLSGEN_EXPORT_GLSNURBCURVE ) || defined( GLSGEN_IMPORT_GLSNURBCURVE ) || defined( GLS_EXPORT_GENERATED ) || defined( GLS_IMPORT_GENERATED ) ) \
49  && defined( _MSC_VER )
50 # if defined( GLSGEN_EXPORT_GLSNURBCURVE ) || defined( GLS_EXPORT_GENERATED )
51 # define GLSGEN_GLSNURBCURVE_EXPORT __declspec( dllexport )
52 # else
53 # define GLSGEN_GLSNURBCURVE_EXPORT __declspec( dllimport )
54 # endif
55 #else
56 # define GLSGEN_GLSNURBCURVE_EXPORT
57 #endif
58 ///////////////////////////////////////////////////////////////////////////////
59 
60 #define LIB_BASE_NAME "gls_nurb_curve"
61 #include "gls_auto_lib.h"
62 #undef LIB_BASE_NAME
63 
64 namespace disti
65 {
66 /** Maximum number of tesselated vertices in a spline */
67 const int MAX_SPLINE_VERTICES = 2000;
68 
69 /** smallest number of control points in a spline */
70 const int MIN_NUMBER_POINTS = 2;
71 
72 /** When calculating the current vertices, how many control
73  * points should we consider */
75 
76 // SetValue enumerations
77 enum
78 {
79  GLS_GLSNURBCURVE_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
80  GLS_GLSNURBCURVE_EMITEVENT // example
81 };
82 
83 /** Runtime implementation of a GlsNurbCurve */
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 GlsNurbCurveEditor;
91 
92 private:
93  // We capture the tesselated vertices from the NURB render function
94  // and store them here, to be used by the draw routine.
95  // This is not to be confused with the editor Tesselator functions.
96  // These are the points that the NURB render function generates to
97  // draw the curve.
98  Vertex* _tesselated_vertices; /** The tesselated vertices, computed from the control points */
99  unsigned int _tesselated_vertices_count; /** The number of tesselated vertices */
100 
101  // disabling default implicit assignment and copy constructor
102  GlsNurbCurve& operator=( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
103  GlsNurbCurve( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
104 
105 public:
106  /** Creates a NURB Curve with the vertices specified
107  * \param nPoints Number of control points in the NURB
108  * \param vertices An array of allocated vertices
109  * \pre vertices is not NULL
110  */
111  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int nPoints, Vertex* vertices );
112 
113  /** Allocate a (blank) NURB Curve object */
114  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( bool generateInstanceName = false );
115 
116  /** NurbCurve Constructor. Creates a new NURBCurve object with
117  * the number of vertices and vertex data specified.
118  * \param n_points Number of control points in the NURB
119  * \param vertices An array of allocated vertices
120  * \param location Initial location of the NURB
121  */
122  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int n_points, Vertex* vertices, Vertex& location );
123 
124  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( const GlsNurbCurve& that, const bool generateNames );
125 
126  /** Destructs a GlsNurbCurve object */
127  virtual GLSGEN_GLSNURBCURVE_EXPORT ~GlsNurbCurve();
128 
129  static GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CreateInstance();
130 
131  /** Generate a list of vertices describing the NURB curve, save those
132  * vertices in the NURBCurve object for use in drawing.
133  */
134  void GLSGEN_GLSNURBCURVE_EXPORT GenerateTessellatedVertices( void );
135 
136  /** Gets the object's number of Tesselated vertices.
137  * These tesselated vertices are generated by the NURB render function.
138  * \return The number of vertices in the object
139  */
140  unsigned int NumberOfTessVertices() const { return _tesselated_vertices_count; }
141 
142  /** Gets the object's tesselated vertices.
143  * \return Pointer the the object's tesselated vertices
144  */
145  Vertex* TessVertices() { return _tesselated_vertices; }
146 
147  //////////////////////////////////////////////////
148  // Overridden base class methods
149  //////////////////////////////////////////////////
150  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetAvailableAttributes( unsigned int availableAttributes ) DISTI_METHOD_OVERRIDE;
151  virtual GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
152  virtual GLSGEN_GLSNURBCURVE_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
153 #ifndef GLES
154  virtual GLSGEN_GLSNURBCURVE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
155  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
156 #endif
157  virtual GLSGEN_GLSNURBCURVE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
158  virtual GLSGEN_GLSNURBCURVE_EXPORT void Draw( void ) DISTI_METHOD_OVERRIDE;
159 
160  /** Calculates normals based on the vertices and the specified winding order */
161  virtual GLSGEN_GLSNURBCURVE_EXPORT void CalcNormals( int windingOrder = 1 );
162 
163  /* See base class */
164  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices ) DISTI_METHOD_OVERRIDE;
165 
166  /* See base class */
167  virtual GLSGEN_GLSNURBCURVE_EXPORT void VaListSetVertices( unsigned int nPoints, va_list args ) DISTI_METHOD_OVERRIDE;
168 
169  /* Unhides base class implementation. */
170  using BaseClass::Scale;
171 
172  /* See base class */
173  GLSGEN_GLSNURBCURVE_EXPORT void Scale( float px, float py, float pz, Vertex* a, int handleBar ) DISTI_METHOD_OVERRIDE;
174 
175  /* See base class */
176  virtual GLSGEN_GLSNURBCURVE_EXPORT void CalculateTextureCoordinates( void ) DISTI_METHOD_OVERRIDE;
177 
178  /* Unhides base class implementation. */
179  using BaseClass::Rotate;
180 
181  /* See base class */
182  virtual GLSGEN_GLSNURBCURVE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
183 
184  /* See base class */
185  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 ) DISTI_METHOD_OVERRIDE;
186 
187  /* See base class */
188  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetTransformedExtents( Vector& min, Vector& max, const GlsMatrixType& matrix, bool resetMinMax = true ) DISTI_METHOD_OVERRIDE;
189 
190  /* See base class */
191  virtual GLSGEN_GLSNURBCURVE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
192 
193  /** Remove the Vertex at the given index. This causes tesselated vertices to be recalculated.
194  * \param index The index to remove
195  */
196  GLSGEN_GLSNURBCURVE_EXPORT void DeleteVertexAt( unsigned int index ) DISTI_METHOD_OVERRIDE;
197 
198  /* See base class */
199  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertexColor( unsigned int index, unsigned char col[] ) DISTI_METHOD_OVERRIDE;
200 
201  /* Unhides base class implementation. */
202  using BaseClass::SetFillColor;
203 
204  /* See base class */
205  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetFillColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
206 
207  //
208  // Create a spline from a set of control points. Return the vertices, so that the user
209  // can draw the spline as he/she wishes.
210  //
211  GLSGEN_GLSNURBCURVE_EXPORT void GenerateSpline(
212  unsigned int num_vertices, // Number of control points to make a spline out of
213  Vertex* vertices, // Control points
214  unsigned int* curve_array_size, // Originally the size of the curve array
215  // the actually used size is returned here
216  Vertex* curve_array );
217 
218 protected:
219 #ifdef GLES
220  // BakeVBO is a helper function only used for GLES drawing and should not be considered missing external api
221  void BakeVBO();
222  GlsVertexArray _curve;
223  GlsVertexArray _fill;
224 #endif
225 };
226 
227 } // namespace disti
228 
229 #endif
Definition: cull.h:49
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
const int MIN_NUMBER_POINTS
Definition: gls_nurb_curve.h:70
void GenerateTessellatedVertices(void)
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
Definition: vertex.h:409
void DeleteVertexAt(unsigned int index) DISTI_METHOD_OVERRIDE
virtual void CalcNormals(int windingOrder=1)
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:436
const int MAX_SPLINE_VERTICES
Definition: gls_nurb_curve.h:67
virtual void GetTransformedExtents(Vector &min, Vector &max, const GlsMatrixType &matrix, bool resetMinMax=true) DISTI_METHOD_OVERRIDE
Definition: dynamic_array.h:66
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:473
virtual void SetFillColor(const GlsColor &color) DISTI_METHOD_OVERRIDE
virtual void SetAvailableAttributes(unsigned int availableAttributes) DISTI_METHOD_OVERRIDE
Definition: display.h:98
virtual void VaListSetVertices(unsigned int nPoints, va_list args) DISTI_METHOD_OVERRIDE
The disti::GLPolygon class. Implements Polygons.
The disti::DisplayObject class and global enumerations.
Vertex * TessVertices()
Definition: gls_nurb_curve.h:145
virtual void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
virtual void CalculateTextureCoordinates(void) DISTI_METHOD_OVERRIDE
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) DISTI_METHOD_OVERRIDE
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL) DISTI_METHOD_OVERRIDE
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
Definition: gls_vertex_array.h:58
Definition: gls_color.h:53
unsigned int NumberOfTessVertices() const
Definition: gls_nurb_curve.h:140
The gls_auto_lib.
Definition: gls_nurb_curve.h:84
virtual void Draw(void) DISTI_METHOD_OVERRIDE
Definition: vertex.h:84
const int NUMBER_POINTS_TO_CONSIDER
Definition: gls_nurb_curve.h:74
virtual ~GlsNurbCurve()
Macros and helper code to determine what subset of C++11/14/17 is available.
virtual void SetVertices(unsigned int nPoints, Vertex *vertices) DISTI_METHOD_OVERRIDE
virtual void SetVertexColor(unsigned int index, unsigned char col[]) DISTI_METHOD_OVERRIDE
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array) DISTI_METHOD_OVERRIDE
Definition: bmpimage.h:46
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1) DISTI_METHOD_OVERRIDE
void Scale(float px, float py, float pz, Vertex *a, int handleBar) DISTI_METHOD_OVERRIDE