Vector4.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * @author supereggbert / http://www.paulbrunt.co.uk/
  3. * @author philogb / http://blog.thejit.org/
  4. * @author mikael emtinger / http://gomo.se/
  5. */
  6. THREE.Vector4 = function ( x, y, z, w ) {
  7. this.set(
  8. x || 0,
  9. y || 0,
  10. z || 0,
  11. w || 1
  12. );
  13. };
  14. THREE.Vector4.prototype = {
  15. set : function ( x, y, z, w ) {
  16. this.x = x;
  17. this.y = y;
  18. this.z = z;
  19. this.w = w;
  20. return this;
  21. },
  22. copy : function ( v ) {
  23. this.set(
  24. v.x,
  25. v.y,
  26. v.z,
  27. v.w || 1.0
  28. );
  29. return this;
  30. },
  31. add : function ( v1, v2 ) {
  32. this.set(
  33. v1.x + v2.x,
  34. v1.y + v2.y,
  35. v1.z + v2.z,
  36. v1.w + v2.w
  37. );
  38. return this;
  39. },
  40. addSelf : function ( v ) {
  41. this.set(
  42. this.x + v.x,
  43. this.y + v.y,
  44. this.z + v.z,
  45. this.w + v.w
  46. );
  47. return this;
  48. },
  49. sub : function ( v1, v2 ) {
  50. this.set(
  51. v1.x - v2.x,
  52. v1.y - v2.y,
  53. v1.z - v2.z,
  54. v1.w - v2.w
  55. );
  56. return this;
  57. },
  58. subSelf : function ( v ) {
  59. this.set(
  60. this.x - v.x,
  61. this.y - v.y,
  62. this.z - v.z,
  63. this.w - v.w
  64. );
  65. return this;
  66. },
  67. multiplyScalar : function ( s ) {
  68. this.set(
  69. this.x * s,
  70. this.y * s,
  71. this.z * s,
  72. this.w * s
  73. );
  74. return this;
  75. },
  76. divideScalar : function ( s ) {
  77. this.set(
  78. this.x / s,
  79. this.y / s,
  80. this.z / s,
  81. this.w / s
  82. );
  83. return this;
  84. },
  85. lerpSelf : function ( v, alpha ) {
  86. this.set(
  87. this.x + (v.x - this.x) * alpha,
  88. this.y + (v.y - this.y) * alpha,
  89. this.z + (v.z - this.z) * alpha,
  90. this.w + (v.w - this.w) * alpha
  91. );
  92. },
  93. clone : function () {
  94. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  95. }
  96. };