/** * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return same as multiply(-1, store) */ @Override public Vector3 negate(final Vector3 store) { return multiply(-1, store); }
@Test public void testMultiply() { final Vector3 vec1 = new Vector3(1, -1, 2); final Vector3 vec2 = vec1.multiply(2.0, null); final Vector3 vec2B = vec1.multiply(2.0, new Vector3()); assertEquals(new Vector3(2.0, -2.0, 4.0), vec2); assertEquals(new Vector3(2.0, -2.0, 4.0), vec2B); vec2.multiplyLocal(0.5); assertEquals(new Vector3(1.0, -1.0, 2.0), vec2); final Vector3 vec3 = vec1.multiply(vec2, null); final Vector3 vec3B = vec1.multiply(vec2, new Vector3()); assertEquals(new Vector3(1, 1, 4), vec3); assertEquals(new Vector3(1, 1, 4), vec3B); final Vector3 vec4 = vec1.multiply(2, 3, 2, null); final Vector3 vec4B = vec1.multiply(2, 3, 2, new Vector3()); assertEquals(new Vector3(2, -3, 4), vec4); assertEquals(new Vector3(2, -3, 4), vec4B); vec1.multiplyLocal(0.5, 0.5, 0.5); assertEquals(new Vector3(0.5, -0.5, 1.0), vec1); vec1.multiplyLocal(vec2); assertEquals(new Vector3(0.5, 0.5, 2.0), vec1); }
final double sinTheta = MathUtils.sin(theta); radialAxis.set(cosTheta, sinTheta, 0); radialAxis.multiply(_centerRadius, torusMiddle);
/** * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return same as multiply(-1, store) */ @Override public Vector3 negate(final Vector3 store) { return multiply(-1, store); }
final double sinTheta = MathUtils.sin(theta); radialAxis.set(cosTheta, sinTheta, 0); radialAxis.multiply(_centerRadius, torusMiddle);
@Override public double getRadius() { double radius = 0.0; radius = Math.max(radius, _xAxis.multiply(_extent.getX(), _compVect1).length()); radius = Math.max(radius, _yAxis.multiply(_extent.getY(), _compVect1).length()); radius = Math.max(radius, _zAxis.multiply(_extent.getZ(), _compVect1).length()); return radius; }
@Override public double getRadius() { double radius = 0.0; radius = Math.max(radius, _xAxis.multiply(_extent.getX(), _compVect1).length()); radius = Math.max(radius, _yAxis.multiply(_extent.getY(), _compVect1).length()); radius = Math.max(radius, _zAxis.multiply(_extent.getZ(), _compVect1).length()); return radius; }
/** * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, if the vector is * 0, 0, 0) then a new vector (0, 0, 0) is returned. * * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return a new unit vector (or 0, 0, 0 if this unit is 0 length) */ @Override public Vector3 normalize(final Vector3 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector3.ZERO) : new Vector3(Vector3.ZERO); }
/** * Creates a new unit length vector from this one by dividing by length. If the length is 0, (ie, if the vector is * 0, 0, 0) then a new vector (0, 0, 0) is returned. * * @param store * the vector to store the result in for return. If null, a new vector object is created and returned. * @return a new unit vector (or 0, 0, 0 if this unit is 0 length) */ @Override public Vector3 normalize(final Vector3 store) { final double lengthSq = lengthSquared(); if (Math.abs(lengthSq) > MathUtils.EPSILON) { return multiply(MathUtils.inverseSqrt(lengthSq), store); } return store != null ? store.set(Vector3.ZERO) : new Vector3(Vector3.ZERO); }
/** * random returns a random point within the plane defined by: A, B, C, and (B + C) - A. * * @param result * Vector to store result in * @return a random point within the rectangle. */ @Override public Vector3 random(Vector3 result) { if (result == null) { result = new Vector3(); } final double s = MathUtils.nextRandomFloat(); final double t = MathUtils.nextRandomFloat(); final double aMod = 1.0 - s - t; final Vector3 temp1 = Vector3.fetchTempInstance(); final Vector3 temp2 = Vector3.fetchTempInstance(); final Vector3 temp3 = Vector3.fetchTempInstance(); result.set(_a.multiply(aMod, temp1).addLocal(_b.multiply(s, temp2).addLocal(_c.multiply(t, temp3)))); Vector3.releaseTempInstance(temp1); Vector3.releaseTempInstance(temp2); Vector3.releaseTempInstance(temp3); return result; }
/** * random returns a random point within the plane defined by: A, B, C, and (B + C) - A. * * @param result * Vector to store result in * @return a random point within the rectangle. */ @Override public Vector3 random(Vector3 result) { if (result == null) { result = new Vector3(); } final double s = MathUtils.nextRandomFloat(); final double t = MathUtils.nextRandomFloat(); final double aMod = 1.0 - s - t; final Vector3 temp1 = Vector3.fetchTempInstance(); final Vector3 temp2 = Vector3.fetchTempInstance(); final Vector3 temp3 = Vector3.fetchTempInstance(); result.set(_a.multiply(aMod, temp1).addLocal(_b.multiply(s, temp2).addLocal(_c.multiply(t, temp3)))); Vector3.releaseTempInstance(temp1); Vector3.releaseTempInstance(temp2); Vector3.releaseTempInstance(temp3); return result; }
_position.addLocal(_velocity.multiply(secondsPassed * 1000f, temp)); Vector3.releaseTempInstance(temp);
final double fRadialFraction = iR * fInvRS; // in [0,1) final Vector3 kRadial = tempVc.set(afCos[iR], 0, afSin[iR]); kRadial.multiply(fSliceRadius, tempVa); _meshData.getVertexBuffer().put((float) (kSliceCenter.getX() + tempVa.getX())) .put((float) (kSliceCenter.getY() + tempVa.getY()))
final double fRadialFraction = iR * fInvRS; // in [0,1) final Vector3 kRadial = tempVc.set(afCos[iR], 0, afSin[iR]); kRadial.multiply(fSliceRadius, tempVa); _meshData.getVertexBuffer().put((float) (kSliceCenter.getX() + tempVa.getX())) .put((float) (kSliceCenter.getY() + tempVa.getY()))
_center.multiply(scale, box._center); rotate.applyPost(box._center, box._center); box._center.addLocal(translate);
_center.multiply(scale, box._center); rotate.applyPost(box._center, box._center); box._center.addLocal(translate);
/** * 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; }
calc1.set(t).subtractLocal(n.multiply(dot, calc2)).normalizeLocal(); tangentBuffer.put(calc1.getXf()).put(calc1.getYf()).put(calc1.getZf());
_position.addLocal(_velocity.multiply(secondsPassed * 1000f, temp)); Vector3.releaseTempInstance(temp);