List of usage examples for com.badlogic.gdx.math Vector3 dst
@Override
public float dst(final Vector3 vector)
From source file:com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush.java
License:Apache License
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;//from w w w.j ava2 s .co m 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); }
From source file:com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush.java
License:Apache License
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;/*from w ww. j a v a 2 s .c o m*/ 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); }
From source file:com.mbrlabs.mundus.tools.brushes.TerrainBrush.java
License:Apache License
private void flatten() { 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;// w w w .j av a 2s. c o m 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); final float newHeight = heightSample * elevation; if (Math.abs(heightSample - newHeight) < Math .abs(heightSample - terrain.heightData[index])) { terrain.heightData[index] = newHeight; } } } } } terrain.update(); terrainHeightModified = true; }
From source file:com.mbrlabs.mundus.tools.brushes.TerrainBrush.java
License:Apache License
private void raiseLower(BrushAction action) { 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;//from w w w. j av a 2 s.com 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; }
From source file:gaia.cu9.ari.gaiaorbit.util.g3d.MeshBuilder2.java
License:Apache License
@Override public void arrow(float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions) { Vector3 begin = tmp(x1, y1, z1), end = tmp(x2, y2, z2); float length = begin.dst(end); float coneHeight = length * capLength; float coneDiameter = 2 * (float) (coneHeight * Math.sqrt(1f / 3)); float stemLength = length - coneHeight; float stemDiameter = coneDiameter * stemThickness; Vector3 up = tmp(end).sub(begin).nor(); Vector3 forward = tmp(up).crs(Vector3.Z); if (forward.isZero()) forward.set(Vector3.X);/*from www .j ava2 s . c om*/ forward.crs(up).nor(); Vector3 left = tmp(up).crs(forward).nor(); Vector3 direction = tmp(end).sub(begin).nor(); // Matrices Matrix4 userTransform = getVertexTransform(tmp()); Matrix4 transform = tmp(); float[] val = transform.val; val[Matrix4.M00] = left.x; val[Matrix4.M01] = up.x; val[Matrix4.M02] = forward.x; val[Matrix4.M10] = left.y; val[Matrix4.M11] = up.y; val[Matrix4.M12] = forward.y; val[Matrix4.M20] = left.z; val[Matrix4.M21] = up.z; val[Matrix4.M22] = forward.z; Matrix4 temp = tmp(); // Stem transform.setTranslation(tmp(direction).scl(stemLength / 2).add(x1, y1, z1)); setVertexTransform(temp.set(transform).mul(userTransform)); cylinder(stemDiameter, stemLength, stemDiameter, divisions); // Cap transform.setTranslation(tmp(direction).scl(stemLength).add(x1, y1, z1)); setVertexTransform(temp.set(transform).mul(userTransform)); cone(coneDiameter, coneHeight, coneDiameter, divisions); setVertexTransform(userTransform); cleanup(); }