Java Code Examples for com.jme3.math.Vector3f#setX()

The following examples show how to use com.jme3.math.Vector3f#setX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestReverb.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
  time += tpf;

  if (time > nextTime) {
    Vector3f v = new Vector3f();
    v.setX(FastMath.nextRandomFloat());
    v.setY(FastMath.nextRandomFloat());
    v.setZ(FastMath.nextRandomFloat());
    v.multLocal(40, 2, 40);
    v.subtractLocal(20, 1, 20);

    audioSource.setLocalTranslation(v);
    audioSource.playInstance();
    time = 0;
    nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
  }
}
 
Example 2
Source File: TestReverb.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
  time += tpf;

  if (time > nextTime) {
    Vector3f v = new Vector3f();
    v.setX(FastMath.nextRandomFloat());
    v.setY(FastMath.nextRandomFloat());
    v.setZ(FastMath.nextRandomFloat());
    v.multLocal(40, 2, 40);
    v.subtractLocal(20, 1, 20);

    audioSource.setLocalTranslation(v);
    audioSource.playInstance();
    time = 0;
    nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
  }
}
 
Example 3
Source File: CreateSkyDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * The process of creating a new sky.
 */
@FxThread
private void createSkyInBackground() {

    final AssetManager assetManager = EditorUtil.getAssetManager();
    final NodeTree<?> nodeTree = getNodeTree();
    final ChangeConsumer changeConsumer = notNull(nodeTree.getChangeConsumer());

    final FloatTextField normalScaleXSpinner = getNormalScaleXField();
    final FloatTextField normalScaleYSpinner = getNormalScaleYField();
    final FloatTextField normalScaleZSpinner = getNormalScaleZField();

    final Vector3f scale = new Vector3f();
    scale.setX(normalScaleXSpinner.getValue());
    scale.setY(normalScaleYSpinner.getValue());
    scale.setZ(normalScaleZSpinner.getValue());

    final ComboBox<SkyType> skyTypeComboBox = getSkyTypeComboBox();
    final SingleSelectionModel<SkyType> selectionModel = skyTypeComboBox.getSelectionModel();
    final SkyType selectedItem = selectionModel.getSelectedItem();

    if (selectedItem == SkyType.SINGLE_TEXTURE) {
        createSingleTexture(assetManager, changeConsumer, scale);
    } else if (selectedItem == SkyType.MULTIPLE_TEXTURE) {
        createMultipleTexture(assetManager, changeConsumer, scale);
    }
}
 
Example 4
Source File: RelativeWanderBehavior.java    From MonkeyBrains with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see SimpleWanderBehavior#changeSteer(float)
 */
@Override
protected void changeSteer(float tpf) {
    time -= tpf;
    if (time <= 0) {
        lastSteer = currentSteer;
        Vector3f randomSteer = this.newRandomSteer();
        randomSteer.setX(lastSteer.x*(1-relativeFactor) + randomSteer.getX()*relativeFactor);
        randomSteer.setY(lastSteer.y*(1-relativeFactor) + randomSteer.getY()*relativeFactor);
        randomSteer.setZ(lastSteer.z*(1-relativeFactor) + randomSteer.getZ()*relativeFactor);
        currentSteer = randomSteer;
        time = timeInterval;
    }
}
 
Example 5
Source File: AbstractStrengthSteeringBehavior.java    From MonkeyBrains with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Calculates the steering force with the specified strength. <br><br>
 *
 * If the strength was not setted up it the return calculateSteering(), the
 * unmodified force.
 *
 * @return The steering force with the specified strength.
 */
@Override
protected Vector3f calculateSteering() {

    Vector3f strengthSteeringForce = calculateRawSteering();

    switch (this.type) {
        case SCALAR:
            strengthSteeringForce = strengthSteeringForce.mult(this.scalar);
            break;

        case AXIS:
            strengthSteeringForce.setX(strengthSteeringForce.getX() * this.x);
            strengthSteeringForce.setY(strengthSteeringForce.getY() * this.y);
            strengthSteeringForce.setZ(strengthSteeringForce.getZ() * this.z);
            break;

        case PLANE:
            strengthSteeringForce = this.plane.getClosestPoint(strengthSteeringForce).mult(this.scalar);
            break;

    }
    
    //if there is no steering force, than the steering vector is zero
    if (strengthSteeringForce.equals(Vector3f.NAN)) {
        strengthSteeringForce = Vector3f.ZERO.clone();
    }
    
    return strengthSteeringForce;
}
 
