i read this tutorial. it's game development, , says need store acceleration, velocity, position vectors make game physics. hope makes sense! need choose data type now... example need store values like...
(3, 5, 2)
(6, 2, 3)
(2, 3)
also, need addition , subtraction this...
(0, 1, 4) + (3, -2, 5) = (0 + 3, 1 - 2, 4 + 5) = (3, -1,9)
what data type should use in situation?
for 1 vector 2 integers (floats/doubles) maybe? maybe array 1 vector where values integers (floats/doubles)?
sounds want 3 values (probably doubles):
public class vector3 { private final double x; private final double y; private final double z; public vector3(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public vector3 plus(vector3 other) { return new vector3(x + other.x, y + other.y, z + other.z); } // etc }
note i've made immutable - isn't best choice performance (which may relevant in situation) helps readability.
Comments
Post a Comment