Skip to content

Instantly share code, notes, and snippets.

@ziir
Created September 15, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ziir/c31112c71eaa35a816bb to your computer and use it in GitHub Desktop.
Save ziir/c31112c71eaa35a816bb to your computer and use it in GitHub Desktop.
export class Vector3 {
constructor (...args) {
if (args[0] instanceof Vector3) {
this.set(other);
} else if (Array.isArray(args[0]) && args[0].length === 3) {
this.x = args[0][0];
this.y = args[0][1];
this.z = args[0][2];
} else if (Object.Keys(args[0]) && Object.Keys(args[0]).length === 3) {
this.x = other.x;
this.y = other.y;
this.z = other.z;
} else if (args.length === 3) {
this.x = args[0];
this.y = args[1];
this.z = args[2];
} else {
console.warn("Couldn't handle Vector3(...args); Assigning default values");
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment