| 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/// Automatically link the runtime library plugin (on Windows).
61#define LIB_BASE_NAME "gls_nurb_curve"
62#include "gls_auto_lib.h"
63#undef LIB_BASE_NAME
64
65 namespace disti
66{
67/** Maximum number of tesselated vertices in a spline */
68 const int MAX_SPLINE_VERTICES = 2000;
69
70/** smallest number of control points in a spline */
71 const int MIN_NUMBER_POINTS = 2;
72
73/** When calculating the current vertices, how many control
74 * points should we consider */
75 const int NUMBER_POINTS_TO_CONSIDER = 3;
76
77// SetValue enumerations
78 enum
79{
80 GLS_GLSNURBCURVE_FIRST_VALUE = GLS_LAST_INITIALIZER + 1,
81 GLS_GLSNURBCURVE_EMITEVENT // example
82};
83
84/** Runtime implementation of a GlsNurbCurve */
85 class GlsNurbCurve : public DisplayObject
86{
87 public:
88 DISTI_DEPRECATED( "This identifier is forbidden by the C++ standard. Use BaseClass instead." )
89 typedef DisplayObject _BaseClass; ///< Deprecated typedef for the base class.
90 typedef DisplayObject BaseClass; ///< Typedef for the base class.
91 friend class GlsNurbCurveEditor;
92
93private:
94 // We capture the tesselated vertices from the NURB render function
95 // and store them here, to be used by the draw routine.
96 // This is not to be confused with the editor Tesselator functions.
97 // These are the points that the NURB render function generates to
98 // draw the curve.
99 Vertex* _tesselated_vertices; /** The tesselated vertices, computed from the control points */
100 unsigned int _tesselated_vertices_count; /** The number of tesselated vertices */
101
102 // disabling default implicit assignment and copy constructor
103 GlsNurbCurve& operator=( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
104 GlsNurbCurve( const GlsNurbCurve& ) DISTI_SPECIAL_MEM_FUN_DELETE;
105
106public:
107 /** Creates a NURB Curve with the vertices specified
108 * \param nPoints Number of control points in the NURB
109 * \param vertices An array of allocated vertices
110 * \pre vertices is not NULL
111 */
112 GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int nPoints, Vertex* vertices );
113
114 /// Allocate a (blank) NURB Curve object.
115 /// \param generateInstanceName Whether or not to generate an instance name for this object.
116 GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( bool generateInstanceName = false );
117
118 /** NurbCurve Constructor. Creates a new NURBCurve object with
119 * the number of vertices and vertex data specified.
120 * \param n_points Number of control points in the NURB
121 * \param vertices An array of allocated vertices
122 * \param location Initial location of the NURB
123 */
124 GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( unsigned int n_points, Vertex* vertices, Vertex& location );
125
126 /// Copy constructor
127 /// \param that The object to copy from.
128 /// \param generateNames Whether or not to generate an instance name for this object.
129 GLSGEN_GLSNURBCURVE_EXPORT GlsNurbCurve( const GlsNurbCurve& that, const bool generateNames );
130
131 /** Destructs a GlsNurbCurve object */
132 virtual GLSGEN_GLSNURBCURVE_EXPORT ~GlsNurbCurve();
133
134 /// \return A pointer to a new GlsNurbCurve object.
135 static GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CreateInstance();
136
137 /** Generate a list of vertices describing the NURB curve, save those
138 * vertices in the NURBCurve object for use in drawing.
139 */
140 void GLSGEN_GLSNURBCURVE_EXPORT GenerateTessellatedVertices();
141
142 /** Gets the object's number of Tesselated vertices.
143 * These tesselated vertices are generated by the NURB render function.
144 * \return The number of vertices in the object
145 */
146 unsigned int NumberOfTessVertices() const { return _tesselated_vertices_count; }
147
148 /** Gets the object's tesselated vertices.
149 * \return Pointer the the object's tesselated vertices
150 */
151 Vertex* TessVertices() { return _tesselated_vertices; }
152
153 //////////////////////////////////////////////////
154 // Overridden base class methods
155 //////////////////////////////////////////////////
156
157 virtual GLSGEN_GLSNURBCURVE_EXPORT void SetAvailableAttributes( unsigned int availableAttributes ) DISTI_METHOD_OVERRIDE;
158 virtual GLSGEN_GLSNURBCURVE_EXPORT DisplayObject* CloneObject( bool generateNames = false ) DISTI_METHOD_OVERRIDE;
159 virtual GLSGEN_GLSNURBCURVE_EXPORT void CopyGeometry( DisplayObject* src ) DISTI_METHOD_OVERRIDE;
160
161#ifndef GLES
162 virtual GLSGEN_GLSNURBCURVE_EXPORT InterfaceListType* GetCppInterfaceDescription( InterfaceListType* addToThisList = NULL ) DISTI_METHOD_OVERRIDE;
163 virtual GLSGEN_GLSNURBCURVE_EXPORT void GetCppInterfaceDescriptionFree( InterfaceListType* array ) DISTI_METHOD_OVERRIDE;
164#endif
165
166 virtual GLSGEN_GLSNURBCURVE_EXPORT void PreDraw( const OpenGLMatrices& parentMatrices, Culler& culler ) DISTI_METHOD_OVERRIDE;
167 virtual GLSGEN_GLSNURBCURVE_EXPORT void Draw() DISTI_METHOD_OVERRIDE;
168 virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertices( unsigned int nPoints, Vertex* vertices ) DISTI_METHOD_OVERRIDE;
169 virtual GLSGEN_GLSNURBCURVE_EXPORT void VaListSetVertices( unsigned int nPoints, va_list args ) DISTI_METHOD_OVERRIDE;
170
171 /* Unhides base class implementation. */
172 using BaseClass::Scale;
173 GLSGEN_GLSNURBCURVE_EXPORT void Scale( float px, float py, float pz, Vertex* a, int handleBar ) DISTI_METHOD_OVERRIDE;
174
175 virtual GLSGEN_GLSNURBCURVE_EXPORT void CalculateTextureCoordinates() DISTI_METHOD_OVERRIDE;
176
177 /* Unhides base class implementation. */
178 using BaseClass::Rotate;
179 virtual GLSGEN_GLSNURBCURVE_EXPORT void Rotate( const Vector& orig, float angle, const Vector& axis ) DISTI_METHOD_OVERRIDE;
180
181 virtual GLSGEN_GLSNURBCURVE_EXPORT void GetExtents( float& x, float& y, float& z, float& x1, float& y1, float& z1 ) DISTI_METHOD_OVERRIDE;
182 virtual GLSGEN_GLSNURBCURVE_EXPORT void GetTransformedExtents( Vector& min, Vector& max, const GlsMatrixType& matrix, bool resetMinMax = true ) DISTI_METHOD_OVERRIDE;
183 virtual GLSGEN_GLSNURBCURVE_EXPORT bool Hit( float x, float y, float z, float scale, const Vector& directionVector, Vector* collisionPoint ) DISTI_METHOD_OVERRIDE;
184
185 GLSGEN_GLSNURBCURVE_EXPORT void DeleteVertexAt( unsigned int index ) DISTI_METHOD_OVERRIDE;
186 virtual GLSGEN_GLSNURBCURVE_EXPORT void SetVertexColor( unsigned int index, unsigned char col[] ) DISTI_METHOD_OVERRIDE;
187
188 /* Unhides base class implementation. */
189 using BaseClass::SetFillColor;
190 virtual GLSGEN_GLSNURBCURVE_EXPORT void SetFillColor( const GlsColor& color ) DISTI_METHOD_OVERRIDE;
191
192 /// Calculates normals based on the vertices and the specified winding order.
193 /// \param windingOrder If less than zero, all normals will be mirrored (*= -1.0f).
194 virtual GLSGEN_GLSNURBCURVE_EXPORT void CalcNormals( int windingOrder = 1 );
195
196 /// Create a spline from a set of control points. Return the vertices, so that the user can draw the spline as they wish.
197 /// \param num_vertices The number of control points to make a spline out of.
198 /// \param vertices The control points.
199 /// \param curve_array_size Originally the size of the curve array.
200 /// \param curve_array The actually used size is returned here.
201 GLSGEN_GLSNURBCURVE_EXPORT void GenerateSpline( unsigned int num_vertices, Vertex* vertices, unsigned int* curve_array_size, Vertex* curve_array );
202
203protected:
204#ifdef GLES
205 /// BakeVBO is a helper function only used for GLES drawing and should not be considered missing external api
206 void BakeVBO();
207 GlsVertexArray _curve; ///< The geometric object composed of a list of vertices for rendering.
208 GlsVertexArray _fill; ///< Tesselated vertices used to fill in color.
209#endif
210};
211
212} // namespace disti
213
214#endif
disti::Culler
Definition: cull.h:50
disti::DisplayObject
Definition: display.h:96
disti::DynamicArray
Definition: dynamic_array.h:79
disti::GlsColor
Definition: gls_color.h:54
disti::GlsMatrixAffine< double >
disti::GlsNurbCurve
Definition: gls_nurb_curve.h:86
disti::GlsNurbCurve::CalculateTextureCoordinates
virtual void CalculateTextureCoordinates() DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::SetAvailableAttributes
virtual void SetAvailableAttributes(unsigned int availableAttributes) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::_fill
GlsVertexArray _fill
Tesselated vertices used to fill in color.
Definition: gls_nurb_curve.h:208
disti::GlsNurbCurve::Draw
virtual void Draw() DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::GetTransformedExtents
virtual void GetTransformedExtents(Vector &min, Vector &max, const GlsMatrixType &matrix, bool resetMinMax=true) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::CloneObject
virtual DisplayObject * CloneObject(bool generateNames=false) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::VaListSetVertices
virtual void VaListSetVertices(unsigned int nPoints, va_list args) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::Hit
virtual bool Hit(float x, float y, float z, float scale, const Vector &directionVector, Vector *collisionPoint) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::PreDraw
virtual void PreDraw(const OpenGLMatrices &parentMatrices, Culler &culler) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::DeleteVertexAt
void DeleteVertexAt(unsigned int index) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::Scale
void Scale(float px, float py, float pz, Vertex *a, int handleBar) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::NumberOfTessVertices
unsigned int NumberOfTessVertices() const
Definition: gls_nurb_curve.h:146
disti::GlsNurbCurve::Rotate
virtual void Rotate(const Vector &orig, float angle, const Vector &axis) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::GenerateTessellatedVertices
void GenerateTessellatedVertices()
disti::GlsNurbCurve::CalcNormals
virtual void CalcNormals(int windingOrder=1)
disti::GlsNurbCurve::CreateInstance
static DisplayObject * CreateInstance()
disti::GlsNurbCurve::CopyGeometry
virtual void CopyGeometry(DisplayObject *src) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::SetVertices
virtual void SetVertices(unsigned int nPoints, Vertex *vertices) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::_curve
GlsVertexArray _curve
The geometric object composed of a list of vertices for rendering.
Definition: gls_nurb_curve.h:207
disti::GlsNurbCurve::BakeVBO
void BakeVBO()
BakeVBO is a helper function only used for GLES drawing and should not be considered missing external...
disti::GlsNurbCurve::TessVertices
Vertex * TessVertices()
Definition: gls_nurb_curve.h:151
disti::GlsNurbCurve::SetVertexColor
virtual void SetVertexColor(unsigned int index, unsigned char col[]) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::GetExtents
virtual void GetExtents(float &x, float &y, float &z, float &x1, float &y1, float &z1) DISTI_METHOD_OVERRIDE
disti::GlsNurbCurve::GenerateSpline
void GenerateSpline(unsigned int num_vertices, Vertex *vertices, unsigned int *curve_array_size, Vertex *curve_array)
disti::GlsNurbCurve::SetFillColor
virtual void SetFillColor(const GlsColor &color) DISTI_METHOD_OVERRIDE
disti::GlsVertexArray
Definition: gls_vertex_array.h:60
disti::OpenGLMatrices
Class to contain current OpenGL view, projection and draw matrices.
Definition: util.h:544
disti::VertexNoColor
Definition: vertex.h:85
disti::Vertex
Definition: vertex.h:420
display.h
The disti::DisplayObject class and global enumerations.
glpolygon.h
The disti::GLPolygon class. Implements Polygons.
gls_auto_lib.h
The gls_auto_lib.
gls_cpp_lang_support.h
Macros and helper code to determine what subset of C++11/14/17 is available.
DISTI_SPECIAL_MEM_FUN_DELETE
#define DISTI_SPECIAL_MEM_FUN_DELETE
Macro to wrap function deletion, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:246
DISTI_DEPRECATED
#define DISTI_DEPRECATED(msg)
Defines whether this compiler supports the C++14 deprecated attribute.
Definition: gls_cpp_lang_support.h:488
DISTI_METHOD_OVERRIDE
#define DISTI_METHOD_OVERRIDE
Macro to wrap the override keyword, removed on compilers that don't support it.
Definition: gls_cpp_lang_support.h:222
GLSGEN_GLSNURBCURVE_EXPORT
#define GLSGEN_GLSNURBCURVE_EXPORT
Provides support for creating DLLs.
Definition: gls_nurb_curve.h:56
disti
Definition: bmpimage.h:47
disti::MAX_SPLINE_VERTICES
const int MAX_SPLINE_VERTICES
Definition: gls_nurb_curve.h:68
disti::NUMBER_POINTS_TO_CONSIDER
const int NUMBER_POINTS_TO_CONSIDER
Definition: gls_nurb_curve.h:75
disti::MIN_NUMBER_POINTS
const int MIN_NUMBER_POINTS
Definition: gls_nurb_curve.h:71