Java Code Examples for com.jme3.math.Vector2f#getY()

The following examples show how to use com.jme3.math.Vector2f#getY() . 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: ChangeHeightTerrainToolControl.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Notify about changing height by the point in the terrain.
 *
 * @param terrain the terrain.
 * @param point   the point.
 */
@JmeThread
protected void change(@NotNull final Terrain terrain, @NotNull final Vector2f point) {

    final Node terrainNode = (Node) terrain;
    final Vector3f scale = terrainNode.getWorldScale();

    final int halfSize = terrain.getTerrainSize() / 2;
    final int x = Math.round((point.x / scale.x) + halfSize);
    final int z = Math.round((point.y / scale.z) + halfSize);

    final HeightPoint heightPoint = new HeightPoint(point.getX(), point.getY(), x, z);

    final ObjectDictionary<Terrain, ObjectDictionary<HeightPoint, Float>> originalHeight = getOriginalHeight();
    final ObjectDictionary<HeightPoint, Float> terrainHeights = originalHeight.get(terrain, DICTIONARY_FACTORY);
    if (terrainHeights.containsKey(heightPoint)) {
        return;
    }

    final float height = terrain.getHeightmapHeight(point);
    terrainHeights.put(heightPoint, height);
}
 
Example 2
Source File: EditorUtil.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Get the angle between these points.
 *
 * @param center the center.
 * @param first  the first point.
 * @param second the second point.
 * @return the angle between these points.
 */
@FromAnyThread
public static float getAngle(
        @NotNull Vector2f center,
        @NotNull Vector2f first,
        @NotNull Vector2f second
) {

    var x = center.getX();
    var y = center.getY();

    var ax = first.getX() - x;
    var ay = first.getY() - y;
    var bx = second.getX() - x;
    var by = second.getY() - y;

    var delta = (float) ((ax * bx + ay * by) / Math.sqrt((ax * ax + ay * ay) * (bx * bx + by * by)));

    if (delta > 1.0) {
        return 0.0F;
    } else if (delta < -1.0) {
        return 180.0F;
    }

    return (float) toDegrees(acos(delta));
}
 
Example 3
Source File: Mesh.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Scales the texture coordinate buffer on this mesh by the given
 * scale factor. 
 * <p>
 * Note that values above 1 will cause the 
 * texture to tile, while values below 1 will cause the texture 
 * to stretch.
 * </p>
 * 
 * @param scaleFactor The scale factor to scale by. Every texture
 * coordinate is multiplied by this vector to get the result.
 * 
 * @throws IllegalStateException If there's no texture coordinate
 * buffer on the mesh
 * @throws UnsupportedOperationException If the texture coordinate
 * buffer is not in 2D float format.
 */
public void scaleTextureCoordinates(Vector2f scaleFactor){
    VertexBuffer tc = getBuffer(Type.TexCoord);
    if (tc == null)
        throw new IllegalStateException("The mesh has no texture coordinates");

    if (tc.getFormat() != VertexBuffer.Format.Float)
        throw new UnsupportedOperationException("Only float texture coord format is supported");

    if (tc.getNumComponents() != 2)
        throw new UnsupportedOperationException("Only 2D texture coords are supported");

    FloatBuffer fb = (FloatBuffer) tc.getData();
    fb.clear();
    for (int i = 0; i < fb.limit() / 2; i++){
        float x = fb.get();
        float y = fb.get();
        fb.position(fb.position()-2);
        x *= scaleFactor.getX();
        y *= scaleFactor.getY();
        fb.put(x).put(y);
    }
    fb.clear();
    tc.updateData(fb);
}