/* *EERT = EERT enhanced rendering technology * *Copyright (C) [2008] [Robert "BuRnEr" Schadek] *This program is free software; you can redistribute it and/or modify it under *the terms of the GNU General Public License as published by the Free Software *Foundation; either version 3 of the License, *or (at your option) any later version. *This program is distributed in the hope that it will be useful, but WITHOUT *ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. *You should have received a copy of the GNU General Public License along with *this program; if not, see <http://www.gnu.org/licenses/>. */ package Types.Geometrie; public class Vector { public float x; public float y; public float z; public Vector() { this.x = 0.0f; this.y = 0.0f; this.z = 0.0f; } public Vector(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } public Vector(Vector old) { this.x = old.x; this.y = old.y; this.z = old.z; } public float getLength() { return (float) Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } public void normalize() { float f = 1.0f / this.getLength(); this.mult(f); } public void add(Vector vec) { this.x += vec.x; this.y += vec.y; this.z += vec.z; } public Vector addR(Vector vec) { this.x += vec.x; this.y += vec.y; this.z += vec.z; return this; } public void sub(Vector vec) { this.x -= vec.x; this.y -= vec.y; this.z -= vec.z; } public Vector subR(Vector vec) { return new Vector(this.x - vec.x, this.y - vec.y, this.z - vec.z); } public void mult(float scalar) { this.x *= scalar; this.y *= scalar; this.z *= scalar; } public void div(float scalar) { this.x /= scalar; this.y /= scalar; this.z /= scalar; } public Vector getCrossProd(Vector vector) { return new Vector( this.y * vector.z - this.z * vector.y, this.z * vector.x - this.x * vector.z, this.x * vector.y - this.y * vector.x); } @Override public String toString() { return new String(this.x + " " + this.y + " " + this.z); } }