private static float calculateDeltaRotation( Vector3 currentPosition1, Vector3 currentPosition2, Vector3 previousPosition1, Vector3 previousPosition2) { Vector3 currentDirection = Vector3.subtract(currentPosition1, currentPosition2).normalized(); Vector3 previousDirection = Vector3.subtract(previousPosition1, previousPosition2).normalized(); float sign = Math.signum( previousDirection.x * currentDirection.y - previousDirection.y * currentDirection.x); return Vector3.angleBetweenVectors(currentDirection, previousDirection) * sign; } }
private static void updateEndPointUV(List<Vertex> vertices) { // Update UV coordinates of ending vertices for (int edgeIndex = 0; edgeIndex <= NUMBER_OF_SIDES; edgeIndex++) { int vertexIndex = vertices.size() - edgeIndex - 1; Vertex currentVertex = vertices.get(vertexIndex); currentVertex.setUvCoordinate( new UvCoordinate( currentVertex.getUvCoordinate().x, (Vector3.subtract( vertices.get(vertexIndex).getPosition(), vertices.get(vertexIndex - NUMBER_OF_SIDES - 1).getPosition()) .length() + vertices.get(vertexIndex - NUMBER_OF_SIDES - 1).getUvCoordinate().y))); } }
Vector3 normal = Vector3.subtract(centerPoint, nextPoint).normalized(); Vertex center = Vertex.builder()
float diff = Vector3.subtract(newPosition, startPosition).length(); float slopPixels = gesturePointersUtility.inchesToPixels(SLOP_INCHES); if (diff >= slopPixels) {
@Override protected boolean updateGesture(HitTestResult hitTestResult, MotionEvent motionEvent) { int actionId = motionEvent.getPointerId(motionEvent.getActionIndex()); int action = motionEvent.getActionMasked(); if (action == MotionEvent.ACTION_CANCEL) { cancel(); return false; } boolean touchEnded = action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP; if (touchEnded && (actionId == pointerId1 || actionId == pointerId2)) { complete(); return false; } if (action != MotionEvent.ACTION_MOVE) { return false; } Vector3 newPosition1 = GesturePointersUtility.motionEventToPosition(motionEvent, pointerId1); Vector3 newPosition2 = GesturePointersUtility.motionEventToPosition(motionEvent, pointerId2); float newGap = Vector3.subtract(newPosition1, newPosition2).length(); if (newGap == gap) { return false; } gapDelta = newGap - gap; gap = newGap; debugLog("Update: " + gapDelta); return true; }
@Override protected boolean updateGesture(HitTestResult hitTestResult, MotionEvent motionEvent) { int actionId = motionEvent.getPointerId(motionEvent.getActionIndex()); int action = motionEvent.getActionMasked(); if (action == MotionEvent.ACTION_MOVE) { Vector3 newPosition = GesturePointersUtility.motionEventToPosition(motionEvent, pointerId); if (!Vector3.equals(newPosition, position)) { delta.set(Vector3.subtract(newPosition, position)); position.set(newPosition); debugLog("Updated: " + pointerId + " : " + position); return true; } } else if (actionId == pointerId && (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP)) { complete(); } else if (action == MotionEvent.ACTION_CANCEL) { cancel(); } return false; }
Vector3 firstToSecond = Vector3.subtract(startPosition1, startPosition2); Vector3 firstToSecondDirection = firstToSecond.normalized(); Vector3 deltaPosition1 = Vector3.subtract(newPosition1, previousPosition1); Vector3 deltaPosition2 = Vector3.subtract(newPosition2, previousPosition2); previousPosition1.set(newPosition1); previousPosition2.set(newPosition2); gap = Vector3.subtract(newPosition1, newPosition2).length(); float separation = Math.abs(gap - startGap); float slopPixels = gesturePointersUtility.inchesToPixels(SLOP_INCHES);
private void updatePosition(FrameTime frameTime) { // Store in local variable for nullness static analysis. Vector3 desiredLocalPosition = this.desiredLocalPosition; if (desiredLocalPosition == null) { return; } Vector3 localPosition = getTransformableNode().getLocalPosition(); float lerpFactor = MathHelper.clamp(frameTime.getDeltaSeconds() * LERP_SPEED, 0, 1); localPosition = Vector3.lerp(localPosition, desiredLocalPosition, lerpFactor); float lengthDiff = Math.abs(Vector3.subtract(desiredLocalPosition, localPosition).length()); if (lengthDiff <= POSITION_LENGTH_THRESHOLD) { localPosition = desiredLocalPosition; this.desiredLocalPosition = null; } getTransformableNode().setLocalPosition(localPosition); }
public void add(Vector3 pointInWorld) { Vector3 pointInLocal = anchorNode.worldToLocalPoint(pointInWorld); List<Vector3> points = lineSimplifier.getPoints(); if (getNumOfPoints() < 1) { lineSimplifier.add(pointInLocal); return; } Vector3 prev = points.get(points.size() - 1); Vector3 diff = Vector3.subtract(prev, pointInLocal); if (diff.length() < MINIMUM_DISTANCE_BETWEEN_POINTS) { return; } lineSimplifier.add(pointInLocal); RenderableDefinition renderableDefinition = ExtrudedCylinder.makeExtrudedCylinder(CYLINDER_RADIUS, points, material); if (shape == null) { shape = ModelRenderable.builder().setSource(renderableDefinition).build().join(); node.setRenderable(shape); } else { shape.updateFromDefinition(renderableDefinition); } }
new UvCoordinate( vertices.get(currentSegmentVertexIndex).getUvCoordinate().x, (Vector3.subtract( position, vertices.get(previousSegmentVertexIndex).getPosition())
@Override public void onUpdate(FrameTime frameTime) { if (infoCard == null) { return; } // Typically, getScene() will never return null because onUpdate() is only called when the node // is in the scene. // However, if onUpdate is called explicitly or if the node is removed from the scene on a // different thread during onUpdate, then getScene may be null. if (getScene() == null) { return; } Vector3 cameraPosition = getScene().getCamera().getWorldPosition(); Vector3 cardPosition = infoCard.getWorldPosition(); Vector3 direction = Vector3.subtract(cameraPosition, cardPosition); Quaternion lookRotation = Quaternion.lookRotation(direction, Vector3.up()); infoCard.setWorldRotation(lookRotation); } }
float radius) { final Vector3 difference = Vector3.subtract(firstPoint, secondPoint); Vector3 directionFromTopToBottom = difference.normalized(); Quaternion rotationFromAToB = Quaternion.lookRotation(directionFromTopToBottom, desiredUp); rightDirection.scaled(radius * cosTheta), upDirection.scaled(radius * sinTheta))); Vector3 normal = Vector3.subtract(topPosition, directionFromTopToBottom.scaled(-halfHeight)).normalized(); topPosition = Vector3.add(topPosition, center); UvCoordinate uvCoordinate = new UvCoordinate(uStep * edgeIndex, 0); rightDirection.scaled(radius * cosTheta), upDirection.scaled(radius * sinTheta))); normal = Vector3.subtract(bottomPosition, directionFromTopToBottom.scaled(halfHeight)) .normalized(); bottomPosition = Vector3.add(bottomPosition, center);