Examples of Ray


Examples of com.jme3.math.Ray

   
  public Ray getClickRay(Vector2f point) {
    Vector3f camLocation = cam.getLocation();
    Vector3f clickPoint = cam.getWorldCoordinates(point, 0.9f);
    Vector3f dir = clickPoint.subtract(camLocation).normalize();
    return new Ray(camLocation, dir);
    //return new Ray(camLocation, cam.getDirection());
  }
View Full Code Here

Examples of com.jme3.math.Ray

    this.cam = cam;
    this.map = map;
  }

  public void click(Vector2f point) {
    Ray clickRay = cam.getClickRay(point);
    CollisionResults results = map.getCollisions(clickRay);
    if (results.size() == 0) {
      if (listener != null) {
        listener.onPolluxEvent(new NothingHitClickEvent(this.getClass().getName()));
      }
View Full Code Here

Examples of com.jme3.math.Ray

//        li.setLineWidth(3f);
        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) {
View Full Code Here

Examples of com.jme3.math.Ray

          inputManager.getCursorPosition(), 0.0f);
      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) {
View Full Code Here

Examples of com.jme3.math.Ray

                        // terrain
    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;

View Full Code Here

Examples of com.jme3.math.Ray

                if (!Float.isInfinite(t)) {
                    if (worldMatrix != null) {
                        worldMatrix.mult(v1, v1);
                        worldMatrix.mult(v2, v2);
                        worldMatrix.mult(v3, v3);
                        float t_world = new Ray(o, d).intersects(v1, v2, v3);
                        t = t_world;
                    }

                    Vector3f contactNormal = Triangle.computeTriangleNormal(v1, v2, v3, null);
                    Vector3f contactPoint = new Vector3f(d).multLocal(t).addLocal(o);
View Full Code Here

Examples of com.jme3.math.Ray

            Matrix4f worldMatrix,
            BoundingVolume worldBound,
            CollisionResults results) {

        if (other instanceof Ray) {
            Ray ray = (Ray) other;
            return collideWithRay(ray, worldMatrix, worldBound, results);
        } else if (other instanceof BoundingVolume) {
            BoundingVolume bv = (BoundingVolume) other;
            return collideWithBoundingVolume(bv, worldMatrix, results);
        } else {
View Full Code Here

Examples of com.jme3.math.Ray

        FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

        // Prepare to cast rays
        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){
View Full Code Here

Examples of com.jme3.math.Ray

            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();
View Full Code Here

Examples of com.jme3.math.Ray

        // 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 {
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.