Vector3.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. function Vector3() {
  2. Object.defineProperties(this, {
  3. 'x': { enumerable: true, configurable: true, get: Vector3.prototype.__get_x, set: Vector3.prototype.__set_x},
  4. 'y': { enumerable: true, configurable: true, get: Vector3.prototype.__get_y, set: Vector3.prototype.__set_y},
  5. 'z': { enumerable: true, configurable: true, get: Vector3.prototype.__get_z, set: Vector3.prototype.__set_z}
  6. })
  7. }
  8. Vector3.prototype.__get_x = function() {
  9. return Polycode.Vector3__get_x(this.__ptr)
  10. }
  11. Vector3.prototype.__set_x = function(val) {
  12. Polycode.Vector3__set_x(this.__ptr, val)
  13. }
  14. Vector3.prototype.__get_y = function() {
  15. return Polycode.Vector3__get_y(this.__ptr)
  16. }
  17. Vector3.prototype.__set_y = function(val) {
  18. Polycode.Vector3__set_y(this.__ptr, val)
  19. }
  20. Vector3.prototype.__get_z = function() {
  21. return Polycode.Vector3__get_z(this.__ptr)
  22. }
  23. Vector3.prototype.__set_z = function(val) {
  24. Polycode.Vector3__set_z(this.__ptr, val)
  25. }
  26. Duktape.fin(Vector3.prototype, function (x) {
  27. if (x === Vector3.prototype) {
  28. return;
  29. }
  30. Polycode.Vector3__delete(x.__ptr)
  31. })
  32. Vector3.prototype.set = function(x,y,z) {
  33. Polycode.Vector3_set(this.__ptr, x,y,z)
  34. }
  35. Vector3.prototype.distance = function(vec2) {
  36. return Polycode.Vector3_distance(this.__ptr, vec2)
  37. }
  38. Vector3.prototype.angleBetween = function(dest) {
  39. return Polycode.Vector3_angleBetween(this.__ptr, dest)
  40. }
  41. Vector3.prototype.length = function() {
  42. return Polycode.Vector3_length(this.__ptr)
  43. }
  44. Vector3.prototype.lengthSquared = function() {
  45. return Polycode.Vector3_lengthSquared(this.__ptr)
  46. }
  47. Vector3.prototype.setLength = function(newLength) {
  48. var retVal = new Vector3()
  49. retVal.__ptr = Polycode.Vector3_setLength(this.__ptr, newLength)
  50. return retVal
  51. }
  52. Vector3.prototype.dot = function(u) {
  53. return Polycode.Vector3_dot(this.__ptr, u)
  54. }
  55. Vector3.prototype.crossProduct = function(vec2) {
  56. var retVal = new Vector3()
  57. retVal.__ptr = Polycode.Vector3_crossProduct(this.__ptr, vec2)
  58. return retVal
  59. }
  60. Vector3.prototype.Normalize = function() {
  61. Polycode.Vector3_Normalize(this.__ptr)
  62. }