splineUtil.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _SPLINEUTIL_H_
  23. #define _SPLINEUTIL_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _MPOINT_H_
  28. #include "math/mPoint.h"
  29. #endif
  30. #ifndef _MSPLINEPATCH_H_
  31. #include "math/mSplinePatch.h"
  32. #endif
  33. #ifndef _COLOR_H_
  34. #include "graphics/gColor.h"
  35. #endif
  36. /// Spline utility namespace. This is used for generating pretty splines so you can get nice curved surfaces.
  37. /// However, many polygons are required, so use these only when needed.
  38. namespace SplineUtil
  39. {
  40. /// All the info that is needed to define a spline. This is optional for actually drawing a spline
  41. /// @see drawSplineBeam
  42. struct SplineBeamInfo
  43. {
  44. Point3F * camPos;
  45. U32 numSegments;
  46. F32 width;
  47. SplinePatch * spline;
  48. /// Offset for u/v texture coordinates, useful for animating the texture on the spline
  49. F32 uvOffset;
  50. /// Stretch for texture
  51. F32 numTexRep;
  52. ColorF color;
  53. bool zeroAlphaStart; ///< first part of first segment has 0 alpha value
  54. SplineBeamInfo()
  55. {
  56. dMemset( this, 0, sizeof( SplineBeamInfo ) );
  57. numTexRep = 1.0;
  58. }
  59. };
  60. /// Function for drawing the spline.
  61. ///
  62. /// Use this if you only have a SplinePatch object and want to specify all of the parameters
  63. ///
  64. /// @param camPos This parameter is the point at which each polygon will face.
  65. ///
  66. /// Usually, you want all of the polygons of the spline to be facing the
  67. /// camera, so the camera pos is a good bet for this parameter.
  68. ///
  69. /// @param numSegments The SplineUtil will cut up the spline into numSegments segments.
  70. ///
  71. /// More segments means more smoothness, but less framerate.
  72. ///
  73. /// @param width The width of the spline beam.
  74. ///
  75. /// @param spline The SplinePatch data structure for the given spline beam.
  76. ///
  77. /// @see SplinePatch
  78. ///
  79. /// @param uvOffset This should be called textureOffset, since it is only
  80. /// an offset along the spline and not perpendicular. This parameter
  81. /// can be used for "sliding" the spline texture down the spline shaft
  82. /// to make it a little more dynamic.
  83. ///
  84. /// @param numTexRep This is the scale of the texture so you can squish or stretch it.
  85. void drawSplineBeam( const Point3F& camPos, U32 numSegments, F32 width,
  86. SplinePatch &spline, F32 uvOffset = 0.0, F32 numTexRep = 1.0 );
  87. /// Function for drawing a spline. Only needs SplineBeamInfo.
  88. /// @see SplineBeamInfo
  89. void drawSplineBeam( SplineBeamInfo &sbi );
  90. }
  91. #endif