All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joml.AABBi Maven / Gradle / Ivy

There is a newer version: 1.10.1
Show newest version
/*
 * The MIT License
 *
 * Copyright (c) 2020 JOML.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.joml;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class AABBi implements Externalizable {

    /**
     * The x coordinate of the minimum corner.
     */
    public int minX = Integer.MAX_VALUE;
    /**
     * The y coordinate of the minimum corner.
     */
    public int minY = Integer.MAX_VALUE;
    /**
     * The z coordinate of the minimum corner.
     */
    public int minZ = Integer.MAX_VALUE;
    /**
     * The x coordinate of the maximum corner.
     */
    public int maxX = Integer.MIN_VALUE;
    /**
     * The y coordinate of the maximum corner.
     */
    public int maxY = Integer.MIN_VALUE;
    /**
     * The z coordinate of the maximum corner.
     */
    public int maxZ = Integer.MIN_VALUE;


    /**
     * Create a new {@link AABBi} representing the box with
     * (minX, minY, minZ)=(+inf, +inf, +inf) and (maxX, maxY, maxZ)=(-inf, -inf, -inf).
     */
    public AABBi() {
    }

    /**
     * Create a new {@link AABBi} as a copy of the given source.
     *
     * @param source
     *          the {@link AABBi} to copy from
     */
    public AABBi(AABBi source) {
        this.minX = source.minX;
        this.minY = source.minY;
        this.minZ = source.minZ;
        this.maxX = source.maxX;
        this.maxY = source.maxY;
        this.maxZ = source.maxZ;
    }

    /**
     * Create a new {@link AABBi} with the given minimum and maximum corner coordinates.
     *
     * @param min
     *          the minimum coordinates
     * @param max
     *          the maximum coordinates
     */
    public AABBi(Vector3ic min, Vector3ic max) {
        this.minX = min.x();
        this.minY = min.y();
        this.minZ = min.z();
        this.maxX = max.x();
        this.maxY = max.y();
        this.maxZ = max.z();
    }

    /**
     * Create a new {@link AABBi} with the given minimum and maximum corner coordinates.
     *
     * @param minX
     *          the x coordinate of the minimum corner
     * @param minY
     *          the y coordinate of the minimum corner
     * @param minZ
     *          the z coordinate of the minimum corner
     * @param maxX
     *          the x coordinate of the maximum corner
     * @param maxY
     *          the y coordinate of the maximum corner
     * @param maxZ
     *          the z coordinate of the maximum corner
     */
    public AABBi(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        this.maxX = maxX;
        this.maxY = maxY;
        this.maxZ = maxZ;
    }

    /**
     * Set the minimum corner coordinates.
     *
     * @param minX
     *          the x coordinate of the minimum corner
     * @param minY
     *          the y coordinate of the minimum corner
     * @param minZ
     *          the z coordinate of the minimum corner
     * @return this
     */
    public AABBi setMin(int minX, int minY, int minZ) {
        this.minX = minX;
        this.minY = minY;
        this.minZ = minZ;
        return this;
    }

    /**
     * Set the maximum corner coordinates.
     *
     * @param maxX
     *          the x coordinate of the maximum corner
     * @param maxY
     *          the y coordinate of the maximum corner
     * @param maxZ
     *          the z coordinate of the maximum corner
     * @return this
     */
    public AABBi setMax(int maxX, int maxY, int maxZ) {
        this.maxX = maxX;
        this.maxY = maxY;
        this.maxZ = maxZ;
        return this;
    }

    /**
     * Set this {@link AABBi} to be a clone of source.
     *
     * @param source
     *            the {@link AABBi} to copy from
     * @return this
     */
    public AABBi set(AABBi source){
        this.minX = source.minX;
        this.minY = source.minY;
        this.minZ = source.minZ;
        this.maxX = source.maxX;
        this.maxY = source.maxY;
        this.maxZ = source.maxZ;
        return this;
    }

    private AABBi validate() {
        if (!isValid()) {
            minX = Integer.MAX_VALUE;
            minY = Integer.MAX_VALUE;
            minZ = Integer.MAX_VALUE;

            maxX = Integer.MIN_VALUE;
            maxY = Integer.MIN_VALUE;
            maxZ = Integer.MIN_VALUE;
        }
        return this;
    }

    /**
     * Check whether this AABB represents a valid AABB.
     *
     * @return true iff this AABB is valid; false otherwise
     */
    public boolean isValid() {
        return minX < maxX && minY < maxY && minZ < maxZ;
    }

    /**
     * Set the minimum corner coordinates.
     *
     * @param min
     *          the minimum coordinates
     * @return this
     */
    public AABBi setMin(Vector3ic min) {
        return this.setMin(min.x(), min.y(), min.z());
    }

    /**
     * Set the maximum corner coordinates.
     *
     * @param max
     *          the maximum coordinates
     * @return this
     */
    public AABBi setMax(Vector3ic max) {
        return this.setMax(max.x(), max.y(), max.z());
    }

    /**
     * Get the maximum corner coordinate of the given component.
     *
     * @param component
     *          the component, within [0..2]
     * @return the maximum coordinate
     * @throws IllegalArgumentException if component is not within [0..2]
     */
    public int getMax(int component) throws IllegalArgumentException {
        switch (component) {
            case 0:
                return maxX;
            case 1:
                return maxY;
            case 2:
                return maxZ;
            default:
                throw new IllegalArgumentException();
        }
    }

    /**
     * Get the minimum corner coordinate of the given component.
     *
     * @param component
     *          the component, within [0..2]
     * @return the maximum coordinate
     * @throws IllegalArgumentException if component is not within [0..2]
     */
    public int getMin(int component) throws IllegalArgumentException {
        switch (component) {
            case 0:
                return minX;
            case 1:
                return minY;
            case 2:
                return minZ;
            default:
                throw new IllegalArgumentException();
        }
    }

    /**
     * Set this to the union of this and the given point (x, y, z).
     *
     * @param x
     *          the x coordinate of the point
     * @param y
     *          the y coordinate of the point
     * @param z
     *          the z coordinate of the point
     * @return this
     */
    public AABBi union(int x, int y, int z) {
        return union(x, y, z, this);
    }

    /**
     * Set this to the union of this and the given point p.
     *
     * @param p
     *          the point
     * @return this
     */
    public AABBi union(Vector3ic p) {
        return union(p.x(), p.y(), p.z(), this);
    }


    /**
     * Compute the union of this and the given point (x, y, z) and store the result in dest.
     *
     * @param x
     *          the x coordinate of the point
     * @param y
     *          the y coordinate of the point
     * @param z
     *          the z coordinate of the point
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBi union(int x, int y, int z, AABBi dest) {
        dest.minX = this.minX < x ? this.minX : x;
        dest.minY = this.minY < y ? this.minY : y;
        dest.minZ = this.minZ < z ? this.minZ : z;
        dest.maxX = this.maxX > x ? this.maxX : x;
        dest.maxY = this.maxY > y ? this.maxY : y;
        dest.maxZ = this.maxZ > z ? this.maxZ : z;
        return dest;
    }
    /**
     * Compute the union of this and the given point p and store the result in dest.
     *
     * @param p
     *          the point
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBi union(Vector3ic p, AABBi dest) {
        return union(p.x(), p.y(), p.z(), dest);
    }

    /**
     * Set this to the union of this and other.
     *
     * @param other
     *          the other {@link AABBi}
     * @return this
     */
    public AABBi union(AABBi other) {
        return this.union(other, this);
    }

    /**
     * Compute the union of this and other and store the result in dest.
     *
     * @param other
     *          the other {@link AABBi}
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBi union(AABBi other, AABBi dest) {
        dest.minX = this.minX < other.minX ? this.minX : other.minX;
        dest.minY = this.minY < other.minY ? this.minY : other.minY;
        dest.minZ = this.minZ < other.minZ ? this.minZ : other.minZ;
        dest.maxX = this.maxX > other.maxX ? this.maxX : other.maxX;
        dest.maxY = this.maxY > other.maxY ? this.maxY : other.maxY;
        dest.maxZ = this.maxZ > other.maxZ ? this.maxZ : other.maxZ;
        return dest;
    }

    /**
     * Ensure that the minimum coordinates are strictly less than or equal to the maximum coordinates by swapping
     * them if necessary.
     *
     * @return this
     */
    public AABBi correctBounds() {
        int tmp;
        if (this.minX > this.maxX) {
            tmp = this.minX;
            this.minX = this.maxX;
            this.maxX = tmp;
        }
        if (this.minY > this.maxY) {
            tmp = this.minY;
            this.minY = this.maxY;
            this.maxY = tmp;
        }
        if (this.minZ > this.maxZ) {
            tmp = this.minZ;
            this.minZ = this.maxZ;
            this.maxZ = tmp;
        }
        return this;
    }

    /**
     * Translate this by the given vector xyz.
     *
     * @param xyz
     *          the vector to translate by
     * @return this
     */
    public AABBi translate(Vector3ic xyz) {
        return translate(xyz.x(), xyz.y(), xyz.z(), this);
    }

    /**
     * Translate this by the given vector xyz and store the result in dest.
     *
     * @param xyz
     *          the vector to translate by
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBi translate(Vector3ic xyz, AABBi dest) {
        return translate(xyz.x(), xyz.y(), xyz.z(), dest);
    }

    /**
     * Translate this by the vector (x, y, z).
     *
     * @param x
     *          the x coordinate to translate by
     * @param y
     *          the y coordinate to translate by
     * @param z
     *          the z coordinate to translate by
     * @return this
     */
    public AABBi translate(int x, int y, int z) {
        return translate(x, y, z, this);
    }

    /**
     * Translate this by the vector (x, y, z) and store the result in dest.
     *
     * @param x
     *          the x coordinate to translate by
     * @param y
     *          the y coordinate to translate by
     * @param z
     *          the z coordinate to translate by
     * @param dest
     *          will hold the result
     * @return dest
     */
    public AABBi translate(int x, int y, int z, AABBi dest) {
        dest.minX = minX + x;
        dest.minY = minY + y;
        dest.minZ = minZ + z;
        dest.maxX = maxX + x;
        dest.maxY = maxY + y;
        dest.maxZ = maxZ + z;
        return dest;
    }


    /**
     * Compute the AABB of intersection between this and the given AABB.
     * 

* If the two AABBs do not intersect, then the minimum coordinates of this * will have a value of {@link Integer#MAX_VALUE} and the maximum coordinates will have a value of * {@link Integer#MIN_VALUE}. * * @param other * the other AABB * @param dest * will hold the result * @return dest */ public AABBi intersection(AABBi other, AABBi dest) { dest.minX = Math.max(minX, other.minX); dest.minY = Math.max(minY, other.minY); dest.minZ = Math.max(minZ, other.minZ); dest.maxX = Math.min(maxX, other.maxX); dest.maxY = Math.min(maxY, other.maxY); dest.maxZ = Math.min(maxZ, other.maxZ); return dest.validate(); } /** * Compute the AABB of intersection between this and the given AABB. *

* If the two AABBs do not intersect, then the minimum coordinates of this * will have a value of {@link Integer#MAX_VALUE} and the maximum coordinates will have a value of * {@link Integer#MIN_VALUE}. * * @param other * the other AABB * @return this */ public AABBi intersection(AABBi other) { return intersection(other, this); } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBd aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBf aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Check if this AABB contains the given AABB. * * @param aabb * the AABB to test * @return true iff this AABB contains the AABB; false otherwise */ public boolean containsAABB(AABBi aabb) { return aabb.minX >= minX && aabb.maxX <= maxX && aabb.minY >= minY && aabb.maxY <= maxY && aabb.minZ >= minZ && aabb.maxZ <= maxZ; } /** * Test whether the point (x, y, z) lies inside this AABB. * * @param x * the x coordinate of the point * @param y * the y coordinate of the point * @param z * the z coordinate of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(int x, int y, int z){ return x >= minX && y >= minY && z >= minZ && x <= maxX && y <= maxY && z <= maxZ; } /** * Test whether the point (x, y, z) lies inside this AABB. * * @param x * the x coordinate of the point * @param y * the y coordinate of the point * @param z * the z coordinate of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(float x, float y, float z){ return x >= minX && y >= minY && z >= minZ && x <= maxX && y <= maxY && z <= maxZ; } /** * Test whether the given point lies inside this AABB. * * @param point * the coordinates of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(Vector3ic point) { return containsPoint(point.x(), point.y(), point.z()); } /** * Test whether the given point lies inside this AABB. * * @param point * the coordinates of the point * @return true iff the given point lies inside this AABB; false otherwise */ public boolean containsPoint(Vector3fc point) { return containsPoint(point.x(), point.y(), point.z()); } /** * Test whether the plane given via its plane equation a*x + b*y + c*z + d = 0 intersects this AABB. *

* Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II") * * @param a * the x factor in the plane equation * @param b * the y factor in the plane equation * @param c * the z factor in the plane equation * @param d * the constant in the plane equation * @return true iff the plane intersects this AABB; false otherwise */ public boolean intersectsPlane(float a, float b, float c, float d) { return Intersectionf.testAabPlane(minX, minY, minZ, maxX, maxY, maxZ, a, b, c, d); } /** * Test whether the given plane intersects this AABB. *

* Reference: http://www.lighthouse3d.com ("Geometric Approach - Testing Boxes II") * * @param plane * the plane * @return true iff the plane intersects this AABB; false otherwise */ public boolean intersectsPlane(Planef plane) { return Intersectionf.testAabPlane(this, plane); } /** * Test whether this and other intersect. * * @param other * the other AABB * @return true iff both AABBs intersect; false otherwise */ public boolean intersectsAABB(AABBi other) { return this.maxX >= other.minX && this.maxY >= other.minY && this.maxZ >= other.minZ && this.minX <= other.maxX && this.minY <= other.maxY && this.minZ <= other.maxZ; } /** * Test whether this and other intersect. * * @param other * the other AABB * @return true iff both AABBs intersect; false otherwise */ public boolean intersectsAABB(AABBf other) { return this.maxX >= other.minX && this.maxY >= other.minY && this.maxZ >= other.minZ && this.minX <= other.maxX && this.minY <= other.maxY && this.minZ <= other.maxZ; } /** * Test whether this AABB intersects the given sphere with equation * (x - centerX)^2 + (y - centerY)^2 + (z - centerZ)^2 - radiusSquared = 0. *

* Reference: http://stackoverflow.com * * @param centerX * the x coordinate of the center of the sphere * @param centerY * the y coordinate of the center of the sphere * @param centerZ * the z coordinate of the center of the sphere * @param radiusSquared * the square radius of the sphere * @return true iff this AABB and the sphere intersect; false otherwise */ public boolean intersectsSphere(float centerX, float centerY, float centerZ, float radiusSquared) { return Intersectionf.testAabSphere(minX, minY, minZ, maxX, maxY, maxZ, centerX, centerY, centerZ, radiusSquared); } /** * Test whether this AABB intersects the given sphere. *

* Reference: http://stackoverflow.com * * @param sphere * the sphere * @return true iff this AABB and the sphere intersect; false otherwise */ public boolean intersectsSphere(Spheref sphere) { return Intersectionf.testAabSphere(this, sphere); } /** * Test whether the given ray with the origin (originX, originY, originZ) and direction (dirX, dirY, dirZ) * intersects this AABB. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param originX * the x coordinate of the ray's origin * @param originY * the y coordinate of the ray's origin * @param originZ * the z coordinate of the ray's origin * @param dirX * the x coordinate of the ray's direction * @param dirY * the y coordinate of the ray's direction * @param dirZ * the z coordinate of the ray's direction * @return true if this AABB and the ray intersect; false otherwise */ public boolean intersectsRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ) { return Intersectionf.testRayAab(originX, originY, originZ, dirX, dirY, dirZ, minX, minY, minZ, maxX, maxY, maxZ); } /** * Test whether the given ray intersects this AABB. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param ray * the ray * @return true if this AABB and the ray intersect; false otherwise */ public boolean intersectsRay(Rayf ray) { return Intersectionf.testRayAab(ray, this); } /** * Determine whether the given ray with the origin (originX, originY, originZ) and direction (dirX, dirY, dirZ) * intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + t * dir of the near and far point of intersection. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param originX * the x coordinate of the ray's origin * @param originY * the y coordinate of the ray's origin * @param originZ * the z coordinate of the ray's origin * @param dirX * the x coordinate of the ray's direction * @param dirY * the y coordinate of the ray's direction * @param dirZ * the z coordinate of the ray's direction * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = origin + t * dir of the near and far point of intersection * iff the ray intersects this AABB * @return true if the given ray intersects this AABB; false otherwise */ public boolean intersectsRay(float originX, float originY, float originZ, float dirX, float dirY, float dirZ, Vector2f result) { return Intersectionf.intersectRayAab(originX, originY, originZ, dirX, dirY, dirZ, minX, minY, minZ, maxX, maxY, maxZ, result); } /** * Determine whether the given ray intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + t * dir of the near and far point of intersection. *

* This method returns true for a ray whose origin lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param ray * the ray * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = origin + t * dir of the near and far point of intersection * iff the ray intersects this AABB * @return true if the given ray intersects this AABB; false otherwise */ public boolean intersectsRay(Rayf ray, Vector2f result) { return Intersectionf.intersectRayAab(ray, this, result); } /** * Determine whether the undirected line segment with the end points (p0X, p0Y, p0Z) and (p1X, p1Y, p1Z) * intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection. *

* This method returns true for a line segment whose either end point lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param p0X * the x coordinate of the line segment's first end point * @param p0Y * the y coordinate of the line segment's first end point * @param p0Z * the z coordinate of the line segment's first end point * @param p1X * the x coordinate of the line segment's second end point * @param p1Y * the y coordinate of the line segment's second end point * @param p1Z * the z coordinate of the line segment's second end point * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection * iff the line segment intersects this AABB * @return {@link Intersectionf#INSIDE} if the line segment lies completely inside of this AABB; or * {@link Intersectionf#OUTSIDE} if the line segment lies completely outside of this AABB; or * {@link Intersectionf#ONE_INTERSECTION} if one of the end points of the line segment lies inside of this AABB; or * {@link Intersectionf#TWO_INTERSECTION} if the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB */ public int intersectLineSegment(float p0X, float p0Y, float p0Z, float p1X, float p1Y, float p1Z, Vector2f result) { return Intersectionf.intersectLineSegmentAab(p0X, p0Y, p0Z, p1X, p1Y, p1Z, minX, minY, minZ, maxX, maxY, maxZ, result); } /** * Determine whether the given undirected line segment intersects this AABB, and return the values of the parameter t in the ray equation * p(t) = origin + p0 * (p1 - p0) of the near and far point of intersection. *

* This method returns true for a line segment whose either end point lies inside this AABB. *

* Reference: An Efficient and Robust Ray–Box Intersection * * @param lineSegment * the line segment * @param result * a vector which will hold the resulting values of the parameter * t in the ray equation p(t) = p0 + t * (p1 - p0) of the near and far point of intersection * iff the line segment intersects this AABB * @return {@link Intersectionf#INSIDE} if the line segment lies completely inside of this AABB; or * {@link Intersectionf#OUTSIDE} if the line segment lies completely outside of this AABB; or * {@link Intersectionf#ONE_INTERSECTION} if one of the end points of the line segment lies inside of this AABB; or * {@link Intersectionf#TWO_INTERSECTION} if the line segment intersects two sides of this AABB or lies on an edge or a side of this AABB */ public int intersectLineSegment(LineSegmentf lineSegment, Vector2f result) { return Intersectionf.intersectLineSegmentAab(lineSegment, this, result); } /** * Apply the given {@link Matrix4fc#isAffine() affine} transformation to this {@link AABBi}. *

* The matrix in m must be {@link Matrix4fc#isAffine() affine}. * * @param m * the affine transformation matrix * @return this */ public AABBi transform(Matrix4fc m) { return transform(m, this); } /** * Apply the given {@link Matrix4fc#isAffine() affine} transformation to this * {@link AABBi} and store the resulting AABB into dest. *

* The matrix in m must be {@link Matrix4fc#isAffine() affine}. * * @param m * the affine transformation matrix * @param dest * will hold the result * @return dest */ public AABBi transform(Matrix4fc m, AABBi dest) { float dx = maxX - minX, dy = maxY - minY, dz = maxZ - minZ; float minx = Float.POSITIVE_INFINITY, miny = Float.POSITIVE_INFINITY, minz = Float.POSITIVE_INFINITY; float maxx = Float.NEGATIVE_INFINITY, maxy = Float.NEGATIVE_INFINITY, maxz = Float.NEGATIVE_INFINITY; for (int i = 0; i < 8; i++) { float x = minX + (i & 1) * dx, y = minY + (i >> 1 & 1) * dy, z = minZ + (i >> 2 & 1) * dz; float tx = m.m00() * x + m.m10() * y + m.m20() * z + m.m30(); float ty = m.m01() * x + m.m11() * y + m.m21() * z + m.m31(); float tz = m.m02() * x + m.m12() * y + m.m22() * z + m.m32(); minx = Math.min(tx, minx); miny = Math.min(ty, miny); minz = Math.min(tz, minz); maxx = Math.max(tx, maxx); maxy = Math.max(ty, maxy); maxz = Math.max(tz, maxz); } dest.minX = Math.roundUsing(minx, RoundingMode.FLOOR); dest.minY = Math.roundUsing(miny, RoundingMode.FLOOR); dest.minZ = Math.roundUsing(minz, RoundingMode.FLOOR); dest.maxX = Math.roundUsing(maxx, RoundingMode.CEILING); dest.maxY = Math.roundUsing(maxy, RoundingMode.CEILING); dest.maxZ = Math.roundUsing(maxz, RoundingMode.CEILING); return dest; } public int hashCode() { final int prime = 31; int result = 1; result = prime * result + minX; result = prime * result + minY; result = prime * result + minZ; result = prime * result + maxX; result = prime * result + maxY; result = prime * result + maxZ; return result; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; AABBi aabBi = (AABBi) obj; return minX == aabBi.minX && minY == aabBi.minY && minZ == aabBi.minZ && maxX == aabBi.maxX && maxY == aabBi.maxY && maxZ == aabBi.maxZ; } public String toString() { return "(" + this.minX + " " + this.minY + " " + this.minZ + ") < " + "(" + this.maxX + " " + this.maxY + " " + this.maxZ + ")"; } public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(minX); out.writeInt(minY); out.writeInt(minZ); out.writeInt(maxX); out.writeInt(maxY); out.writeInt(maxZ); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { minX = in.readInt(); minY = in.readInt(); minZ = in.readInt(); maxX = in.readInt(); maxY = in.readInt(); maxZ = in.readInt(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy