private void updateCameraFrustum() { final double width = _corners[2].subtractLocal(_corners[1]).length() / 2.0; final double height = _corners[1].subtractLocal(_corners[0]).length() / 2.0; _tRenderer.getCamera().setFrustum(_nearPlane, _farPlane, -width, width, height, -height); }
private void updateCameraFrustum() { final double width = _corners[2].subtractLocal(_corners[1]).length() / 2.0; final double height = _corners[1].subtractLocal(_corners[0]).length() / 2.0; _tRenderer.getCamera().setFrustum(_nearPlane, _farPlane, -width, width, height, -height); }
/** * Sets the vectorStore information to the 8 corners of the box. */ public void computeCorners() { final Vector3 tempAxis0 = _xAxis.multiply(_extent.getX(), _compVect1); final Vector3 tempAxis1 = _yAxis.multiply(_extent.getY(), _compVect2); final Vector3 tempAxis2 = _zAxis.multiply(_extent.getZ(), _compVect3); _vectorStore[0].set(_center).subtractLocal(tempAxis0).subtractLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[1].set(_center).addLocal(tempAxis0).subtractLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[2].set(_center).addLocal(tempAxis0).addLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[3].set(_center).subtractLocal(tempAxis0).addLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[4].set(_center).subtractLocal(tempAxis0).subtractLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[5].set(_center).addLocal(tempAxis0).subtractLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[6].set(_center).addLocal(tempAxis0).addLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[7].set(_center).subtractLocal(tempAxis0).addLocal(tempAxis1).addLocal(tempAxis2); correctCorners = true; }
/** * Sets the vectorStore information to the 8 corners of the box. */ public void computeCorners() { final Vector3 tempAxis0 = _xAxis.multiply(_extent.getX(), _compVect1); final Vector3 tempAxis1 = _yAxis.multiply(_extent.getY(), _compVect2); final Vector3 tempAxis2 = _zAxis.multiply(_extent.getZ(), _compVect3); _vectorStore[0].set(_center).subtractLocal(tempAxis0).subtractLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[1].set(_center).addLocal(tempAxis0).subtractLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[2].set(_center).addLocal(tempAxis0).addLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[3].set(_center).subtractLocal(tempAxis0).addLocal(tempAxis1).subtractLocal(tempAxis2); _vectorStore[4].set(_center).subtractLocal(tempAxis0).subtractLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[5].set(_center).addLocal(tempAxis0).subtractLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[6].set(_center).addLocal(tempAxis0).addLocal(tempAxis1).addLocal(tempAxis2); _vectorStore[7].set(_center).subtractLocal(tempAxis0).addLocal(tempAxis1).addLocal(tempAxis2); correctCorners = true; }
/** * Decrements the values of this vector by the x, y and z values from the given source vector. * * @param source * @return this vector for chaining * @throws NullPointerException * if source is null. */ public Vector3 subtractLocal(final ReadOnlyVector3 source) { return subtractLocal(source.getX(), source.getY(), source.getZ()); }
/** * Decrements the values of this vector by the x, y and z values from the given source vector. * * @param source * @return this vector for chaining * @throws NullPointerException * if source is null. */ public Vector3 subtractLocal(final ReadOnlyVector3 source) { return subtractLocal(source.getX(), source.getY(), source.getZ()); }
@Override public boolean contains(final ReadOnlyVector3 point) { _compVect1.set(point).subtractLocal(_center); double coeff = _compVect1.dot(_xAxis); if (Math.abs(coeff) > _extent.getX()) { return false; } coeff = _compVect1.dot(_yAxis); if (Math.abs(coeff) > _extent.getY()) { return false; } coeff = _compVect1.dot(_zAxis); if (Math.abs(coeff) > _extent.getZ()) { return false; } return true; }
@Override public boolean contains(final ReadOnlyVector3 point) { _compVect1.set(point).subtractLocal(_center); double coeff = _compVect1.dot(_xAxis); if (Math.abs(coeff) > _extent.getX()) { return false; } coeff = _compVect1.dot(_yAxis); if (Math.abs(coeff) > _extent.getY()) { return false; } coeff = _compVect1.dot(_zAxis); if (Math.abs(coeff) > _extent.getZ()) { return false; } return true; }
private boolean getWorldIntersection(final double planeHeight, final Vector3 source, final Vector3 destination, final Vector3 store, final Vector3 tmpStorage) { final Vector3 origin = store.set(source); final Vector3 direction = tmpStorage.set(destination).subtractLocal(origin); final double t = (planeHeight - origin.getY()) / (direction.getY()); direction.multiplyLocal(t); origin.addLocal(direction); return t >= 0.0 && t <= 1.0; }
private boolean getWorldIntersection(final double planeHeight, final Vector3 source, final Vector3 destination, final Vector3 store, final Vector3 tmpStorage) { final Vector3 origin = store.set(source); final Vector3 direction = tmpStorage.set(destination).subtractLocal(origin); final double t = (planeHeight - origin.getY()) / (direction.getY()); direction.multiplyLocal(t); origin.addLocal(direction); return t >= 0.0 && t <= 1.0; }
/** * Constructs a new segment segment using the supplied start and end points * * @param start * @param end */ public LineSegment3(final ReadOnlyVector3 start, final ReadOnlyVector3 end) { this(); _origin.set(start).addLocal(end).multiplyLocal(0.5); _direction.set(end).subtractLocal(start); _extent = 0.5 * _direction.length(); _direction.normalizeLocal(); }
/** * Constructs a new segment segment using the supplied start and end points * * @param start * @param end */ public LineSegment3(final ReadOnlyVector3 start, final ReadOnlyVector3 end) { this(); _origin.set(start).addLocal(end).multiplyLocal(0.5); _direction.set(end).subtractLocal(start); _extent = 0.5 * _direction.length(); _direction.normalizeLocal(); }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } final Vector3 diff = _compVect1.set(getCenter()).subtractLocal(bs.getCenter()); final double rsum = getRadius() + bs.getRadius(); return (diff.dot(diff) <= rsum * rsum); }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } final Vector3 diff = _compVect1.set(getCenter()).subtractLocal(bs.getCenter()); final double rsum = getRadius() + bs.getRadius(); return (diff.dot(diff) <= rsum * rsum); }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } _compVect1.set(bs.getCenter()).subtractLocal(_center); final Matrix3 tempMa = Matrix3.fetchTempInstance().fromAxes(_xAxis, _yAxis, _zAxis); tempMa.applyPost(_compVect1, _compVect1); boolean result = false; if (Math.abs(_compVect1.getX()) < bs.getRadius() + _extent.getX() && Math.abs(_compVect1.getY()) < bs.getRadius() + _extent.getY() && Math.abs(_compVect1.getZ()) < bs.getRadius() + _extent.getZ()) { result = true; } Matrix3.releaseTempInstance(tempMa); return result; }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } _compVect1.set(bs.getCenter()).subtractLocal(_center); final Matrix3 tempMa = Matrix3.fetchTempInstance().fromAxes(_xAxis, _yAxis, _zAxis); tempMa.applyPost(_compVect1, _compVect1); boolean result = false; if (Math.abs(_compVect1.getX()) < bs.getRadius() + _extent.getX() && Math.abs(_compVect1.getY()) < bs.getRadius() + _extent.getY() && Math.abs(_compVect1.getZ()) < bs.getRadius() + _extent.getZ()) { result = true; } Matrix3.releaseTempInstance(tempMa); return result; }
/** * Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA. */ protected void calculateNormal() { if (_normal == null) { _normal = _pointB.clone(); } else { _normal.set(_pointB); } _normal.subtractLocal(_pointA).crossLocal(_pointC.getX() - _pointA.getX(), _pointC.getY() - _pointA.getY(), _pointC.getZ() - _pointA.getZ()); _normal.normalizeLocal(); _dirtyNormal = false; }
/** * Recalculates the surface normal of the triangle by crossing the vectors formed by BA and CA. */ protected void calculateNormal() { if (_normal == null) { _normal = _pointB.clone(); } else { _normal.set(_pointB); } _normal.subtractLocal(_pointA).crossLocal(_pointC.getX() - _pointA.getX(), _pointC.getY() - _pointA.getY(), _pointC.getZ() - _pointA.getZ()); _normal.normalizeLocal(); _dirtyNormal = false; }
/** * Sets this plane to the plane defined by the given three points. * * @param pointA * @param pointB * @param pointC * @return this plane for chaining * @throws NullPointerException * if one or more of the points are null. */ public Plane setPlanePoints(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB, final ReadOnlyVector3 pointC) { _normal.set(pointB).subtractLocal(pointA); _normal.crossLocal(pointC.getX() - pointA.getX(), pointC.getY() - pointA.getY(), pointC.getZ() - pointA.getZ()) .normalizeLocal(); _constant = _normal.dot(pointA); return this; }
/** * Aligns this Billboard Node so that it points to the camera position. */ private void rotateCameraAligned() { final Camera camera = Camera.getCurrentCamera(); _look.set(camera.getLocation()).subtractLocal(_worldTransform.getTranslation()).normalizeLocal(); _left.set(camera.getUp()).crossLocal(_look); final Vector3 up = Vector3.fetchTempInstance(); up.set(_look).crossLocal(_left); _orient.fromAxes(_left, up, _look); if(_localRot != null) _orient.multiplyLocal(_localRot); _worldTransform.setRotation(_orient); Vector3.releaseTempInstance(up); }