Java Code Examples for com.badlogic.gdx.math.Vector3#dst()

The following examples show how to use com.badlogic.gdx.math.Vector3#dst() . 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: TerrainBrush.java    From Mundus with Apache License 2.0 6 votes vote down vote up
private void raiseLower(BrushAction action) {
    Terrain terrain = terrainAsset.getTerrain();
    final Vector3 terPos = terrain.getPosition(tVec1);
    float dir = (action == BrushAction.PRIMARY) ? 1 : -1;
    for (int x = 0; x < terrain.vertexResolution; x++) {
        for (int z = 0; z < terrain.vertexResolution; z++) {
            final Vector3 vertexPos = terrain.getVertexPosition(tVec0, x, z);
            vertexPos.x += terPos.x;
            vertexPos.z += terPos.z;
            float distance = vertexPos.dst(brushPos);

            if (distance <= radius) {
                float elevation = getValueOfBrushPixmap(brushPos.x, brushPos.z, vertexPos.x, vertexPos.z, radius);
                terrain.heightData[z * terrain.vertexResolution + x] += dir * elevation * strength;
            }
        }
    }

    terrain.update();
    terrainHeightModified = true;
    getProjectManager().current().assetManager.addDirtyAsset(terrainAsset);
}
 
Example 2
Source File: TerrainBrush.java    From Mundus with Apache License 2.0 5 votes vote down vote up
private void flatten() {
    Terrain terrain = terrainAsset.getTerrain();
    final Vector3 terPos = terrain.getPosition(tVec1);
    for (int x = 0; x < terrain.vertexResolution; x++) {
        for (int z = 0; z < terrain.vertexResolution; z++) {
            final Vector3 vertexPos = terrain.getVertexPosition(tVec0, x, z);
            vertexPos.x += terPos.x;
            vertexPos.z += terPos.z;
            float distance = vertexPos.dst(brushPos);

            if (distance <= radius) {
                final int index = z * terrain.vertexResolution + x;
                final float diff = Math.abs(terrain.heightData[index] - heightSample);
                if (diff <= 1f) {
                    terrain.heightData[index] = heightSample;
                } else if (diff > 1f) {
                    final float elevation = getValueOfBrushPixmap(brushPos.x, brushPos.z, vertexPos.x, vertexPos.z,
                            radius);
                    // current height is lower than sample
                    if(heightSample > terrain.heightData[index]) {
                        terrain.heightData[index] += elevation * strength;
                    } else {
                        float newHeight = terrain.heightData[index] - elevation * strength;
                        if(diff > Math.abs(newHeight) || terrain.heightData[index] > heightSample) {
                            terrain.heightData[index] = newHeight;
                        }

                    }
                }
            }
        }
    }

    terrain.update();
    terrainHeightModified = true;
    getProjectManager().current().assetManager.addDirtyAsset(terrainAsset);
}
 
Example 3
Source File: Physics.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
private void executeRayCast(Vector3 position, Vector3 end, RayResultCallback callback) {
	raycastReport.reset();
	world.rayTest(position, end, callback);
	raycastReport.hit = callback.hasHit();
	if (raycastReport.hit) {
		float length = position.dst(end);
		raycastReport.hitDistance = length * callback.getClosestHitFraction();
		if (callback instanceof ClosestRayResultCallback) {
			ClosestRayResultCallback cb = (ClosestRayResultCallback) callback;
			Vector3 normal = tmp;
			cb.getHitNormalWorld(tmp);
			raycastReport.hitNormal.set(normal.x, normal.y, normal.z);
		}
	}
}