d3dvec.inl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C) 2000 Ove Kaaven
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __WINE_D3DVEC_INL
  19. #define __WINE_D3DVEC_INL
  20. /*** constructors ***/
  21. inline _D3DVECTOR::_D3DVECTOR(D3DVALUE f)
  22. {
  23. x = y = z = f;
  24. }
  25. inline _D3DVECTOR::_D3DVECTOR(D3DVALUE _x, D3DVALUE _y, D3DVALUE _z)
  26. {
  27. x = _x; y = _y; z = _z;
  28. }
  29. /*** assignment operators ***/
  30. inline _D3DVECTOR& _D3DVECTOR::operator += (const _D3DVECTOR& v)
  31. {
  32. x += v.x; y += v.y; z += v.z;
  33. return *this;
  34. }
  35. inline _D3DVECTOR& _D3DVECTOR::operator -= (const _D3DVECTOR& v)
  36. {
  37. x -= v.x; y -= v.y; z -= v.z;
  38. return *this;
  39. }
  40. inline _D3DVECTOR& _D3DVECTOR::operator *= (const _D3DVECTOR& v)
  41. {
  42. x *= v.x; y *= v.y; z *= v.z;
  43. return *this;
  44. }
  45. inline _D3DVECTOR& _D3DVECTOR::operator /= (const _D3DVECTOR& v)
  46. {
  47. x /= v.x; y /= v.y; z /= v.z;
  48. return *this;
  49. }
  50. inline _D3DVECTOR& _D3DVECTOR::operator *= (D3DVALUE s)
  51. {
  52. x *= s; y *= s; z *= s;
  53. return *this;
  54. }
  55. inline _D3DVECTOR& _D3DVECTOR::operator /= (D3DVALUE s)
  56. {
  57. x /= s; y /= s; z /= s;
  58. return *this;
  59. }
  60. /*** unary operators ***/
  61. inline _D3DVECTOR operator + (const _D3DVECTOR& v)
  62. {
  63. return v;
  64. }
  65. inline _D3DVECTOR operator - (const _D3DVECTOR& v)
  66. {
  67. return _D3DVECTOR(-v.x, -v.y, -v.z);
  68. }
  69. /*** binary operators ***/
  70. inline _D3DVECTOR operator + (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
  71. {
  72. return _D3DVECTOR(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
  73. }
  74. inline _D3DVECTOR operator - (const _D3DVECTOR& v1, const _D3DVECTOR& v2)
  75. {
  76. return _D3DVECTOR(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
  77. }
  78. inline _D3DVECTOR operator * (const _D3DVECTOR& v, D3DVALUE s)
  79. {
  80. return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
  81. }
  82. inline _D3DVECTOR operator * (D3DVALUE s, const _D3DVECTOR& v)
  83. {
  84. return _D3DVECTOR(v.x*s, v.y*s, v.z*s);
  85. }
  86. inline _D3DVECTOR operator / (const _D3DVECTOR& v, D3DVALUE s)
  87. {
  88. return _D3DVECTOR(v.x/s, v.y/s, v.z/s);
  89. }
  90. inline D3DVALUE SquareMagnitude(const _D3DVECTOR& v)
  91. {
  92. return v.x*v.x + v.y*v.y + v.z*v.z; /* DotProduct(v, v) */
  93. }
  94. inline D3DVALUE Magnitude(const _D3DVECTOR& v)
  95. {
  96. return sqrt(SquareMagnitude(v));
  97. }
  98. inline _D3DVECTOR Normalize(const _D3DVECTOR& v)
  99. {
  100. return v / Magnitude(v);
  101. }
  102. inline D3DVALUE DotProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
  103. {
  104. return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  105. }
  106. inline _D3DVECTOR CrossProduct(const _D3DVECTOR& v1, const _D3DVECTOR& v2)
  107. {
  108. _D3DVECTOR res;
  109. /* this is a left-handed cross product, right? */
  110. res.x = v1.y * v2.z - v1.z * v2.y;
  111. res.y = v1.z * v2.x - v1.x * v2.z;
  112. res.z = v1.x * v2.y - v1.y * v2.x;
  113. return res;
  114. }
  115. #endif