Vector2.js 1.5 KB

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