Package com.jme3.collision

Examples of com.jme3.collision.CollisionResults


        Geometry g = new Geometry(null, li);
      g.setMaterial(matWireframe);
      bboxes.attachChild(g);

        Ray ray = new Ray(origin, direction);
        CollisionResults results = new CollisionResults();

        rootNode.collideWith(ray, results);

        if (results.size() > 0) {
          for (CollisionResult res : results) {
            System.out.println("Picking: "+res.getGeometry());
          }
        } else
          System.out.println("Picking: no results");
View Full Code Here


      Vector3f direction = camera.getWorldCoordinates(
          inputManager.getCursorPosition(), 0.3f);
      direction.subtractLocal(origin).normalizeLocal();

      Ray ray = new Ray(origin, direction);
      CollisionResults results = new CollisionResults();

      sin.getSceneManager().getRoot().collideWith(ray, results);

      if (results.size() > 0) {
        Geometry geom = null;
        for (CollisionResult res : results) {
          geom = res.getGeometry();
          if (geom != null) {
            log.fine("picked " + geom.getName());
            Integer id = geom.getUserData(Entity.ENTITY_ID);
            if (id != null) {
              //Just create a target component rest is done in the jmeupdatesystem
              Node n = res.getGeometry().getParent();
              String na = n.getName();
              log.fine("picked " + na + " id:"+ id);
              Vector3f loc = n.getLocalTranslation();
              sin.getClientFacade().sendAction(id, loc.x, loc.y, loc.z, false, true);
              results.clear();
              return;
            } else {//FIXME click on anything, check nav, then send request
              // this is the one
              Vector3f location = res.getContactPoint();
              if(location != null){
                Path p = new Path();
                PositioningComponent pos = (PositioningComponent) sin.getEntityManager().getComponent(handler.getSelectedObjectId(), PositioningComponent.class);
                if(pos != null){
                  if(sin.getNavManager().buildNavigationPath(p, pos.position, location.clone())) {
                    log.fine("new loc:" + location
                        + " sent:"+ ServerValues.getServerCoordX(location.x)
                        + ","+ ServerValues.getServerCoordY(location.z)
                        + ","+ ServerValues.getServerCoordZ(location.y));
                    sin.getClientFacade().sendMoveToAction(handler.getSelectedObjectId(), pos.position.x, pos.position.y, pos.position.z, location.x, location.y,
                        location.z);
                    results.clear();
                    return;
                  } else {
                    log.fine("Unable to build path from "+pos.position+" to "+location);
                  }
                }
              }
             
              log.warning("invalid loc on click:" + location);
              return;
            }
          }

        }
        results.clear();
      } else
        log.info("picked nothing");
    }
  }
