Java Code Examples for com.badlogic.gdx.math.MathUtils#isZero()

The following examples show how to use com.badlogic.gdx.math.MathUtils#isZero() . 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: DialogDrawables.java    From skin-composer with MIT License 6 votes vote down vote up
private void refreshDrawableDisplay() {
    contentTable.clear();
    
    if (drawables.size == 0) {
        Label label = new Label("No drawables have been added!", getSkin());
        if (main.getAtlasData().getDrawables().size > 0) {
            label.setText("No drawables match filter!");
        }
        contentTable.add(label);
    } else {
        if (MathUtils.isZero(zoomSlider.getValue())) {
            refreshDrawableDisplayDetail();
        } else {
            refreshDrawableDisplayNormal();
        }
    }
}
 
Example 2
Source File: StyleData.java    From skin-composer with MIT License 6 votes vote down vote up
public boolean hasAllNullFields() {
    boolean returnValue = true;
    for(StyleProperty property : this.properties.values()) {
        if (property.value != null) {
            if (property.value instanceof Double) {
                if (!MathUtils.isZero((float) (double) property.value)) {
                    returnValue = false;
                }
            } else if (property.value instanceof Integer) {
                if ((int) property.value != 0) {
                    returnValue = false;
                }
            } else if (property.value instanceof Float) {
                if (!MathUtils.isZero((float) property.value)) {
                    returnValue = false;
                }
            } else {
                returnValue = false;
            }
            break;
        }
    }
    
    var parentStyle = findParentStyle();
    return returnValue && (parentStyle == null || parentStyle.hasAllNullFields());
}
 
Example 3
Source File: ProjectData.java    From skin-composer with MIT License 5 votes vote down vote up
/**
 * Checks if this is an old project and has drawables with minWidth or minHeight incorrectly set to 0. This error
 * was resolved in version 30.
 * @return
 * @see ProjectData#fixInvalidMinWidthHeight()
 */
public boolean checkForInvalidMinWidthHeight() {
    var returnValue = !loadedVersion.equals(Main.VERSION) && getAtlasData().getDrawables().size > 0;
    
    if (returnValue) {
        for (var drawable : getAtlasData().getDrawables()) {
            if (!drawable.tiled && (!MathUtils.isZero(drawable.minWidth) || !MathUtils.isZero(drawable.minHeight))) {
                returnValue = false;
                break;
            }
        }
    }
    
    return returnValue;
}
 
Example 4
Source File: RadixClient.java    From Radix with MIT License 5 votes vote down vote up
private void updatePositionRotationAndroid() {
    if(!MathUtils.isZero(rotateTouchpad.getKnobPercentX()) || !MathUtils.isZero(rotateTouchpad.getKnobPercentY())) {
        float rotMult = 200 * Gdx.graphics.getDeltaTime();

        player.getRotation().offset(rotateTouchpad.getKnobPercentY() * rotMult, rotateTouchpad.getKnobPercentX() * rotMult);
        updateSelectedBlock();
        gameRenderer.calculateFrustum();
    }

    if(!MathUtils.isZero(moveTouchpad.getKnobPercentX()) || !MathUtils.isZero(moveTouchpad.getKnobPercentY())) {
        float posMult = 4.5f * Gdx.graphics.getDeltaTime();

        float deltaX = 0;
        float deltaZ = 0;
        float yawSine = MathUtils.sinDeg(player.getRotation().getYaw());
        float yawCosine = MathUtils.cosDeg(player.getRotation().getYaw());
        deltaX += yawSine * moveTouchpad.getKnobPercentY() * posMult;
        deltaZ += -yawCosine * moveTouchpad.getKnobPercentY() * posMult;
        deltaX += yawCosine * moveTouchpad.getKnobPercentX() * posMult;
        deltaZ += yawSine * moveTouchpad.getKnobPercentX() * posMult;

        if(!movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)
                && !movementHandler.checkDeltaCollision(player, deltaX, 0, deltaZ)) {
            player.getPosition().offset(deltaX, 0, deltaZ);
            gameRenderer.calculateFrustum();
        }
    }
}
 
Example 5
Source File: SpinAroundToFaceHumanTask.java    From GdxDemo3D with Apache License 2.0 5 votes vote down vote up
@Override
public Status execute () {
	if (facingHuman) {
		return Status.SUCCEEDED;
	}
	DogCharacter dog = getObject();
	updateAnimation(dog);
	if (dog.currentTaskAnimation == getTaskAnimation()) {
		// Get current model orientation
		float currentDogOrientation = dog.getBoneOrientation(DogCharacter.DogArmature.FRONT_SPINE.id);
		
		// Calculate the difference between current and target orientation
		float orientationDiff = ArithmeticUtils.wrapAngleAroundZero(currentDogOrientation - targetOrientation);
		
		// Is dog facing human with enough precision?
		if (MathUtils.isZero(orientationDiff, ORIENTATION_TOLERANCE)) {
			// Make the task succeed on the next frame
			facingHuman = true;

			// Bark
			GameScreen.screen.sounds.bark.play();

			// Finish the animation
			truncateAnimationCleanly(dog, currentDogOrientation);
		}
	}
	return Status.RUNNING;
}
 
Example 6
Source File: ResizeWidget.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public float getMinHeight() {
    return MathUtils.isZero(minHeight) ? stack.getMinHeight() : minHeight;
}
 
Example 7
Source File: ResizeWidget.java    From skin-composer with MIT License 4 votes vote down vote up
@Override
public float getMinWidth() {
    return MathUtils.isZero(minWidth) ? stack.getMinWidth() : minWidth;
}