/indra/llmath/xform.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 119 lines · 77 code · 17 blank · 25 comment · 5 complexity · 5fbd19e7c2224129287eeb145769514c MD5 · raw file

  1. /**
  2. * @file xform.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #include "linden_common.h"
  26. #include "xform.h"
  27. LLXform::LLXform()
  28. {
  29. init();
  30. }
  31. LLXform::~LLXform()
  32. {
  33. }
  34. // Link optimization - don't inline these llwarns
  35. void LLXform::warn(const char* const msg)
  36. {
  37. llwarns << msg << llendl;
  38. }
  39. LLXform* LLXform::getRoot() const
  40. {
  41. const LLXform* root = this;
  42. while(root->mParent)
  43. {
  44. root = root->mParent;
  45. }
  46. return (LLXform*)root;
  47. }
  48. BOOL LLXform::isRoot() const
  49. {
  50. return (!mParent);
  51. }
  52. BOOL LLXform::isRootEdit() const
  53. {
  54. return (!mParent);
  55. }
  56. LLXformMatrix::~LLXformMatrix()
  57. {
  58. }
  59. void LLXformMatrix::update()
  60. {
  61. if (mParent)
  62. {
  63. mWorldPosition = mPosition;
  64. if (mParent->getScaleChildOffset())
  65. {
  66. mWorldPosition.scaleVec(mParent->getScale());
  67. }
  68. mWorldPosition *= mParent->getWorldRotation();
  69. mWorldPosition += mParent->getWorldPosition();
  70. mWorldRotation = mRotation * mParent->getWorldRotation();
  71. }
  72. else
  73. {
  74. mWorldPosition = mPosition;
  75. mWorldRotation = mRotation;
  76. }
  77. }
  78. void LLXformMatrix::updateMatrix(BOOL update_bounds)
  79. {
  80. update();
  81. mWorldMatrix.initAll(mScale, mWorldRotation, mWorldPosition);
  82. if (update_bounds && (mChanged & MOVED))
  83. {
  84. mMin.mV[0] = mMax.mV[0] = mWorldMatrix.mMatrix[3][0];
  85. mMin.mV[1] = mMax.mV[1] = mWorldMatrix.mMatrix[3][1];
  86. mMin.mV[2] = mMax.mV[2] = mWorldMatrix.mMatrix[3][2];
  87. F32 f0 = (fabs(mWorldMatrix.mMatrix[0][0])+fabs(mWorldMatrix.mMatrix[1][0])+fabs(mWorldMatrix.mMatrix[2][0])) * 0.5f;
  88. F32 f1 = (fabs(mWorldMatrix.mMatrix[0][1])+fabs(mWorldMatrix.mMatrix[1][1])+fabs(mWorldMatrix.mMatrix[2][1])) * 0.5f;
  89. F32 f2 = (fabs(mWorldMatrix.mMatrix[0][2])+fabs(mWorldMatrix.mMatrix[1][2])+fabs(mWorldMatrix.mMatrix[2][2])) * 0.5f;
  90. mMin.mV[0] -= f0;
  91. mMin.mV[1] -= f1;
  92. mMin.mV[2] -= f2;
  93. mMax.mV[0] += f0;
  94. mMax.mV[1] += f1;
  95. mMax.mV[2] += f2;
  96. }
  97. }
  98. void LLXformMatrix::getMinMax(LLVector3& min, LLVector3& max) const
  99. {
  100. min = mMin;
  101. max = mMax;
  102. }