Examples of CollisionResult


Examples of com.jme3.collision.CollisionResult

            if (tracer.isRayPerpendicularToGrid()) {
                Triangle hit = new Triangle();
                checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit);
                float distance = worldPickRay.origin.distance(intersection);
                CollisionResult cr = new CollisionResult(intersection, distance);
                cr.setGeometry(patch);
                cr.setContactNormal(hit.getNormal());
                results.addCollision(cr);
                return intersection;
            }
           
           

            while (loc.x >= -1 && loc.x <= patch.getSize() &&
                   loc.y >= -1 && loc.y <= patch.getSize()) {

                //System.out.print(loc.x+","+loc.y+" : ");
                // check the triangles of main square for intersection.
                Triangle hit = new Triangle();
                if (checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit)) {
                    // we found an intersection, so return that!
                    float distance = worldPickRay.origin.distance(intersection);
                    CollisionResult cr = new CollisionResult(intersection, distance);
                    cr.setGeometry(patch);
                    results.addCollision(cr);
                    cr.setContactNormal(hit.getNormal());
                    return intersection;
                }

                // because of how we get our height coords, we will
                // sometimes be off by a grid spot, so we check the next
                // grid space up.
                int dx = 0, dz = 0;
                Direction d = tracer.getLastStepDirection();
                switch (d) {
                case PositiveX:
                case NegativeX:
                    dx = 0;
                    dz = 1;
                    break;
                case PositiveZ:
                case NegativeZ:
                    dx = 1;
                    dz = 0;
                    break;
                }

                if (checkTriangles(loc.x + dx, loc.y + dz, workRay, intersection, patch, hit)) {
                    // we found an intersection, so return that!
                    float distance = worldPickRay.origin.distance(intersection);
                    CollisionResult cr = new CollisionResult(intersection, distance);
                    results.addCollision(cr);
                    cr.setGeometry(patch);
                    cr.setContactNormal(hit.getNormal());
                    return intersection;
                }

                tracer.next();
            }
View Full Code Here

Examples of com.jme3.collision.CollisionResult

        return matrix.determinant();
    }

    public static final CollisionResult getClosestMouseHitResult(SimpleApplication app) {
        Camera cam = app.getCamera();
        CollisionResult result;

        ray.setOrigin(cam.getLocation());
        ray.setDirection(get3DMousePosition(app, v3f_0).subtractLocal(cam.getLocation()));

        results.clear();
View Full Code Here

Examples of com.jme3.collision.CollisionResult

        CollisionResults tmpResults = new CollisionResults();
        CollisionResults results = new CollisionResults();
        // float d0, d1;

        // CollisionResult result = null;
        CollisionResult r;
        // boolean dbl = false;
        // float dist = Float.POSITIVE_INFINITY, tmpDist = 0;
        Ray ray = new Ray();
        ray.setLimit(1);
        // int edgeCase = 0;
        // int added = 0;
        // float d0, d1;
        for (Vector3f rDirection : rDirections) {
            tmpResults.clear();

            ray.setOrigin(voxelPos);
            ray.setDirection(rDirection);
            // added = refGeom.collideWith(ray, tmpResults);
            if (refGeom.collideWith(ray, tmpResults) > 0) {
                // d0 = tmpResults.getClosestCollision().getDistance();

                ray.setOrigin(voxelPos.add(rDirection));
                ray.setDirection(rDirection.negate());
                refGeom.collideWith(ray, tmpResults);
                // d1 = tmpResults.getFarthestCollision().getDistance();
                // edgeCase = Math.abs(d0) - Math.abs(d1);
            } else {

            }
            // if (refGeom.collideWith(ray, tmpResults) > 0) {
            // ray.setOrigin(voxelPos.add(rDirection));
            // ray.setDirection(rDirection.negate());
            // refGeom.collideWith(ray, tmpResults);
            // }

            for (int i = 0; i < tmpResults.size(); i++) {
                r = tmpResults.getCollision(i);
                //                dbl = false;
                // if (results.size() > 0)
                // if (r.getContactPoint()
                // .equals(results.getCollision(results.size() - 1).getContactPoint())
                // && r.getDistance() == results.getCollision(results.size() - 1)
                // .getDistance()) {
                // dbl = true;
                // }
                // if (r.getDistance() <= 1 && !dbl) {
                results.addCollision(r);
                // } else {
                // // results.d
                // }
            }

            // if (added > 0) {
            //
            // for (int i = 0; i < results.size(); i++) {
            // tmpResult = results.getCollision(i);
            //
            // tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
            // if (dist > tmpDist) {
            // result = tmpResult;
            // dist = tmpDist;
            // }
            // }
            // }

            // if (added > 0) {
            //
            // for (int i = 0; i < results.size(); i++) {
            // tmpResult = results.getCollision(i);
            //
            // tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
            // if (dist > tmpDist) {
            // result = tmpResult;
            // dist = tmpDist;
            // }
            // }
            // d0 = result.getDistance();
            //
            // angle = (float) Math.toDegrees(result.getTriangle(null)
            // .getNormal()
            // .angleBetween(rDirection));
            //
            // if (angle > 90 && angle < 270) {
            // d0 *= -1;
            // }
            //
            // results.clear();
            // r.setOrigin(voxelPos.add(rDirection));
            // r.setDirection(rDirection.negate());
            // refGeom.collideWith(r, results);
            // for (int i = 0; i < results.size(); i++) {
            // tmpResult = results.getCollision(i);
            // // System.out.println(tmpResult.getDistance());
            //
            // if (Math.abs(tmpResult.getDistance()) <= 1) {
            // tmpDist = tmpResult.getTriangle(null).getCenter()
            // .distance(voxelPos);
            // dist = Float.NEGATIVE_INFINITY;
            // if (dist < tmpDist) {
            // result = tmpResult;
            // dist = tmpDist;
            // }
            // }
            // }
            // d1 = result.getDistance();
            //
            // angle = (float) Math.toDegrees(result.getTriangle(null)
            // .getNormal()
            // .angleBetween(rDirection.negate()));
            //
            // if (angle > 90 && angle < 270) {
            // d1 *= -1;
            // }
            //
            // density = d0 + Math.signum(d0) * ((1 - (d0 + d1)) / 2);
            // System.out.println("density: " + density + ", d0: " + d0 + ", d1: " + d1
            // + ", ");
            // added = -1;
            // }
            // if (added == -1)
            // break;
        }

        if (results.size() > 0) {
            // System.out.println("Results for " + voxelPos);
            densities0 = new float[results.size()];
            densities1 = new float[results.size()];
            for (int i = 0; i < results.size(); i++) {
                r = results.getCollision(i);

                densities0[0] = r.getDistance();
                densities1[0] = r.getDistance();

                // tmpDist = tmpResult.getTriangle(null).getCenter().distance(voxelPos);
                // if (dist > tmpDist) {
                // result = tmpResult;
                // dist = tmpDist;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.