llxform.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @file llxform.cpp
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewergpl$
  5. *
  6. * Copyright (c) 2001-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #include "linden_common.h"
  32. #include "llxform.h"
  33. LLXform::LLXform() noexcept
  34. {
  35. init();
  36. }
  37. void LLXform::init()
  38. {
  39. mParent = NULL;
  40. mChanged = UNCHANGED;
  41. mPosition.clear();
  42. mRotation.loadIdentity();
  43. mScale.set(1.f, 1.f, 1.f);
  44. mWorldPosition.clear();
  45. mWorldRotation.loadIdentity();
  46. mIsAvatar = false;
  47. mScaleChildOffset = false;
  48. }
  49. // Link optimization: do not inline these llwarns
  50. LL_NO_INLINE void LLXform::warn(U32 idx)
  51. {
  52. const char* msg;
  53. switch (idx)
  54. {
  55. case 0:
  56. msg = "Non Finite in LLXform::setPosition(LLVector3)";
  57. break;
  58. case 1:
  59. msg = "Non Finite in LLXform::setPosition(F32, F32, F32)";
  60. break;
  61. case 2:
  62. msg = "Non Finite in LLXform::setPositionX(F32)";
  63. break;
  64. case 3:
  65. msg = "Non Finite in LLXform::setPositionY(F32)";
  66. break;
  67. case 4:
  68. msg = "Non Finite in LLXform::setPositionZ(F32)";
  69. break;
  70. case 5:
  71. msg = "Non Finite in LLXform::addPosition(LLVector3)";
  72. break;
  73. case 6:
  74. msg = "Non Finite in LLXform::setScale(LLVector3)";
  75. break;
  76. case 7:
  77. msg = "Non Finite in LLXform::setScale(F32, F32, F32)";
  78. break;
  79. case 8:
  80. msg = "Non Finite in LLXform::setRotation(LLQuaternion)";
  81. break;
  82. case 9:
  83. msg = "Non Finite in LLXform::setRotation(F32, F32, F32)";
  84. break;
  85. case 10:
  86. msg = "Non Finite in LLXform::setRotation(F32, F32, F32, F32)";
  87. break;
  88. default:
  89. msg = NULL;
  90. llerrs << "Please, update warn() messages..." << llendl;
  91. }
  92. llwarns << msg << llendl;
  93. }
  94. LLXform* LLXform::getRoot() const
  95. {
  96. const LLXform* root = this;
  97. while (root->mParent)
  98. {
  99. root = root->mParent;
  100. }
  101. return (LLXform*)root;
  102. }
  103. LLXformMatrix::LLXformMatrix()
  104. : LLXform()
  105. {
  106. }
  107. void LLXformMatrix::init()
  108. {
  109. mWorldMatrix.setIdentity();
  110. mMin.clear();
  111. mMax.clear();
  112. LLXform::init();
  113. }
  114. void LLXformMatrix::update()
  115. {
  116. if (mParent)
  117. {
  118. mWorldPosition = mPosition;
  119. if (mParent->getScaleChildOffset())
  120. {
  121. mWorldPosition.scaleVec(mParent->getScale());
  122. }
  123. mWorldPosition *= mParent->getWorldRotation();
  124. mWorldPosition += mParent->getWorldPosition();
  125. mWorldRotation = mRotation * mParent->getWorldRotation();
  126. }
  127. else
  128. {
  129. mWorldPosition = mPosition;
  130. mWorldRotation = mRotation;
  131. }
  132. }
  133. void LLXformMatrix::updateMatrix(bool update_bounds)
  134. {
  135. update();
  136. mWorldMatrix.initAll(mScale, mWorldRotation, mWorldPosition);
  137. if (update_bounds && (mChanged & MOVED))
  138. {
  139. mMin.mV[0] = mMax.mV[0] = mWorldMatrix.mMatrix[3][0];
  140. mMin.mV[1] = mMax.mV[1] = mWorldMatrix.mMatrix[3][1];
  141. mMin.mV[2] = mMax.mV[2] = mWorldMatrix.mMatrix[3][2];
  142. F32 f0 = (fabs(mWorldMatrix.mMatrix[0][0]) +
  143. fabs(mWorldMatrix.mMatrix[1][0]) +
  144. fabs(mWorldMatrix.mMatrix[2][0])) * 0.5f;
  145. F32 f1 = (fabs(mWorldMatrix.mMatrix[0][1]) +
  146. fabs(mWorldMatrix.mMatrix[1][1]) +
  147. fabs(mWorldMatrix.mMatrix[2][1])) * 0.5f;
  148. F32 f2 = (fabs(mWorldMatrix.mMatrix[0][2]) +
  149. fabs(mWorldMatrix.mMatrix[1][2]) +
  150. fabs(mWorldMatrix.mMatrix[2][2])) * 0.5f;
  151. mMin.mV[0] -= f0;
  152. mMin.mV[1] -= f1;
  153. mMin.mV[2] -= f2;
  154. mMax.mV[0] += f0;
  155. mMax.mV[1] += f1;
  156. mMax.mV[2] += f2;
  157. }
  158. }