Vector3.js 2.1 KB

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