Vector2.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. function Vector2() {
  2. Object.defineProperties(this, {
  3. 'x': { enumerable: true, configurable: true, get: Vector2.prototype.__get_x, set: Vector2.prototype.__set_x},
  4. 'y': { enumerable: true, configurable: true, get: Vector2.prototype.__get_y, set: Vector2.prototype.__set_y}
  5. })
  6. }
  7. Vector2.prototype.__get_x = function() {
  8. return Polycode.Vector2__get_x(this.__ptr)
  9. }
  10. Vector2.prototype.__set_x = function(val) {
  11. Polycode.Vector2__set_x(this.__ptr, val)
  12. }
  13. Vector2.prototype.__get_y = function() {
  14. return Polycode.Vector2__get_y(this.__ptr)
  15. }
  16. Vector2.prototype.__set_y = function(val) {
  17. Polycode.Vector2__set_y(this.__ptr, val)
  18. }
  19. Duktape.fin(Vector2.prototype, function (x) {
  20. if (x === Vector2.prototype) {
  21. return;
  22. }
  23. Polycode.Vector2__delete(x.__ptr)
  24. })
  25. Vector2.prototype.set = function(x,y) {
  26. Polycode.Vector2_set(this.__ptr, x,y)
  27. }
  28. Vector2.prototype.distance = function(vec2) {
  29. return Polycode.Vector2_distance(this.__ptr, vec2)
  30. }
  31. Vector2.prototype.length = function() {
  32. return Polycode.Vector2_length(this.__ptr)
  33. }
  34. Vector2.prototype.dot = function(u) {
  35. return Polycode.Vector2_dot(this.__ptr, u)
  36. }
  37. Vector2.prototype.crossProduct = function(vec2) {
  38. return Polycode.Vector2_crossProduct(this.__ptr, vec2)
  39. }
  40. Vector2.prototype.angle = function(vec2) {
  41. return Polycode.Vector2_angle(this.__ptr, vec2)
  42. }
  43. Vector2.prototype.Normalize = function() {
  44. Polycode.Vector2_Normalize(this.__ptr)
  45. }