mSplinePatch.h

Engine/source/math/mSplinePatch.h

More...

Classes:

class

Class for spline control points.

class

Base class for spline patches.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _MSPLINEPATCH_H_
 25#define _MSPLINEPATCH_H_
 26
 27#ifndef _PLATFORM_H_
 28#include "platform/platform.h"
 29#endif
 30#ifndef _MPOINT3_H_
 31#include "math/mPoint3.h"
 32#endif
 33#ifndef _TVECTOR_H_
 34#include "core/util/tVector.h"
 35#endif
 36
 37//------------------------------------------------------------------------------
 38// Spline control points
 39//------------------------------------------------------------------------------
 40
 41/// Class for spline control points.
 42/// @see SplinePatch
 43class SplCtrlPts
 44{
 45private:
 46   /// Vector of points in the spline
 47   Vector <Point3F> mPoints;
 48
 49public:
 50
 51   SplCtrlPts();
 52   virtual ~SplCtrlPts();
 53
 54   /// Gets the number of points in the spline
 55   U32               getNumPoints(){ return mPoints.size(); }
 56   /// Gets the point at the given index
 57   /// @param pointNum index of the point in question
 58   const Point3F *   getPoint( U32 pointNum );
 59   /// Sets a point at the given index to the point given
 60   /// @param point New value for the given point
 61   /// @param pointNum index of the given point
 62   void              setPoint( Point3F &point, U32 pointNum );
 63   /// Adds a point to the end of the spline
 64   /// @param point New point to be added
 65   void              addPoint( Point3F &point );
 66   /// Clears existing points and enters new points
 67   /// @param pts List of points to be added
 68   /// @param num Number of points to be added
 69   void              submitPoints( Point3F *pts, U32 num );
 70};
 71
 72//------------------------------------------------------------------------------
 73// Base class for spline patches
 74//------------------------------------------------------------------------------
 75
 76/// Base class for spline patches.  The only child of this class is QuadPatch.
 77///
 78/// Spline utility class for drawing nice pretty splines.  In order to draw a spline,
 79/// you need to create a SplCtrlPts data structure, which contains all control
 80/// points on the spline.  See SplCtrlPts for more information on how to submit
 81/// points to the spline utility.  Next, submit the SplCtrlPts structure to the
 82/// spline utility.
 83/// @code
 84/// SplinePatch patch;
 85/// patch.submitControlPoints(ctrlPts);
 86/// @endcode
 87/// Next, use the SplineUtil namespace to draw your spline.
 88/// @code
 89/// SplineUtil::drawSplineBeam(camPos, numSegments, width, patch[, uvOffset, numTexRep]);
 90/// @endcode
 91///
 92/// You can also create a SplineBeamInfo structure (SplineUtil::SplineBeamInfo)
 93/// and just pass the SplineBeamInfo structure to the SplineUtil::drawSplineBeam function.
 94/// @see SplCtrlPts
 95/// @see SplineUtil
 96class SplinePatch
 97{
 98private:
 99   U32         mNumReqControlPoints;
100   SplCtrlPts  mControlPoints;
101
102protected:
103   void     setNumReqControlPoints( U32 numPts ){ mNumReqControlPoints = numPts; }
104
105public:
106
107   SplinePatch();
108
109   U32                  getNumReqControlPoints(){ return mNumReqControlPoints; }
110   const SplCtrlPts *   getControlPoints(){ return &mControlPoints; }
111   const Point3F *      getControlPoint( U32 index ){ return mControlPoints.getPoint( index ); }
112
113   // virtuals
114   virtual void         setControlPoint( Point3F &point, S32 index );
115   /// If you have a preconstructed "SplCtrlPts" class, submit it with this function.
116   /// @see SplCtrlPts
117   virtual void         submitControlPoints( SplCtrlPts &points ){ mControlPoints = points; }
118   /// Recalc function.  Do not call this ever - only SplineUtil needs this.
119   /// @see SplineUtil
120   virtual void         calc( F32 t, Point3F &result) = 0;
121   /// Recalc function.  Do not call this ever - only SplineUtil needs this.
122   /// @see SplineUtil
123   virtual void         calc( Point3F *points, F32 t, Point3F &result ) = 0;
124
125};
126
127
128#endif
129