View Full Code Here

    Vector2f grassPatchRandomOffset = new Vector2f().zero();
    Vector3f candidateGrassPatchLocation = new Vector3f();

    Random rand = new Random();
    Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Y.mult(-1f));
    CollisionResults results = new CollisionResults();
    float ax, az;
    for (float x = centre.x - terrainWidth / 2 + inc; x < centre.x
        + terrainWidth / 2 - inc; x += inc) {
      for (float z = centre.z - terrainWidth / 2 + inc; z < centre.z
          + terrainWidth / 2 - inc; z += inc) {
        grassPatchRandomOffset.set(inc, inc);
        grassPatchRandomOffset.multLocal(rand.nextFloat()); // make the
                                  // off set
                                  // length a
                                  // random
                                  // distance
                                  // smaller
                                  // than the
                                  // increment
                                  // size
        grassPatchRandomOffset
            .rotateAroundOrigin(
                (float) (((int) (rand.nextFloat() * 359)) * (Math.PI / 180)),
                true); // rotate the offset by a random angle

        ax = x + grassPatchRandomOffset.x;
        az = z + grassPatchRandomOffset.y;
        ray.setOrigin(new Vector3f(ax, centre.y + terrainWidth, az));
        terrain.collideWith(ray, results);

        if (results.size() <= 0)
          continue;

        try {
          if (results.size() > 0) {

            candidateGrassPatchLocation.set(ax, results
                .getCollision(0).getContactPoint().y, az);
            results.clear();

            if (isGrassLayer(candidateGrassPatchLocation, terrain,
                minIntensity, terrainWidth, channelId)) {
              // this will be in world coords, but we want it to
              // be in local
View Full Code Here

                for (int i = 0; i < getQuantity(); i++) {
                    if (children.get(i) instanceof TerrainPatch) {
                        TerrainPatch tp = (TerrainPatch) children.get(i);
                        tp.ensurePositiveVolumeBBox();
                        if (tp.getWorldBound().intersects(toTest)) {
                            CollisionResults cr = new CollisionResults();
                            toTest.collideWith(tp.getWorldBound(), cr);
                            if (cr != null && cr.getClosestCollision() != null) {
                                cr.getClosestCollision().getDistance();
                                results.add(new TerrainPickData(tp, cr.getClosestCollision()));
                            }
                        }
                    }
                    else if (children.get(i) instanceof TerrainQuad) {
                        ((TerrainQuad) children.get(i)).findPick(toTest, results);
View Full Code Here

        Vector3f pos = new Vector3f();
        Vector3f dir = new Vector3f(0, -1, 0);
        Ray ray = new Ray(pos, dir);

        // Prepare collision results
        CollisionResults results = new CollisionResults();

        // Set the LOD indices on the block
        VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

        terrainBlock.clearBuffer(Type.Index);
        if (lodIndices instanceof IntBuffer)
            terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices);
        else if (lodIndices instanceof ShortBuffer) {
            terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
        }

        // Recalculate collision mesh
        terrainBlock.createCollisionData();

        float entropy = 0;
        for (int i = 0; i < positions.limit() / 3; i++){
            BufferUtils.populateFromBuffer(pos, positions, i);

            float realHeight = pos.y;

            pos.addLocal(0, bbox.getYExtent(), 0);
            ray.setOrigin(pos);

            results.clear();
            terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

            if (results.size() > 0){
                Vector3f contactPoint = results.getClosestCollision().getContactPoint();
                float delta = Math.abs(realHeight - contactPoint.y);
                entropy = Math.max(delta, entropy);
            }
        }
View Full Code Here

            initFlash();
            i.shoot=false;
           
            int power=100;
            // 1. Reset results list.
            CollisionResults results = new CollisionResults();
            Ray ray = new Ray(cam.getLocation(), cam.getDirection());
            rootNode.collideWith(ray, results);
            for (int j = 0; j < results.size(); j++) {
               
              float dist = results.getCollision(j).getDistance();
              String hit = results.getCollision(j).getGeometry().getName();
              power-=dist;
              if(opponent.player.hasChild(results.getCollision(j).getGeometry())){
                  hitmarker = true;
                  if(power>=0) {
                      opponent.life -= power;
                  }
                  if(opponent.life < 0)
                      opponent.player.getChild(hit).removeFromParent();
                  power -= 30;
              }
              if(scene.hasChild(results.getCollision(j).getGeometry())) //don't kill scene
                power -= 80;

            }
        }
    }
View Full Code Here

    private Geometry cursor3D;

    private boolean show3DCursor = true;

    public DebugMouse() {
        results = new CollisionResults();
        cursor3D = Util.createPoint(0, 0, 0, .05f);
        cursor3D.setName("3D mouse cursor");

        mouse3DNode = new Node("3D mouse");
View Full Code Here

    // }

    public float extractVoxelData2(Geometry refGeom, Vector3f voxelPos) {
        // float density = -1, angle;
        float[] densities0, densities1;
        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);
View Full Code Here

        flame.setSelectRandomImage(true);
        flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, 1f));
        flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
        flame.setStartSize(1.3f);
        flame.setEndSize(2f);
        flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        flame.setParticlesPerSec(0);
        flame.setGravity(-5f);
        flame.setLowLife(1f);
        flame.setHighLife(1f);
        flame.setInitialVelocity(new Vector3f(0, 7, 0));
View Full Code Here

  public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    tuioInput = TuioInput.get();
    tuioInput.addListener(this);
    BitmapFont guiFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
   
    BitmapText tuioStatsLabel = new BitmapText(guiFont, false);
        tuioStatsLabel.setLocalTranslation(0, tuioStatsLabel.getLineHeight()*3, 0);
        tuioStatsLabel.setText("Tuio Input:");
        tuioStatsNode.attachChild(tuioStatsLabel);
View Full Code Here

TOP

Related Classes of com.jme3.collision.CollisionResults

Copyright © 2018 www.massapicom. 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.