Vec4.inl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/Mat4.h"
  16. #include "math/Vec4.h"
  17. NS_CC_MATH_BEGIN
  18. inline Vec4 Vec4::operator+(const Vec4& v) const
  19. {
  20. Vec4 result(*this);
  21. result.add(v);
  22. return result;
  23. }
  24. inline Vec4& Vec4::operator+=(const Vec4& v)
  25. {
  26. add(v);
  27. return *this;
  28. }
  29. inline Vec4 Vec4::operator-(const Vec4& v) const
  30. {
  31. Vec4 result(*this);
  32. result.subtract(v);
  33. return result;
  34. }
  35. inline Vec4& Vec4::operator-=(const Vec4& v)
  36. {
  37. subtract(v);
  38. return *this;
  39. }
  40. inline Vec4 Vec4::operator-() const
  41. {
  42. Vec4 result(*this);
  43. result.negate();
  44. return result;
  45. }
  46. inline Vec4 Vec4::operator*(float s) const
  47. {
  48. Vec4 result(*this);
  49. result.scale(s);
  50. return result;
  51. }
  52. inline Vec4& Vec4::operator*=(float s)
  53. {
  54. scale(s);
  55. return *this;
  56. }
  57. inline Vec4 Vec4::operator/(const float s) const
  58. {
  59. return Vec4(this->x / s, this->y / s, this->z / s, this->w / s);
  60. }
  61. inline bool Vec4::operator<(const Vec4& v) const
  62. {
  63. if (x == v.x)
  64. {
  65. if (y == v.y)
  66. {
  67. if (z == v.z)
  68. {
  69. if (w < v.w)
  70. {
  71. return w < v.w;
  72. }
  73. }
  74. return z < v.z;
  75. }
  76. return y < v.y;
  77. }
  78. return x < v.x;
  79. }
  80. inline bool Vec4::operator==(const Vec4& v) const
  81. {
  82. return x==v.x && y==v.y && z==v.z && w==v.w;
  83. }
  84. inline bool Vec4::operator!=(const Vec4& v) const
  85. {
  86. return x!=v.x || y!=v.y || z!=v.z || w!=v.w;
  87. }
  88. inline Vec4 operator*(float x, const Vec4& v)
  89. {
  90. Vec4 result(v);
  91. result.scale(x);
  92. return result;
  93. }
  94. NS_CC_MATH_END