e3f1afe537de50bf0eba741ab5b609b1acaf70c2.svn-base 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. if (!dojo._hasResource["dojox.gfx3d.vector"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.gfx3d.vector"] = true;
  6. dojo.provide("dojox.gfx3d.vector");
  7. dojo.mixin(dojox.gfx3d.vector, {
  8. sum : function() {
  9. // summary: sum of the vectors
  10. var v = {
  11. x : 0,
  12. y : 0,
  13. z : 0
  14. };
  15. dojo.forEach(arguments, function(item) {
  16. v.x += item.x;
  17. v.y += item.y;
  18. v.z += item.z;
  19. });
  20. return v;
  21. },
  22. center : function() {
  23. // summary: center of the vectors
  24. var l = arguments.length;
  25. if (l == 0) {
  26. return {
  27. x : 0,
  28. y : 0,
  29. z : 0
  30. };
  31. }
  32. var v = dojox.gfx3d.vector.sum(arguments);
  33. return {
  34. x : v.x / l,
  35. y : v.y / l,
  36. z : v.z / l
  37. };
  38. },
  39. substract : function(/* Pointer */a, /* Pointer */b) {
  40. return {
  41. x : a.x - b.x,
  42. y : a.y - b.y,
  43. z : a.z - b.z
  44. };
  45. },
  46. _crossProduct : function(x, y, z, u, v, w) {
  47. // summary: applies a cross product of two vectorss, (x, y, z) and
  48. // (u, v, w)
  49. // x: Number: an x coordinate of a point
  50. // y: Number: a y coordinate of a point
  51. // z: Number: a z coordinate of a point
  52. // u: Number: an x coordinate of a point
  53. // v: Number: a y coordinate of a point
  54. // w: Number: a z coordinate of a point
  55. return {
  56. x : y * w - z * v,
  57. y : z * u - x * w,
  58. z : x * v - y * u
  59. }; // Object
  60. },
  61. crossProduct : function(/* Number||Point */a, /* Number||Point */b, /*
  62. * Number,
  63. * optional
  64. */
  65. c, /* Number, optional */d, /* Number, optional */e, /*
  66. * Number,
  67. * optional
  68. */
  69. f) {
  70. // summary: applies a matrix to a point
  71. // matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be
  72. // applied
  73. // a: Number: an x coordinate of a point
  74. // b: Number: a y coordinate of a point
  75. // c: Number: a z coordinate of a point
  76. // d: Number: an x coordinate of a point
  77. // e: Number: a y coordinate of a point
  78. // f: Number: a z coordinate of a point
  79. if (arguments.length == 6 && dojo.every(arguments, function(item) {
  80. return typeof item == "number";
  81. })) {
  82. return dojox.gfx3d.vector._crossProduct(a, b, c, d, e, f); // Object
  83. }
  84. // branch
  85. // a: Object: a point
  86. // b: Object: a point
  87. // c: null
  88. // d: null
  89. // e: null
  90. // f: null
  91. return dojox.gfx3d.vector._crossProduct(a.x, a.y, a.z, b.x, b.y,
  92. b.z); // Object
  93. },
  94. _dotProduct : function(x, y, z, u, v, w) {
  95. // summary: applies a cross product of two vectorss, (x, y, z) and
  96. // (u, v, w)
  97. // x: Number: an x coordinate of a point
  98. // y: Number: a y coordinate of a point
  99. // z: Number: a z coordinate of a point
  100. // u: Number: an x coordinate of a point
  101. // v: Number: a y coordinate of a point
  102. // w: Number: a z coordinate of a point
  103. return x * u + y * v + z * w; // Number
  104. },
  105. dotProduct : function(/* Number||Point */a, /* Number||Point */b, /*
  106. * Number,
  107. * optional
  108. */
  109. c, /* Number, optional */d, /* Number, optional */e, /*
  110. * Number,
  111. * optional
  112. */
  113. f) {
  114. // summary: applies a matrix to a point
  115. // matrix: dojox.gfx3d.matrix.Matrix3D: a 3D matrix object to be
  116. // applied
  117. // a: Number: an x coordinate of a point
  118. // b: Number: a y coordinate of a point
  119. // c: Number: a z coordinate of a point
  120. // d: Number: an x coordinate of a point
  121. // e: Number: a y coordinate of a point
  122. // f: Number: a z coordinate of a point
  123. if (arguments.length == 6 && dojo.every(arguments, function(item) {
  124. return typeof item == "number";
  125. })) {
  126. return dojox.gfx3d.vector._dotProduct(a, b, c, d, e, f); // Object
  127. }
  128. // branch
  129. // a: Object: a point
  130. // b: Object: a point
  131. // c: null
  132. // d: null
  133. // e: null
  134. // f: null
  135. return dojox.gfx3d.vector._dotProduct(a.x, a.y, a.z, b.x, b.y, b.z); // Object
  136. },
  137. normalize : function(/* Point||Array */a, /* Point */b, /* Point */c) {
  138. // summary: find the normal of the implicit surface
  139. // a: Object: a point
  140. // b: Object: a point
  141. // c: Object: a point
  142. var l, m, n;
  143. if (a instanceof Array) {
  144. l = a[0];
  145. m = a[1];
  146. n = a[2];
  147. } else {
  148. l = a;
  149. m = b;
  150. n = c;
  151. }
  152. var u = dojox.gfx3d.vector.substract(m, l);
  153. var v = dojox.gfx3d.vector.substract(n, l);
  154. return dojox.gfx3d.vector.crossProduct(u, v);
  155. }
  156. });
  157. }