Search in sources :

Example 36 with Triangle

use of com.jme3.math.Triangle in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method getNormal.

protected Vector3f getNormal(float x, float z, Vector2f xz) {
    x -= 0.5f;
    z -= 0.5f;
    float col = FastMath.floor(x);
    float row = FastMath.floor(z);
    boolean onX = false;
    if (// what triangle to interpolate on
    1 - (x - col) - (z - row) < 0)
        onX = true;
    // v1--v2  ^
    // |  / |  |
    // | /  |  |
    // v3--v4  | Z
    //         |
    // <-------Y
    //     X
    Vector3f n1 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.ceil(z));
    Vector3f n2 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.ceil(z));
    Vector3f n3 = getMeshNormal((int) FastMath.ceil(x), (int) FastMath.floor(z));
    Vector3f n4 = getMeshNormal((int) FastMath.floor(x), (int) FastMath.floor(z));
    return n1.add(n2).add(n3).add(n4).normalize();
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)19 Triangle (com.jme3.math.Triangle)9 FloatBuffer (java.nio.FloatBuffer)7 TempVars (com.jme3.util.TempVars)6 CollisionResult (com.jme3.collision.CollisionResult)5 Vector2f (com.jme3.math.Vector2f)5 ShortBuffer (java.nio.ShortBuffer)5 VertexBuffer (com.jme3.scene.VertexBuffer)4 Buffer (java.nio.Buffer)4 IntBuffer (java.nio.IntBuffer)4 ArrayList (java.util.ArrayList)4 Geometry (com.jme3.scene.Geometry)3 BoundingBox (com.jme3.bounding.BoundingBox)2 UnsupportedCollisionException (com.jme3.collision.UnsupportedCollisionException)2 Mesh (com.jme3.scene.Mesh)2 Spatial (com.jme3.scene.Spatial)2 Quad (com.jme3.scene.shape.Quad)2 ByteBuffer (java.nio.ByteBuffer)2 List (java.util.List)2 Test (org.junit.Test)2