Java Code Examples for com.jme3.collision.CollisionResult#setContactNormal()

The following examples show how to use com.jme3.collision.CollisionResult#setContactNormal() . 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: BresenhamTerrainPicker.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method adds the found Collision to an existing collisionResult.
 * @param results The results to add this collision to
 * @param patch The TerrainPatch which collided
 * @param intersection The actual intersection position
 * @param hit The hit triangle
 * @param distance The distance at which the hit occurred
 * @return Whether the collision was accepted to the list or whether it has been deduplicated
 */
private boolean addCollision(CollisionResults results, TerrainPatch patch, Vector3f intersection, Triangle hit, float distance) {
    CollisionResult cr = new CollisionResult(intersection.clone(), distance);
    cr.setGeometry(patch);
    cr.setContactNormal(hit.getNormal());
    cr.setTriangleIndex(hit.getIndex()); // this will probably always be 0

    for (int i = 0; i < results.size(); i++) {
        CollisionResult compare = results.getCollision(i);
        if (compare.getDistance() == cr.getDistance() && compare.getGeometry() == cr.getGeometry() &&
            compare.getContactPoint().equals(cr.getContactPoint()) &&
            compare.getContactNormal().equals(cr.getContactNormal())) {
                return false; // Collision already available, deduplicate.
        }
    }

    results.addCollision(cr);
    return true;
}