BezFwdIterator.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. #include "PreRTS.h"
  24. #include "Common/BezFwdIterator.h"
  25. //-------------------------------------------------------------------------------------------------
  26. BezFwdIterator::BezFwdIterator(): mStep(0), mStepsDesired(0)
  27. {
  28. // Added by Sadullah Nader
  29. mCurrPoint.zero();
  30. mDDDq.zero();
  31. mDDq.zero();
  32. mDq.zero();
  33. }
  34. //-------------------------------------------------------------------------------------------------
  35. BezFwdIterator::BezFwdIterator(Int stepsDesired, const BezierSegment *bezSeg)
  36. {
  37. // Added by Sadullah Nader
  38. mCurrPoint.zero();
  39. mDDDq.zero();
  40. mDDq.zero();
  41. mDq.zero();
  42. //
  43. mStepsDesired = stepsDesired;
  44. mBezSeg = (*bezSeg);
  45. }
  46. //-------------------------------------------------------------------------------------------------
  47. void BezFwdIterator::start(void)
  48. {
  49. mStep = 0;
  50. if (mStepsDesired <= 1)
  51. return;
  52. float d = 1.0f / (mStepsDesired - 1);
  53. float d2 = d * d;
  54. float d3 = d * d2;
  55. D3DXVECTOR4 px(mBezSeg.m_controlPoints[0].x, mBezSeg.m_controlPoints[1].x, mBezSeg.m_controlPoints[2].x, mBezSeg.m_controlPoints[3].x);
  56. D3DXVECTOR4 py(mBezSeg.m_controlPoints[0].y, mBezSeg.m_controlPoints[1].y, mBezSeg.m_controlPoints[2].y, mBezSeg.m_controlPoints[3].y);
  57. D3DXVECTOR4 pz(mBezSeg.m_controlPoints[0].z, mBezSeg.m_controlPoints[1].z, mBezSeg.m_controlPoints[2].z, mBezSeg.m_controlPoints[3].z);
  58. D3DXVECTOR4 cVec[3];
  59. D3DXVec4Transform(&cVec[0], &px, &BezierSegment::s_bezBasisMatrix);
  60. D3DXVec4Transform(&cVec[1], &py, &BezierSegment::s_bezBasisMatrix);
  61. D3DXVec4Transform(&cVec[2], &pz, &BezierSegment::s_bezBasisMatrix);
  62. mCurrPoint = mBezSeg.m_controlPoints[0];
  63. int i = 3;
  64. while (i--) {
  65. float a = cVec[i].x;
  66. float b = cVec[i].y;
  67. float c = cVec[i].z;
  68. float *pD, *pDD, *pDDD;
  69. if (i == 2) {
  70. pD = &mDq.z;
  71. pDD = &mDDq.z;
  72. pDDD = &mDDDq.z;
  73. } else if (i == 1) {
  74. pD = &mDq.y;
  75. pDD = &mDDq.y;
  76. pDDD = &mDDDq.y;
  77. } else if (i == 0) {
  78. pD = &mDq.x;
  79. pDD = &mDDq.x;
  80. pDDD = &mDDDq.x;
  81. }
  82. (*pD) = a * d3 + b * d2 + c * d;
  83. (*pDD) = 6 * a * d3 + 2 * b * d2;
  84. (*pDDD) = 6 * a * d3;
  85. }
  86. }
  87. //-------------------------------------------------------------------------------------------------
  88. Bool BezFwdIterator::done(void)
  89. {
  90. return (mStep >= mStepsDesired);
  91. }
  92. //-------------------------------------------------------------------------------------------------
  93. const Coord3D& BezFwdIterator::getCurrent(void) const
  94. {
  95. return mCurrPoint;
  96. }
  97. //-------------------------------------------------------------------------------------------------
  98. void BezFwdIterator::next(void)
  99. {
  100. mCurrPoint.add(&mDq);
  101. mDq.add(&mDDq);
  102. mDDq.add(&mDDDq);
  103. ++mStep;
  104. }