public RoundedBox(final String name, final Vector3 extent) { super(name); extent.subtract(_slope, _extent); setData(); }
/** * * @return a size 8 array of Vectors representing the 8 points of the box. */ public Vector3[] computeVertices() { final Vector3 akEAxis[] = { Vector3.UNIT_X.multiply(_xExtent, Vector3.fetchTempInstance()), Vector3.UNIT_Y.multiply(_yExtent, Vector3.fetchTempInstance()), Vector3.UNIT_Z.multiply(_zExtent, Vector3.fetchTempInstance()) }; final Vector3 rVal[] = new Vector3[8]; rVal[0] = _center.subtract(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[1] = _center.add(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[2] = _center.add(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[3] = _center.subtract(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[4] = _center.add(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[5] = _center.subtract(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[6] = _center.add(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[7] = _center.subtract(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).addLocal(akEAxis[2]); for (final Vector3 axis : akEAxis) { Vector3.releaseTempInstance(axis); } return rVal; }
/** * * @return a size 8 array of Vectors representing the 8 points of the box. */ public Vector3[] computeVertices() { final Vector3 akEAxis[] = { Vector3.UNIT_X.multiply(_xExtent, Vector3.fetchTempInstance()), Vector3.UNIT_Y.multiply(_yExtent, Vector3.fetchTempInstance()), Vector3.UNIT_Z.multiply(_zExtent, Vector3.fetchTempInstance()) }; final Vector3 rVal[] = new Vector3[8]; rVal[0] = _center.subtract(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[1] = _center.add(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[2] = _center.add(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[3] = _center.subtract(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).subtractLocal(akEAxis[2]); rVal[4] = _center.add(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[5] = _center.subtract(akEAxis[0], new Vector3()).subtractLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[6] = _center.add(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).addLocal(akEAxis[2]); rVal[7] = _center.subtract(akEAxis[0], new Vector3()).addLocal(akEAxis[1]).addLocal(akEAxis[2]); for (final Vector3 axis : akEAxis) { Vector3.releaseTempInstance(axis); } return rVal; }
public RoundedBox(final String name, final Vector3 extent) { super(name); extent.subtract(_slope, _extent); setData(); }
@Test public void testSubtract() { final Vector3 vec1 = new Vector3(); final Vector3 vec2 = new Vector3(Vector3.ONE); vec1.subtractLocal(1, 2, 3); assertEquals(new Vector3(-1, -2, -3), vec1); vec1.subtractLocal(-1, -2, -3); assertEquals(Vector3.ZERO, vec1); vec1.zero(); vec1.subtractLocal(vec2); assertEquals(Vector3.NEG_ONE, vec1); vec1.zero(); final Vector3 vec3 = vec1.subtract(vec2, new Vector3()); assertEquals(Vector3.ZERO, vec1); assertEquals(Vector3.NEG_ONE, vec3); final Vector3 vec4 = vec1.subtract(1, 0, 0, null); assertEquals(Vector3.ZERO, vec1); assertEquals(Vector3.NEG_UNIT_X, vec4); }
/** * Computes the normal from the three vertices in the given array that are indexed by the edges. * * @param verts * The array containing the vertices */ public void computeNormal(final Vector3[] verts) { final int i0 = edges[0].i0; final int i1 = edges[1].i0; final int i2 = edges[2].i0; verts[i2].subtract(verts[i1], _compVect0); verts[i0].subtract(verts[i1], _compVect1); normal.set(_compVect0.crossLocal(_compVect1)).normalizeLocal(); }
@Override public void apply(final double dt, final Particle p, final int index) { final double dtStr = dt * _strength * (_random ? MathUtils.nextRandomFloat() : 1f); p.getPosition().subtract(_line.getOrigin(), _v1); _line.getDirection().cross(_v1, v2); if (v2.length() == 0) { // particle is on the axis return; } v2.normalizeLocal(); if (_type == VT_CYLINDER) { _rot.apply(v2, v2); v2.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); return; } v2.cross(_line.getDirection(), _v1); _v1.multiplyLocal(_radius); _line.getDirection().scaleAdd(_height, _v1, _v1); _v1.addLocal(_line.getOrigin()); _v1.subtractLocal(p.getPosition()); if (_v1.length() == 0) { // particle is on the ring return; } _v1.normalizeLocal(); _v1.cross(v2, v3); _rot.fromAngleAxis(-_divergence, v2); _rot.apply(v3, v3); v3.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); }
/** * Computes the normal from the three vertices in the given array that are indexed by the edges. * * @param verts * The array containing the vertices */ public void computeNormal(final Vector3[] verts) { final int i0 = edges[0].i0; final int i1 = edges[1].i0; final int i2 = edges[2].i0; verts[i2].subtract(verts[i1], _compVect0); verts[i0].subtract(verts[i1], _compVect1); normal.set(_compVect0.crossLocal(_compVect1)).normalizeLocal(); }
@Override public void apply(final double dt, final Particle p, final int index) { final double dtStr = dt * _strength * (_random ? MathUtils.nextRandomFloat() : 1f); p.getPosition().subtract(_line.getOrigin(), _v1); _line.getDirection().cross(_v1, v2); if (v2.length() == 0) { // particle is on the axis return; } v2.normalizeLocal(); if (_type == VT_CYLINDER) { _rot.apply(v2, v2); v2.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); return; } v2.cross(_line.getDirection(), _v1); _v1.multiplyLocal(_radius); _line.getDirection().scaleAdd(_height, _v1, _v1); _v1.addLocal(_line.getOrigin()); _v1.subtractLocal(p.getPosition()); if (_v1.length() == 0) { // particle is on the ring return; } _v1.normalizeLocal(); _v1.cross(v2, v3); _rot.fromAngleAxis(-_divergence, v2); _rot.apply(v3, v3); v3.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); }
public RoundedBox(final String name, final Vector3 extent, final Vector3 border, final Vector3 slope) { super(name); _border.set(border); _slope.set(slope); extent.subtract(_slope, _extent); setData(); }
public RoundedBox(final String name, final Vector3 extent, final Vector3 border, final Vector3 slope) { super(name); _border.set(border); _slope.set(slope); extent.subtract(_slope, _extent); setData(); }
/** * Subtracts the values of the given source vector from those of this vector and returns them in store. * * @param source * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return (this.x - source.x, this.y - source.y, this.z - source.z) * @throws NullPointerException * if source is null. */ @Override public Vector3 subtract(final ReadOnlyVector3 source, final Vector3 store) { return subtract(source.getX(), source.getY(), source.getZ(), store); }
/** * Subtracts the values of the given source vector from those of this vector and returns them in store. * * @param source * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return (this.x - source.x, this.y - source.y, this.z - source.z) * @throws NullPointerException * if source is null. */ @Override public Vector3 subtract(final ReadOnlyVector3 source, final Vector3 store) { return subtract(source.getX(), source.getY(), source.getZ(), store); }
/** * <code>averagePoints</code> selects the sphere center to be the average of the points and the sphere radius to be * the smallest value to enclose all points. * * @param points * the list of points to contain. */ public void averagePoints(final Vector3[] points) { _center.set(points[0]); for (int i = 1; i < points.length; i++) { _center.addLocal(points[i]); } final double quantity = 1.0 / points.length; _center.multiplyLocal(quantity); double maxRadiusSqr = 0; for (int i = 0; i < points.length; i++) { final Vector3 diff = points[i].subtract(_center, _compVect1); final double radiusSqr = diff.lengthSquared(); if (radiusSqr > maxRadiusSqr) { maxRadiusSqr = radiusSqr; } } setRadius(Math.sqrt(maxRadiusSqr) + radiusEpsilon - 1f); }
/** * <code>averagePoints</code> selects the sphere center to be the average of the points and the sphere radius to be * the smallest value to enclose all points. * * @param points * the list of points to contain. */ public void averagePoints(final Vector3[] points) { _center.set(points[0]); for (int i = 1; i < points.length; i++) { _center.addLocal(points[i]); } final double quantity = 1.0 / points.length; _center.multiplyLocal(quantity); double maxRadiusSqr = 0; for (int i = 0; i < points.length; i++) { final Vector3 diff = points[i].subtract(_center, _compVect1); final double radiusSqr = diff.lengthSquared(); if (radiusSqr > maxRadiusSqr) { maxRadiusSqr = radiusSqr; } } setRadius(Math.sqrt(maxRadiusSqr) + radiusEpsilon - 1f); }
/** * Calculates the minimum bounding sphere of 3 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 acrossB = a.cross(b, null); final double Denominator = 2.0 * acrossB.dot(acrossB); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared()) .addLocal(b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
/** * Calculates the minimum bounding sphere of 3 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 acrossB = a.cross(b, null); final double Denominator = 2.0 * acrossB.dot(acrossB); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = acrossB.cross(a, null).multiplyLocal(b.lengthSquared()) .addLocal(b.cross(acrossB, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
/** * Calculates the minimum bounding sphere of 4 points. Used in welzl's algorithm. * * @param O * The 1st point inside the sphere. * @param A * The 2nd point inside the sphere. * @param B * The 3rd point inside the sphere. * @param C * The 4th point inside the sphere. * @see #calcWelzl(java.nio.FloatBuffer) */ private void setSphere(final Vector3 O, final Vector3 A, final Vector3 B, final Vector3 C) { final Vector3 a = A.subtract(O, null); final Vector3 b = B.subtract(O, null); final Vector3 c = C.subtract(O, null); final double Denominator = 2.0 * (a.getX() * (b.getY() * c.getZ() - c.getY() * b.getZ()) - b.getX() * (a.getY() * c.getZ() - c.getY() * a.getZ()) + c.getX() * (a.getY() * b.getZ() - b.getY() * a.getZ())); if (Denominator == 0) { _center.set(0, 0, 0); setRadius(0); } else { final Vector3 o = a.cross(b, null).multiplyLocal(c.lengthSquared()) .addLocal(c.cross(a, null).multiplyLocal(b.lengthSquared())) .addLocal(b.cross(c, null).multiplyLocal(a.lengthSquared())).divideLocal(Denominator); setRadius(o.length() * radiusEpsilon); O.add(o, _center); } }
public void reconstruct(final Vector3 top, final Vector3 bottom, final double radius) { // our temp vars final Vector3 localTranslation = Vector3.fetchTempInstance(); final Vector3 capsuleUp = Vector3.fetchTempInstance(); // first make the capsule the right shape height = top.distance(bottom); this.radius = radius; setGeometryData(); // now orient it in space. localTranslation.set(_localTransform.getTranslation()); top.add(bottom, localTranslation).multiplyLocal(.5); // rotation that takes us from 0,1,0 to the unit vector described by top/center. top.subtract(localTranslation, capsuleUp).normalizeLocal(); final Matrix3 rotation = Matrix3.fetchTempInstance(); rotation.fromStartEndLocal(Vector3.UNIT_Y, capsuleUp); _localTransform.setRotation(rotation); Vector3.releaseTempInstance(localTranslation); Vector3.releaseTempInstance(capsuleUp); Matrix3.releaseTempInstance(rotation); updateWorldTransform(false); }
public void reconstruct(final Vector3 top, final Vector3 bottom, final double radius) { // our temp vars final Vector3 localTranslation = Vector3.fetchTempInstance(); final Vector3 capsuleUp = Vector3.fetchTempInstance(); // first make the capsule the right shape height = top.distance(bottom); this.radius = radius; setGeometryData(); // now orient it in space. localTranslation.set(_localTransform.getTranslation()); top.add(bottom, localTranslation).multiplyLocal(.5); // rotation that takes us from 0,1,0 to the unit vector described by top/center. top.subtract(localTranslation, capsuleUp).normalizeLocal(); final Matrix3 rotation = Matrix3.fetchTempInstance(); rotation.fromStartEndLocal(Vector3.UNIT_Y, capsuleUp); _localTransform.setRotation(rotation); Vector3.releaseTempInstance(localTranslation); Vector3.releaseTempInstance(capsuleUp); Matrix3.releaseTempInstance(rotation); updateWorldTransform(false); }