Quaternion.inl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. Copyright 2013 BlackBerry Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. Original file from GamePlay3D: http://gameplay3d.org
  13. This file was modified to fit the cocos2d-x project
  14. */
  15. #include "math/Quaternion.h"
  16. NS_CC_MATH_BEGIN
  17. inline Quaternion Quaternion::operator*(const Quaternion& q) const
  18. {
  19. Quaternion result(*this);
  20. result.multiply(q);
  21. return result;
  22. }
  23. inline Quaternion& Quaternion::operator*=(const Quaternion& q)
  24. {
  25. multiply(q);
  26. return *this;
  27. }
  28. inline Vec3 Quaternion::operator*(const Vec3& v) const
  29. {
  30. Vec3 uv, uuv;
  31. Vec3 qvec(x, y, z);
  32. Vec3::cross(qvec, v, &uv);
  33. Vec3::cross(qvec, uv, &uuv);
  34. uv *= (2.0f * w);
  35. uuv *= 2.0f;
  36. return v + uv + uuv;
  37. }
  38. NS_CC_MATH_END