Example 6
Source File: UnalignedCollisionAvoidanceBehavior.java    From MonkeyBrains with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * removes negative zeros
 */
private void removeNegativeZeros(Vector3f vector) {
    if (vector.x == -0) {
        vector.setX(0);
    }
    if (vector.y == -0) {
        vector.setY(0);
    }
    if (vector.z == -0) {
        vector.setZ(0);
    }
}
 
Example 7
Source File: Intersection.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static final void findMinMax(float x0, float x1, float x2, Vector3f minMax) {
    minMax.set(x0, x0, 0);
    if (x1 < minMax.x) {
        minMax.setX(x1);
    }
    if (x1 > minMax.y) {
        minMax.setY(x1);
    }
    if (x2 < minMax.x) {
        minMax.setX(x2);
    }
    if (x2 > minMax.y) {
        minMax.setY(x2);
    }
}
 
Example 8
Source File: Intersection.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static final void findMinMax(float x0, float x1, float x2, Vector3f minMax) {
    minMax.set(x0, x0, 0);
    if (x1 < minMax.x) {
        minMax.setX(x1);
    }
    if (x1 > minMax.y) {
        minMax.setY(x1);
    }
    if (x2 < minMax.x) {
        minMax.setX(x2);
    }
    if (x2 > minMax.y) {
        minMax.setY(x2);
    }
}
 
Example 9
Source File: ScaleToolControl.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@JmeThread
@Override
public void processTransform() {

    final EditorTransformSupport editorControl = getEditorControl();

    final LocalObjects local = LocalObjects.get();
    final Camera camera = editorControl.getCamera();
    final InputManager inputManager = EditorUtil.getInputManager();
    final Transform transform = notNull(editorControl.getTransformCenter());

    // cursor position and selected position vectors
    final Vector2f cursorPos = inputManager.getCursorPosition();
    final Vector3f transformOnScreen = camera.getScreenCoordinates(transform.getTranslation(), local.nextVector());
    final Vector2f selectedCoords = local.nextVector(transformOnScreen.getX(), transformOnScreen.getY());

    // set new deltaVector if it's not set (scale tool stores position of a cursor)
    if (Float.isNaN(editorControl.getTransformDeltaX())) {
        editorControl.setTransformDeltaX(cursorPos.getX());
        editorControl.setTransformDeltaY(cursorPos.getY());
    }

    final Node parentNode = getParentNode();
    final Node childNode = getChildNode();

    // Picked vector
    final Spatial toTransform = notNull(editorControl.getToTransform());
    final TransformationMode transformationMode = editorControl.getTransformationMode();
    transformationMode.prepareToScale(parentNode, childNode, transform, camera);

    // scale according to distance
    final Vector3f deltaVector = local.nextVector(editorControl.getTransformDeltaX(), editorControl.getTransformDeltaY(), 0F);
    final Vector2f delta2d = local.nextVector(deltaVector.getX(), deltaVector.getY());
    final Vector3f baseScale = local.nextVector(transform.getScale()); // default scale
    final Vector3f pickedVector = local.nextVector(transformationMode.getScaleAxis(transform, editorControl.getPickedAxis(), camera));
    pickedVector.setX(abs(pickedVector.getX()));
    pickedVector.setY(abs(pickedVector.getY()));
    pickedVector.setZ(abs(pickedVector.getZ()));

    if (Config.DEV_TRANSFORMS_DEBUG) {
        System.out.println("Base scale " + baseScale + ", pickedVector " + pickedVector);
    }

    // scale object
    float disCursor = cursorPos.distance(selectedCoords);
    float disDelta = delta2d.distance(selectedCoords);
    float scaleValue = (float) (cursorPos.distance(delta2d) * 0.01f * Math.sqrt(baseScale.length()));

    if (disCursor > disDelta) {
        baseScale.addLocal(pickedVector.mult(scaleValue, local.nextVector()));
    } else {
        scaleValue = Math.min(scaleValue, 0.999f); // remove negateve values
        baseScale.subtractLocal(pickedVector.mult(scaleValue, local.nextVector()));
    }

    parentNode.setLocalScale(baseScale);

    if (Config.DEV_TRANSFORMS_DEBUG) {
        System.out.println("New scale " + baseScale + ", result world " + childNode.getWorldScale());
    }

    parentNode.setLocalScale(baseScale);
    toTransform.setLocalScale(childNode.getWorldScale());

    editorControl.notifyTransformed(toTransform);
}