mSplinePatch.h 4.8 KB

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