Created
March 7, 2019 08:02
-
-
Save pofulu/1aef033059ab3a5e7abf566c963a80d1 to your computer and use it in GitHub Desktop.
Vector3 function in reactive style for Spark AR.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vector3(x, y, z) { | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
this.mul = function (multiplier) { | |
return new Vector3(this.x.mul(multiplier), this.y.mul(multiplier), this.z.mul(multiplier)); | |
}; | |
this.scale = function (anotherVector3) { | |
return new Vector3(this.x.mul(anotherVector3.x), this.y.mul(anotherVector3.y), this.z.mul(anotherVector3.z)); | |
} | |
this.add = function (anotherVector3) { | |
return new Vector3(this.x.add(anotherVector3.x), this.y.add(anotherVector3.y), this.z.add(anotherVector3.z)); | |
} | |
this.dot = function (anotherVector3) { | |
return this.x.mul(anotherVector3.x).add(this.y.mul(anotherVector3.y)).add(this.z.mul(anotherVector3.z)); | |
} | |
this.sub = function (anotherVector3) { | |
return new Vector3(this.x.sub(anotherVector3.x), this.y.sub(anotherVector3.y), this.z.sub(anotherVector3.z)); | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment