/** * @return a size 8 array of Vectors representing the 8 points of the box. */ public Vector3[] computeVertices() { final Vector3 rVal[] = new Vector3[8]; rVal[0] = _center.add(-_xExtent, -_yExtent, -_zExtent, null); rVal[1] = _center.add(_xExtent, -_yExtent, -_zExtent, null); rVal[2] = _center.add(_xExtent, _yExtent, -_zExtent, null); rVal[3] = _center.add(-_xExtent, _yExtent, -_zExtent, null); rVal[4] = _center.add(_xExtent, -_yExtent, _zExtent, null); rVal[5] = _center.add(-_xExtent, -_yExtent, _zExtent, null); rVal[6] = _center.add(_xExtent, _yExtent, _zExtent, null); rVal[7] = _center.add(-_xExtent, _yExtent, _zExtent, null); 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; }
/** * * @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 rVal[] = new Vector3[8]; rVal[0] = _center.add(-_xExtent, -_yExtent, -_zExtent, null); rVal[1] = _center.add(_xExtent, -_yExtent, -_zExtent, null); rVal[2] = _center.add(_xExtent, _yExtent, -_zExtent, null); rVal[3] = _center.add(-_xExtent, _yExtent, -_zExtent, null); rVal[4] = _center.add(_xExtent, -_yExtent, _zExtent, null); rVal[5] = _center.add(-_xExtent, -_yExtent, _zExtent, null); rVal[6] = _center.add(_xExtent, _yExtent, _zExtent, null); rVal[7] = _center.add(-_xExtent, _yExtent, _zExtent, null); return rVal; }
@Test public void testAdd() { final Vector3 vec1 = new Vector3(); final Vector3 vec2 = new Vector3(Vector3.ONE); vec1.addLocal(1, 2, 3); assertEquals(new Vector3(1, 2, 3), vec1); vec1.addLocal(-1, -2, -3); assertEquals(Vector3.ZERO, vec1); vec1.zero(); vec1.addLocal(vec2); assertEquals(Vector3.ONE, vec1); vec1.zero(); final Vector3 vec3 = vec1.add(vec2, new Vector3()); assertEquals(Vector3.ZERO, vec1); assertEquals(Vector3.ONE, vec3); final Vector3 vec4 = vec1.add(1, 0, 0, null); assertEquals(Vector3.ZERO, vec1); assertEquals(Vector3.UNIT_X, vec4); }
/** * Adds the values of the given source vector to 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 add(final ReadOnlyVector3 source, final Vector3 store) { return add(source.getX(), source.getY(), source.getZ(), store); }
/** * 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); } }
/** * Adds the values of the given source vector to 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 add(final ReadOnlyVector3 source, final Vector3 store) { return add(source.getX(), source.getY(), source.getZ(), store); }
/** * 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); } }
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); }
BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 1); _position.add(bbX, tempVec3).addLocal(bbY); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 2); _position.add(bbX, tempVec3).subtractLocal(bbY); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 3); break; BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 0); _position.add(bbX, tempVec3).addLocal(3 * bbY.getX(), 3 * bbY.getY(), 3 * bbY.getZ()); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 1); _position.add(bbX, tempVec3).subtractLocal(bbY); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 2); break; BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex); _position.add(bbX, tempVec3); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 1); break;
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); }
/** * 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); } }
SkeletalDebugger.bone.setWorldTranslation(stPnt.add(endPnt, store).divideLocal(2.0)); Vector3.releaseTempInstance(store);
/** * 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); } }
SkeletalDebugger.bone.setWorldTranslation(stPnt.add(endPnt, store).divideLocal(2.0)); Vector3.releaseTempInstance(store);
toruspoints[i].add(pointB, N); T.cross(N, B); B.cross(T, N);
toruspoints[i].add(pointB, N); T.cross(N, B); B.cross(T, N);
BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 0); _position.add(bbX, tempVec3).addLocal(3 * bbY.getX(), 3 * bbY.getY(), 3 * bbY.getZ()); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 1); _position.add(bbX, tempVec3).subtractLocal(bbY); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 2); break; BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex); _position.add(bbX, tempVec3); BufferUtils.setInBuffer(tempVec3, vertexBuffer, startIndex + 1); break;
final Vector3 kBoxCenter = (rkBox0._center.add(rkBox1._center, Vector3.fetchTempInstance())).multiplyLocal(.5);