GL Studio 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  typedef DisplayObject _BaseClass;
88  friend class GlsNurbCurveEditor;
89 
90 private:
91  // We capture the tesselated vertices from the NURB render function
92  // and store them here, to be used by the draw routine.
93  // This is not to be confused with the editor Tesselator functions.
94  // These are the points that the NURB render function generates to
95  // draw the curve.
96  Vertex* _tesselated_vertices; /** The tesselated vertices, computed from the control points */
97  unsigned int _tesselated_vertices_count; /** The number of tesselated vertices */
98 
99  // disabling default implicit assignment and copy constructor
100  GlsNurbCurve& operator=( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
101  GlsNurbCurve( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
102 
103 public:
104  /** Creates a NURB Curve with the vertices specified
105  * \param nPoints Number of control points in the NURB
106  * \param vertices An array of allocated vertices
107  * \pre vertices is not NULL
108  */
109  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int nPoints, Vertex* vertices );
110 
111  /** Allocate a (blank) NURB Curve object */
112  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( bool generateInstanceName = false );
113 
114  /** NurbCurve Constructor. Creates a new NURBCurve object with
115  * the number of vertices and vertex data specified.
116  * \param n_points Number of control points in the NURB
117  * \param vertices An array of allocated vertices
118  * \param location Initial location of the NURB
119  */
120  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int n_points, Vertex* vertices, Vertex& location );
121 
122  GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( const GlsNurbCurve& that, const bool generateNames );
123 
124  /** Destructs a GlsNurbCurve object */
125  virtual GLSGEN_GLSNURBCURVE_EXPORT ~GlsNurbCurve();
126 
127  static GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CreateInstance();
128 
129  /** Generate a list of vertices describing the NURB curve, save those
130  * vertices in the NURBCurve object for use in drawing.
131  */
132  void GLSGEN_GLSNURBCURVE_EXPORT GenerateTessellatedVertices( void );
133 
134  /** Gets the object's number of Tesselated vertices.
135  * These tesselated vertices are generated by the NURB render function.
136  * \return The number of vertices in the object
137  */
138  unsigned int NumberOfTessVertices() const { return _tesselated_vertices_count; }
139 
140  /** Gets the object's tesselated vertices.
141  * \return Pointer the the object's tesselated vertices
142  */
143  Vertex* TessVertices() { return _tesselated_vertices; }
144 
145  //////////////////////////////////////////////////
146  // Overridden base class methods
147  //////////////////////////////////////////////////
148  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetAvailableAttributes( unsigned int availableAttributes );
149  virtual GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CloneObject( bool generateNames = false );
150  virtual GLSGEN_GLSNURBCURVE_EXPORT void CopyGeometry( DisplayObject* src );
151 
152  virtual GLSGEN_GLSNURBCURVE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL );
153  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array );
154 
155  virtual GLSGEN_GLSNURBCURVE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler );
156  virtual GLSGEN_GLSNURBCURVE_EXPORT void Draw( void );
157 
158  /** Calculates normals based on the vertices and the specified winding order */
159  virtual GLSGEN_GLSNURBCURVE_EXPORT void CalcNormals( int windingOrder = 1 );
160 
161  /* See base class */
162  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices );
163 
164  /* See base class */
165  virtual GLSGEN_GLSNURBCURVE_EXPORT void VaListSetVertices( unsigned int nPoints, va_list args );
166 
167  /* Unhides base class implementation. */
168  using _BaseClass::Scale;
169 
170  /* See base class */
171  GLSGEN_GLSNURBCURVE_EXPORT void Scale( float px, float py, float pz, Vertex* a, int handleBar );
172 
173  /* See base class */
174  virtual GLSGEN_GLSNURBCURVE_EXPORT void CalculateTextureCoordinates( void );
175 
176  /* Unhides base class implementation. */
177  using _BaseClass::Rotate;
178 
179  /* See base class */
180  virtual GLSGEN_GLSNURBCURVE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis );
181 
182  /* See base class */
183  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 );
184 
185  /* See base class */
186  virtual GLSGEN_GLSNURBCURVE_EXPORT void GetTransformedExtents( Vector& min, Vector& max, const GlsMatrixAffineD& matrix, bool resetMinMax = true );
187 
188  /* See base class */
189  virtual GLSGEN_GLSNURBCURVE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint );
190 
191  /** Remove the Vertex at the given index. This causes tesselated vertices to be recalculated.
192  * \param index The index to remove (1 based)
193  */
194  virtual GLSGEN_GLSNURBCURVE_EXPORT void DeleteVertex( unsigned int index );
195 
196  /* See base class */
197  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertexColor( unsigned int index, unsigned char col[] );
198 
199  /* Unhides base class implementation. */
201 
202  /* See base class */
203  virtual GLSGEN_GLSNURBCURVE_EXPORT void SetFillColor( const glsColor& color );
204 
205  //
206  // Create a spline from a set of control points. Return the vertices, so that the user
207  // can draw the spline as he/she wishes.
208  //
209  GLSGEN_GLSNURBCURVE_EXPORT void GenerateSpline(
210  unsigned int num_vertices, // Number of control points to make a spline out of
211  Vertex* vertices, // Control points
212  unsigned int* curve_array_size, // Originally the size of the curve array
213  // the actually used size is returned here
214  Vertex* curve_array );
215 
216 protected:
217 #ifdef GLES
218  // BakeVBO is a helper function only used for GLES drawing and should not be considered missing external api
219  void BakeVBO();
220  GlsVertexArray _curve;
221  GlsVertexArray _fill;
222 #endif
223 };
224 
225 } // namespace disti
226 
227 #endif
Definition: cull.h:50
virtual InterfaceListType * GetCppInterfaceDescription(InterfaceListType *addToThisList=NULL)
virtual void SetFillColor(const glsColor &color)
const int MIN_NUMBER_POINTS
Definition: gls_nurb_curve.h:70
virtual DisplayObject * CloneObject(bool generateNames=false)
void GenerateTessellatedVertices(void)
Definition: vertex.h:365
virtual void CalcNormals(int windingOrder=1)
const int MAX_SPLINE_VERTICES
Definition: gls_nurb_curve.h:67
Definition: dynamic_array.h:63
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:289
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1)
Definition: display.h:98
The disti::GLPolygon class. Implements Polygons.
void Scale(float px, float py, float pz, Vertex *a, int handleBar)
The disti::DisplayObject class and global enumerations.
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint)
Vertex * TessVertices()
Definition: gls_nurb_curve.h:143
virtual void SetVertices(unsigned int nPoints, Vertex *vertices)
virtual void DeleteVertex(unsigned int index)
virtual void SetAvailableAttributes(unsigned int availableAttributes)
virtual void VaListSetVertices(unsigned int nPoints, va_list args)
virtual void SetVertexColor(unsigned int index, unsigned char col[])
virtual void CalculateTextureCoordinates(void)
virtual void Rotate(float angle, int axis=Z_AXIS)
virtual void GetCppInterfaceDescriptionFree(InterfaceListType *array)
unsigned int NumberOfTessVertices() const
Definition: gls_nurb_curve.h:138
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler)
The gls_auto_lib.
Definition: gls_color.h:54
virtual void CopyGeometry(DisplayObject *src)
Definition: gls_nurb_curve.h:84
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)
virtual void Draw(void)
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.
Definition: bmpimage.h:46
void SetFillColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Definition: display.h:663
Definition: gls_matrix_affine.h:61