mSplinePatch.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #include "math/mSplinePatch.h"
  23. //******************************************************************************
  24. // Spline control points
  25. //******************************************************************************
  26. SplCtrlPts::SplCtrlPts()
  27. {
  28. }
  29. //------------------------------------------------------------------------------
  30. // Destructor
  31. //------------------------------------------------------------------------------
  32. SplCtrlPts::~SplCtrlPts()
  33. {
  34. }
  35. //------------------------------------------------------------------------------
  36. // Get point
  37. //------------------------------------------------------------------------------
  38. const Point3F * SplCtrlPts::getPoint( U32 pointNum )
  39. {
  40. return &mPoints[pointNum];
  41. }
  42. //------------------------------------------------------------------------------
  43. // Set point
  44. //------------------------------------------------------------------------------
  45. void SplCtrlPts::setPoint( Point3F &point, U32 pointNum )
  46. {
  47. mPoints[pointNum] = point;
  48. }
  49. //------------------------------------------------------------------------------
  50. // Add point
  51. //------------------------------------------------------------------------------
  52. void SplCtrlPts::addPoint( Point3F &point )
  53. {
  54. mPoints.push_back( point );
  55. }
  56. //------------------------------------------------------------------------------
  57. // Submit control points
  58. //------------------------------------------------------------------------------
  59. void SplCtrlPts::submitPoints( Point3F *pts, U32 num )
  60. {
  61. mPoints.clear();
  62. for( S32 i=0; i<num; i++ )
  63. {
  64. mPoints.push_back( pts[i] );
  65. }
  66. }
  67. //******************************************************************************
  68. // Spline patch - base class
  69. //******************************************************************************
  70. SplinePatch::SplinePatch()
  71. {
  72. mNumReqControlPoints = 0;
  73. }
  74. //------------------------------------------------------------------------------
  75. // This method is the only way to modify control points once they have been
  76. // submitted to the patch. This was done to make sure the patch has a chance
  77. // to re-calc any pre-calculated data it may be using from the submitted control
  78. // points.
  79. //------------------------------------------------------------------------------
  80. void SplinePatch::setControlPoint( Point3F &point, S32 index )
  81. {
  82. mControlPoints.setPoint( point, index );
  83. }
  84. //------------------------------------------------------------------------------
  85. // Calc point on spline using already submitted points
  86. //------------------------------------------------------------------------------
  87. void SplinePatch::calc( F32 /*t*/, Point3F &result )
  88. {
  89. result.x = result.y = result.z = 0.0f;
  90. }
  91. //------------------------------------------------------------------------------
  92. // Calc point on spline using passed-in points
  93. //------------------------------------------------------------------------------
  94. void SplinePatch::calc( Point3F * /*points*/, F32 /*t*/, Point3F &result )
  95. {
  96. result.x = result.y = result.z = 0.0f;
  97. }