private Vector3 calculateFaceNormal(int[] vertexIDs) { ArrayList<Vector3> vertices = mVertices.get(mObjects); Vector3 v1 = vertices.get(vertexIDs[0]); Vector3 v2 = vertices.get(vertexIDs[2]); Vector3 v3 = vertices.get(vertexIDs[1]); Vector3 vector1 = Vector3.subtractAndCreate(v2, v1); Vector3 vector2 = Vector3.subtractAndCreate(v3, v1); Vector3 normal = Vector3.crossAndCreate(vector1, vector2); normal.normalize(); return normal; }
@Override protected void applyTransformation() { if (mDiffPosition == null) mDiffPosition = Vector3.subtractAndCreate(mToPosition, mFromPosition); mMultipliedPosition.scaleAndSet(mDiffPosition, mInterpolatedTime); mAddedPosition.addAndSet(mFromPosition, mMultipliedPosition); mTransformable3D.setPosition(mAddedPosition); }
@Override protected void applyTransformation() { if (mDiffScale == null) mDiffScale = Vector3.subtractAndCreate(mToScale, mFromScale); mMultipliedScale.scaleAndSet(mDiffScale, mInterpolatedTime); mAddedScale.addAndSet(mFromScale, mMultipliedScale); mTransformable3D.setScale(mAddedScale); }
Vector3 controlPoint = Vector3.subtractAndCreate(mPoints.get(1), mPoints.get(0)); double oldDistance = mPoints.get(1).distanceTo(mPoints.get(2)); double newDistance = newPoints.get(1).distanceTo(newPoints.get(2)); controlPoint.multiply(newDistance / oldDistance); newPoints.set(0, Vector3.subtractAndCreate(mPoints.get(1), controlPoint)); controlPoint = Vector3.subtractAndCreate(mPoints.get(mPoints.size() - 2), mPoints.get(mPoints.size() - 1)); oldDistance = mPoints.get(mPoints.size() - 2).distanceTo(mPoints.get(mPoints.size() - 3)); newDistance = newPoints.get(newPoints.size() - 2).distanceTo(newPoints.get(newPoints.size() - 3)); controlPoint.multiply(newDistance / oldDistance); newPoints.set(newPoints.size() - 1, Vector3.subtractAndCreate(mPoints.get(mPoints.size() - 2), controlPoint));
/** * Constructs a {@link ArchimedeanSpiral3D} with the specified parameters. * * @param density {@code double} Factor which determines how tightly the spiral is curled. * @param start {@link Vector3} The point where the spiral should start from. * @param normal {@link Vector3} The normal vector of the plane the spiral is in. This is assumed to be * orthogonal to the vector formed from the start to the origin. * @param spiralIn {@code boolean} True if the spiral should move from the staring point in. False to move from starting point out. */ public ASpiral3D(double density, Vector3 start, Vector3 normal, boolean spiralIn) { // Store the provided initial conditions mSpiralIn = spiralIn; mDensity = density; mStart = Vector3.subtractAndCreate(start, Vector3.ZERO); mUp = normal.clone(); // Calculate the remaining conditions mCalculateTangents = false; // Create the initial tangent vector mCurrentTangent = Vector3.crossAndCreate(mStart, mUp); // The initial rotation is 0 radians about the up axis mRotation = new Quaternion(mUp, 0); }
/** * Calculates the side lengths that child nodes * of this node should have. */ protected void calculateChildSideLengths() { //Determine the distance on each axis Vector3 temp = Vector3.subtractAndCreate(mTransformedMax, mTransformedMin); temp.multiply(0.5f); //Divide it in half float overlap = 1.0f + mOverlap/100.0f; temp.multiply(overlap); temp.absoluteValue(); mChildLengths.setAll(temp); }
private boolean getIntersection( double fDst1, double fDst2, Vector3 P1, Vector3 P2) { if ((fDst1 * fDst2) >= 0.0f) return false; if (floatEqual(fDst1, fDst2)) return false; mHitPoint.multiply(0); mHitPoint.add(Vector3.subtractAndCreate(P2, P1)); mHitPoint.multiply(-fDst1/(fDst2-fDst1)); mHitPoint.add(P1); return true; }
Vector3 rad = new Vector3(); rad.setAll(radius, radius, radius); test_against_min = Vector3.subtractAndCreate(bs_position, rad); test_against_max = Vector3.addAndCreate(bs_position, rad); } else {
v3.setAll(vertices[vid3], vertices[vid3+1], vertices[vid3+2]); Vector3 vector1 = Vector3.subtractAndCreate(v2, v1); Vector3 vector2 = Vector3.subtractAndCreate(v3, v1);
rayStart = new Vector3(rayStart); rayEnd = new Vector3(rayEnd); Vector3 dir = Vector3.subtractAndCreate(rayEnd, rayStart); double len = dir.normalize(); double b = 2.0f * Vector3.dot(dir, Vector3.subtractAndCreate(rayStart, sphereCenter)); double c = Vector3.dot(sphereCenter, sphereCenter) + Vector3.dot(rayStart, rayStart) - 2.0f * Vector3.dot(sphereCenter, rayStart) - radius2;
/** * Intersects a ray defined by a start and end point and a {@link Plane}. * @param rayStart Startpoint of the ray * @param rayEnd Endpoint of the ray * @param plane The plane * @param hitPoint The intersection point (optional) * @return True if there is an intersection, false otherwise. */ public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }
Vector3 v2 = new Vector3(mesh.vertices[index23], mesh.vertices[index23 + 1], mesh.vertices[index23 + 2]); Vector3 normal = Vector3.crossAndCreate(Vector3.subtractAndCreate(v2, v0), Vector3.subtractAndCreate(v1, v0)); normal.inverse();
@Test public void testSubtractAndCreate() { final Vector3 u = new Vector3(1.1d, 2.2d, 3.3d); final Vector3 v = new Vector3(0.1d, 0.2d, 0.3d); final Vector3 t = Vector3.subtractAndCreate(u, v); assertNotNull(t); assertEquals(1d, t.x, 0); assertEquals(2d, t.y, 0); assertEquals(3d, t.z, 0); }
Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); rayDir.normalize(); p.set(t1, t2, t3);
@Test public void testSetToLookAtDirectionUp() { final Quaternion q = new Quaternion(1d, 2d, 3d, 4d); final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO); q.lookAt(lookAt, Vector3.Y); final double[] expected = q.toRotationMatrix().getDoubleValues(); final Matrix4 m = new Matrix4(); final Matrix4 out = m.setToLookAt(lookAt, Vector3.Y); assertNotNull(out); assertSame(out, m); final double[] result = out.getDoubleValues(); assertNotNull(result); for (int i = 0; i < expected.length; ++i) { assertEquals("Result: " + Arrays.toString(result), expected[i], result[i], 1e-14); } }
@Test public void testSetToLookAtPositionTargetUp() { final Quaternion q = new Quaternion(1d, 2d, 3d, 4d); final Vector3 lookAt = Vector3.subtractAndCreate(new Vector3(0, 10d, 10d), Vector3.ZERO); q.lookAt(lookAt, Vector3.Y); final double[] expected = q.toRotationMatrix().getDoubleValues(); final Matrix4 m = new Matrix4(); final Matrix4 out = m.setToLookAt(Vector3.ZERO, new Vector3(0, 10d, 10d), Vector3.Y); assertNotNull(out); assertSame(out, m); final double[] result = out.getDoubleValues(); assertNotNull(result); for (int i = 0; i < expected.length; ++i) { assertEquals("Result: " + Arrays.toString(result), expected[i], result[i], 1e-14); } }
Vector3 lightDirection = light.getDirectionVector().clone(); lightDirection.normalize(); Vector3 lightPosition = Vector3.subtractAndCreate(mFrustumCentroid, Vector3.multiplyAndCreate(lightDirection, distance));
private Vector3 calculateFaceNormal(int[] vertexIDs) { ArrayList<Vector3> vertices = mVertices.get(mObjects); Vector3 v1 = vertices.get(vertexIDs[0]); Vector3 v2 = vertices.get(vertexIDs[2]); Vector3 v3 = vertices.get(vertexIDs[1]); Vector3 vector1 = Vector3.subtractAndCreate(v2, v1); Vector3 vector2 = Vector3.subtractAndCreate(v3, v1); Vector3 normal = Vector3.crossAndCreate(vector1, vector2); normal.normalize(); return normal; }
@Override protected void applyTransformation() { if (mDiffPosition == null) mDiffPosition = Vector3.subtractAndCreate(mToPosition, mFromPosition); mMultipliedPosition.scaleAndSet(mDiffPosition, mInterpolatedTime); mAddedPosition.addAndSet(mFromPosition, mMultipliedPosition); mTransformable3D.setPosition(mAddedPosition); }
@Override protected void applyTransformation() { if (mDiffScale == null) mDiffScale = Vector3.subtractAndCreate(mToScale, mFromScale); mMultipliedScale.scaleAndSet(mDiffScale, mInterpolatedTime); mAddedScale.addAndSet(mFromScale, mMultipliedScale); mTransformable3D.setScale(mAddedScale); }