X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPoint3D.java;h=440023f50eb52d280971c081e004db165d24843e;hb=f3da0bbe2c31d899156d410f8e75dabb0255efdf;hp=1c8700a5bda10161ac3d8ba261f0f5e716dea83b;hpb=3e2b906bd05617a4d9725de39ac14c9ea1f8736c;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java index 1c8700a..440023f 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -1,13 +1,17 @@ /* - * Sixth 3D engine. Author: Svjatoslav Agejenko. + * Sixth 3D engine. Author: Svjatoslav Agejenko. * This project is released under Creative Commons Zero (CC0) license. */ package eu.svjatoslav.sixth.e3d.geometry; +import eu.svjatoslav.sixth.e3d.renderer.octree.IntegerPoint; + import static java.lang.Math.*; /** * Used to represent point in a 3D space or vector. + * + * @see Point2D */ public class Point3D implements Cloneable { @@ -36,6 +40,13 @@ public class Point3D implements Cloneable { this.z = z; } + public Point3D(IntegerPoint point) { + this.x = point.x; + this.y = point.y; + this.z = point.z; + } + + /** * Creates new current point by cloning coordinates from parent point. */ @@ -58,6 +69,21 @@ public class Point3D implements Cloneable { return this; } + /** + * Add coordinates of current point to other point. Value of current point will not be changed. + * + * @return current point. + */ + public Point3D addTo(final Point3D... otherPoints) { + for (final Point3D otherPoint : otherPoints) otherPoint.add(this); + return this; + } + + /** + * Create new point by cloning position of current point. + * + * @return newly created clone. + */ public Point3D clone() { return new Point3D(this); } @@ -143,12 +169,12 @@ public class Point3D implements Cloneable { *

* See also: Let's remove Quaternions from every 3D Engine * - * @param center center point. + * @param center center point. * @param angleXZ angle around XZ axis. * @param angleYZ angle around YZ axis. */ - public void rotate(final Point3D center, final double angleXZ, - final double angleYZ) { + public Point3D rotate(final Point3D center, final double angleXZ, + final double angleYZ) { final double s1 = sin(angleXZ); final double c1 = cos(angleXZ); @@ -168,6 +194,12 @@ public class Point3D implements Cloneable { x = x1 + center.x; y = y1 + center.y; z = z2 + center.z; + + return this; + } + + public Point3D rotate(final double angleXZ, final double angleYZ) { + return rotate(new Point3D(0, 0, 0), angleXZ, angleYZ); } /** @@ -209,6 +241,7 @@ public class Point3D implements Cloneable { /** * Set current point coordinates to given values. + * * @param x X coordinate. * @param y Y coordinate. * @param z Z coordinate.