Java 类com.badlogic.gdx.math.collision.Ray 实例源码

项目:Tower-Defense-Galaxy    文件:PlacementWindow.java   
@Override
public void draw(Batch batch, float parentAlpha) {
    batch.draw(texture, getX(), getY(), getWidth(), getHeight());
    for(int i = 0; i < xCells; i++)
        for(int j = 0; j < yCells; j++)
            if(cells[i][j] != null) {
                batch.draw(cells[i][j].texture, getX() + i * getWidth() / xCells, getY() + j * getHeight() / yCells, getWidth() / xCells, getHeight() / yCells);
                if(cells[i][j].price > money.$)
                    batch.draw(cellX, getX() + i * getWidth() / xCells, getY() + j * getHeight() / yCells, getWidth() / xCells, getHeight() / yCells);
            }
    if (paused)
        return;
    if(Gdx.input.isTouched() && lastCell != null) {
        Ray ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY());
        Vector3 pos = Tools.closestRayTest(btcollisionWorld, new ClosestRayResultCallback(ray.origin, new Vector3(ray.direction).setLength(9999).add(ray.origin)));
        if(pos != null && Tools.closestRayTestObject(btcollisionWorld, new ClosestRayResultCallback(ray.origin, new Vector3(ray.direction).setLength(9999).add(ray.origin))).getUserValue() == 0) {
            Vector3 vector = world.getVector(pos);
            if(vector != null && ghost != null) {
                ghost.transform.setToTranslation(pos);
                ghost.transform.rotate(vector, 30);
            }
            if(ghost != null)
                modelBatch.render(ghost, environment);
        }
    }
}
项目:enklave    文件:Enklave3D.java   
public boolean touchEnklave(PerspectiveCamera camera,int screenX,int screenY){
        coordonate = null;
        instanceModel.calculateBoundingBox(box).mul(instanceModel.transform);
        box.getCenter(position);
        box.getDimensions(dimensions);
        Ray ray = camera.getPickRay(screenX,screenY);
//        instanceModel.transform.getTranslation(position);
//        position.add(box.getCenter(new Vector3()));
//        Gdx.app.log("res"+ray.toString(),"position"+position);
        if(Intersector.intersectRayBoundsFast(ray,box)){ // position, box.getDimensions(new Vector3()).len(), null)) {
            coordonate = new SpaceCoordonate();
            coordonate.x = Math.abs(Math.abs(position.x) - Math.abs(camera.position.x)) / (Gdx.graphics.getHeight() * 0.026f);
            coordonate.y = Math.abs(Math.abs(position.y) - Math.abs(camera.position.y)) / (Gdx.graphics.getHeight() * 0.026f);
            coordonate.z = -(Math.abs((Gdx.graphics.getHeight() * 0.033f) - Math.abs(camera.position.z)) / (Gdx.graphics.getHeight() * 0.026f));
            if (box.getCenterX() < camera.position.x) {
                coordonate.x = -coordonate.x;
            }
            if (box.getCenterY() < camera.position.y) {
                coordonate.y = -coordonate.y;
            }
            return true;
        }
        return false;
    }
项目:propan-jogl-examples    文件:StampApplication.java   
private void drawRay(GL2 gl, Ray ray) {

        float axisSize = 50;

        Vector3 v = new Vector3(ray.direction);
        v.scl(axisSize);

        //Draw Camera Axis
        if (colide >= 0) {
            gl.glColor3d(1.0, 0.0, 0.0);
        } else {
            gl.glColor3d(0.0, 0.0, 1.0);
        }

        gl.glBegin(GL.GL_LINES);
        gl.glVertex3d(view.getX(), 1, view.getZ());
        gl.glVertex3d(view.getX() + v.x, view.getY() + v.y, view.getZ() + v.z);
        gl.glEnd();
    }
项目:ZombieInvadersVR    文件:ScreenBase.java   
public GameObject getObject (int screenX, int screenY) {
    Ray ray = camera.getPickRay(screenX, screenY);
    GameObject result = null;
    float distance = -1;
    for (ModelInstance item : instances) {
        if(item instanceof GameObject){
            GameObject gameObject = (GameObject) item;
            if(gameObject.enabled){
        Vector3 position = gameObject.transform.getTranslation(new Vector3());
        gameObject.updateBox();
          position.add(gameObject.center);
          float dist2 = ray.origin.dst2(position);
          if (distance >= 0f && dist2 > distance) continue;
          if (Intersector.intersectRayBoundsFast(ray, gameObject.bounds)) {
           result = gameObject;
              distance = dist2;
          }
            }
        }
    }
    return result;
}
项目:origin    文件:MousePicker.java   
private Vector3 binarySearch(int count, float start, float finish, Ray ray)
{
    float half = start + ((finish - start) * 0.5f);
    if (count >= RECURSION_COUNT)
    {
        return getPointOnRay(ray, half);
    }
    if (intersectionInRange(start, half, ray))
    {
        return binarySearch(count + 1, start, half, ray);
    }
    else
    {
        return binarySearch(count + 1, half, finish, ray);
    }
}
项目:eamaster    文件:RayCastTest.java   
@Override
public boolean tap (float x, float y, int count, int button) {
    Ray ray = camera.getPickRay(x, y);
    rayFrom.set(ray.origin);
    rayTo.set(ray.direction).scl(50f).add(rayFrom); // 50 meters max from the origin

    // Because we reuse the ClosestRayResultCallback, we need reset it's values
    rayTestCB.setCollisionObject(null);
    rayTestCB.setClosestHitFraction(1f);
    rayTestCB.setRayFromWorld(rayFrom);
    rayTestCB.setRayToWorld(rayTo);

    world.collisionWorld.rayTest(rayFrom, rayTo, rayTestCB);

    if (rayTestCB.hasHit()) {
        final btCollisionObject obj = rayTestCB.getCollisionObject();
        if (!obj.isStaticOrKinematicObject()) {
            final btRigidBody body = (btRigidBody)(obj);
            body.activate();
            body.applyCentralImpulse(tmpV2.set(ray.direction).scl(20f));
        }
    }
    return true;
}
项目:Mundus    文件:Terrain.java   
public Vector3 getRayIntersection(Vector3 out, Ray ray) {
    // TODO improve performance. use binary search
    float curDistance = 2;
    int rounds = 0;

    ray.getEndPoint(out, curDistance);
    boolean isUnder = isUnderTerrain(out);

    while (true) {
        rounds++;
        ray.getEndPoint(out, curDistance);

        boolean u = isUnderTerrain(out);
        if (u != isUnder || rounds == 10000) {
            return out;
        }
        curDistance += u ? -0.1f : 0.1f;
    }

}
项目:Mundus    文件:ModelPlacementTool.java   
@Override
public boolean mouseMoved(int screenX, int screenY) {
    if (this.model == null || modelInstance == null) return false;

    final ProjectContext context = getProjectManager().current();

    final Ray ray = getProjectManager().current().currScene.viewport.getPickRay(screenX, screenY);
    if (context.currScene.terrains.size > 0 && modelInstance != null) {
        MeshPartBuilder.VertexInfo vi = TerrainUtils.getRayIntersectionAndUp(context.currScene.terrains, ray);
        if (vi != null) {
            if (shouldRespectTerrainSlope) {
                modelInstance.transform.setToLookAt(DEFAULT_ORIENTATION, vi.normal);
            }
            modelInstance.transform.setTranslation(vi.position);
        }
    } else {
        tempV3.set(getProjectManager().current().currScene.cam.position);
        tempV3.add(ray.direction.nor().scl(200));
        modelInstance.transform.setTranslation(tempV3);
    }

    return false;
}
项目:GdxDemo3D    文件:GameEngine.java   
public Entity rayTest(Ray ray, Vector3 hitPointWorld, short belongsToFlag, short collidesWithFlag,
                      float rayDistance, Bits layers) {
    rayFrom.set(ray.origin);
    rayTo.set(ray.direction).scl(rayDistance).add(rayFrom);
    callback.setCollisionObject(null);
    callback.setClosestHitFraction(1f);
    callback.setRay(ray, rayDistance);
    callback.setLayers(layers);

    callback.setCollisionFilterMask(belongsToFlag);
    callback.setCollisionFilterGroup(collidesWithFlag);

    dynamicsWorld.rayTest(rayFrom, rayTo, callback);

    if (callback.hasHit()) {
        if (hitPointWorld != null) {
            callback.getHitPointWorld(hitPointWorld);
        }
        long entityId = callback.getCollisionObject().getUserPointer();
        return getEntity(entityId);
    }
    return null;
}
项目:GdxDemo3D    文件:NavMesh.java   
/**
 * Get the triangle which this ray intersects. Returns null if no triangle is intersected.
 *
 * @param ray
 * @param distance
 * @param allowedMeshParts
 * @return
 */
public Triangle rayTest(Ray ray, float distance, Bits allowedMeshParts) {
    Triangle hitTriangle = null;

    tmpRayTestRayFrom.set(ray.origin);
    tmpRayTestRayTo.set(ray.direction).scl(distance).add(tmpRayTestRayFrom);
    raycastCallback.setHitFraction(1);
    raycastCallback.clearReport();
    raycastCallback.setFrom(tmpRayTestRayFrom);
    raycastCallback.setTo(tmpRayTestRayTo);
    raycastCallback.setAllowedMeshPartIndices(allowedMeshParts);
    collisionShape.performRaycast(raycastCallback, tmpRayTestRayFrom, tmpRayTestRayTo);

    if (raycastCallback.triangleIndex != -1) {
        hitTriangle = graph.getTriangleFromMeshPart(raycastCallback.partId, raycastCallback.triangleIndex);
    }
    return hitTriangle;
}
项目:GdxDemo3D    文件:CameraController.java   
public void processDragPan(Ray dragCurrentRay, Ray lastDragProcessedRay) {
    followTarget = null;
    // TODO:
    // Can probably be optimized, but simply storing worldDragLast.set(worldDragCurrent)
    // caused jitter for some reason.
    Intersector.intersectRayPlane(dragCurrentRay, worldGroundPlane, worldDragCurrent);
    Intersector.intersectRayPlane(lastDragProcessedRay, worldGroundPlane, worldDragLast);
    tmp1.set(worldDragLast).sub(worldDragCurrent);
    tmp1.y = 0;

    ray.origin.set(camera.targetPosition).add(tmp1);
    ray.direction.set(camera.targetDirection);
    if (Intersector.intersectRayBoundsFast(ray, worldBoundingBox)) {
        camera.targetPosition.add(tmp1);
        worldGroundTarget.add(tmp1);
    }
}
项目:Alien-Ark    文件:ControllerPhysic.java   
public Vector3 calculateCameraPickIntersection(Camera camera, int screenX, int screenY, Vector3 out) {
    Ray pickRay = camera.getPickRay(screenX, screenY);
    rayFrom.set(pickRay.origin);
    tmpVector2.set(pickRay.direction).nor().scl(1000);
    tmpVector.set(pickRay.origin).add(tmpVector2);
    rayTo.set(tmpVector);
    callback.setCollisionObject(null);
    callback.setClosestHitFraction(1f);
    callback.setRayFromWorld(rayFrom);
    callback.setRayToWorld(rayTo);
    callback.setCollisionFilterMask((short) -1);
    callback.setCollisionFilterGroup((short) -1);
    dynamicsWorld.rayTest(rayFrom, rayTo, callback);
    if (callback.hasHit()) {
        callback.getHitPointWorld(out);
        return out;
    }
    return null;
}
项目:vrmleditor    文件:Shape.java   
/**
 * Intersects the shape with a Ray
 *
 * @see Ray
 * @param ray the Ray that will be casted over the shape
 * @param intersectionVector a Vector3 for the intersection point between the shape and the ray
 * @return true if the Ray intersect this shape
 */
public boolean intersect(Ray ray, Vector3 intersectionVector) {
    if (verticesDirty) {
        verticesDirty = false;
        tempVertices = new float[vertices.length];
        System.arraycopy(vertices, 0, tempVertices, 0, vertices.length);

        for (int i = 0; i < vertices.length;) {
            tempVector.x = tempVertices[i];
            tempVector.y = tempVertices[i + 1];
            tempVector.z = tempVertices[i + 2];
            tempVector.mul(transformation);
            tempVertices[i++] = tempVector.x;
            tempVertices[i++] = tempVector.y;
            tempVertices[i++] = tempVector.z;
        }
    }
    return Intersector.intersectRayTriangles(ray, tempVertices, indices, mesh.getVertexSize() / (Float.SIZE / 8), intersectionVector);
}
项目:libgdxcn    文件:RayCastTest.java   
@Override
public boolean tap (float x, float y, int count, int button) {
    Ray ray = camera.getPickRay(x, y);
    rayFrom.set(ray.origin);
    rayTo.set(ray.direction).scl(50f).add(rayFrom); // 50 meters max from the origin

    // Because we reuse the ClosestRayResultCallback, we need reset it's values
    rayTestCB.setCollisionObject(null);
    rayTestCB.setClosestHitFraction(1f);
    rayTestCB.setRayFromWorld(rayFrom);
    rayTestCB.setRayToWorld(rayTo);

    world.collisionWorld.rayTest(rayFrom, rayTo, rayTestCB);

    if (rayTestCB.hasHit()) {
        final btCollisionObject obj = rayTestCB.getCollisionObject();
        if (!obj.isStaticOrKinematicObject()) {
            final btRigidBody body = (btRigidBody)(obj);
            body.activate();
            body.applyCentralImpulse(tmpV2.set(ray.direction).scl(20f));
        }
    }
    return true;
}
项目:Vloxlands    文件:Game.java   
public Chunk pickVoxelRay(Island island, Vector3 selVoxel, boolean lmb, int x, int y) {
    Chunk selectedChunk = null;
    Ray ray = camera.getPickRay(x, y);

    float distance = 0;

    for (Chunk c : island.getChunks()) {
        if (c == null) continue;
        if (c.inFrustum && !c.isEmpty()) {
            tmp1.set(island.pos.x + c.pos.x, island.pos.y + c.pos.y, island.pos.z + c.pos.z);
            tmp2.set(tmp1.cpy().add(Chunk.SIZE, Chunk.SIZE, Chunk.SIZE));

            bb.set(tmp1, tmp2);
            if (Intersector.intersectRayBounds(ray, bb, null) && c.pickVoxel(ray, tmp5, tmp6)) {
                float dst = ray.origin.dst(tmp5);
                if ((distance == 0 || dst < distance) && dst <= pickRayMaxDistance) {
                    distance = dst;
                    selVoxel.set(tmp6).add(c.pos);
                    selectedChunk = c;
                }
            }
        }
    }

    return selectedChunk;
}
项目:gdx-ai    文件:BulletTargetInputProcessor.java   
private btCollisionObject rayTest (Collision<Vector3> output, Ray ray) {
    rayFrom.set(ray.origin);
    // 500 meters max from the origin
    rayTo.set(ray.direction).scl(500f).add(rayFrom);

    // we reuse the ClosestRayResultCallback, thus we need to reset its
    // values
    callback.setCollisionObject(null);
    callback.setClosestHitFraction(1f);
    callback.setRayFromWorld(rayFrom);
    callback.setRayToWorld(rayTo);

    world.rayTest(rayFrom, rayTo, callback);

    if (callback.hasHit()) {
        callback.getHitPointWorld(output.point);
        callback.getHitNormalWorld(output.normal);
        return callback.getCollisionObject();
    }

    return null;
}
项目:Hakd    文件:GameInput.java   
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
    Ray ray = cam.getPickRay(Gdx.input.getX(), Gdx.input.getY());

    HakdSprite sprite = null;
    for (Room.DeviceTile tile : screen.getRoom().getDeviceTileMap().values()) {
        if (tile.getTile().getBoundingRectangle().contains(ray.origin.x, ray.origin.y)) {
            sprite = tile.getTile();
            break;
        }
    }

    if (sprite != null && sprite.getObject() != null) {
        screen.setDeviceScene(((Device) sprite.getObject()).getDeviceScene());
        screen.getDeviceScene().open();
    }
    return true;
}
项目:gdx-tilemap3d    文件:TileContainer.java   
public boolean checkForCollision(Ray ray, TileCoord collisionCoords, TileMeshCollection tileMeshes, Vector3 tileMeshCollisionPoint) {
    // if the ray doesn't collide with any solid tiles in the first place, then
    // we can skip this more expensive triangle collision check...
    tmpCoords.set(Vector3.Zero);
    if (!checkForCollision(ray, tmpCoords))
        return false;

    if (collisionCoords != null)
        collisionCoords.set(tmpCoords);

    // now perform the per-triangle collision check against the tile position
    // where the ray ended up at the end of the above checkForCollision() call
    return checkForCollisionWithTileMesh(
            ray,
            tmpCoords.x, tmpCoords.y, tmpCoords.z,
            tileMeshes,
            tileMeshCollisionPoint
    );
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Ray ray, Sphere sphere, Vector3 outFirstIntersection) {
    tmp1.set(ray.origin).sub(sphere.center);

    float b = tmp1.dot(ray.direction);
    float c = tmp1.dot(tmp1) - (sphere.radius * sphere.radius);

    if (c > 0.0f && b > 0.0f)
        return false;

    float discriminant = b * b - c;
    if (discriminant < 0.0f)
        return false;

    float t = -b - (float)Math.sqrt(discriminant);
    if (t < 0.0f)
        t = 0.0f;

    if (outFirstIntersection != null)
        ray.getEndPoint(outFirstIntersection, t);

    return true;
}
项目:ingress-indonesia-dev    文件:q.java   
public final ak a(Ray paramRay)
{
  int i = this.a.size;
  Object localObject1 = null;
  if (i == 0)
    return localObject1;
  this.e.set(paramRay).mul(this.c);
  Iterator localIterator = this.a.iterator();
  label41: Object localObject2;
  if (localIterator.hasNext())
  {
    o localo = (o)localIterator.next();
    if (!(localo instanceof o))
      break label115;
    localObject2 = ((o)localo).a(this.e);
    if ((localObject2 == null) || ((localObject1 != null) && (((ak)localObject2).b >= ((ak)localObject1).b)))
      break label115;
  }
  while (true)
  {
    localObject1 = localObject2;
    break label41;
    break;
    label115: localObject2 = localObject1;
  }
}
项目:ingress-indonesia-dev    文件:k.java   
public final ej a(float paramFloat1, float paramFloat2, Vector2 paramVector2)
{
  Ray localRay = b(paramFloat1, paramFloat2, paramVector2);
  ej localej;
  if (localRay != null)
  {
    localej = this.l.a(localRay);
    if (localej == null);
  }
  do
  {
    return localej;
    float f1 = paramFloat1 / this.v;
    float f2 = 1.0F - paramFloat2 / this.w;
    localej = this.l.a(this.B, new Vector2(f1, f2));
  }
  while (localej != null);
  return null;
}
项目:ingress-indonesia-dev    文件:ft.java   
public final ej a(Ray paramRay)
{
  l locall = this.h.b().a();
  Object localObject1 = null;
  Object localObject2;
  if (locall.hasNext())
  {
    ep localep = (ep)locall.next();
    if (localep.b != this.v)
      break label97;
    localObject2 = localep.a(paramRay);
    if ((localObject2 == null) || ((localObject1 != null) && (((ak)localObject2).b >= localObject1.b)))
      break label97;
  }
  while (true)
  {
    localObject1 = localObject2;
    break;
    if (localObject1 == null)
      return null;
    return (ej)localObject1.a;
    label97: localObject2 = localObject1;
  }
}
项目:gdx-cclibs    文件:RaySerializer.java   
@Override
public void write(Kryo kryo, Output output, Ray ray) {
    Vector3 origin = ray.origin;
    output.writeFloat(origin.x);
    output.writeFloat(origin.y);
    output.writeFloat(origin.z);
    Vector3 direction = ray.direction;
    output.writeFloat(direction.x);
    output.writeFloat(direction.y);
    output.writeFloat(direction.z);
}
项目:gdx-cclibs    文件:RaySerializer.java   
@Override
public Ray read(Kryo kryo, Input input, Class<Ray> type) {
    Ray ray = new Ray();
    Vector3 origin = ray.origin;
    origin.x = input.readFloat();
    origin.y = input.readFloat();
    origin.z = input.readFloat();
    Vector3 direction = ray.direction;
    direction.x = input.readFloat();
    direction.y = input.readFloat();
    direction.z = input.readFloat();
    return ray;
}
项目:gdx-cclibs    文件:MathTest.java   
public void testCollisionClasses (){
    Object[] objects = new Object[4];

    objects[0] = new BoundingBox(new Vector3(randFloat(), randFloat(), randFloat()), new Vector3(randFloat(), randFloat(), randFloat()));
    objects[1] = new Ray(new Vector3(randFloat(), randFloat(), randFloat()), new Vector3(randFloat(), randFloat(), randFloat()).nor());
    objects[2] = new Segment(randFloat(), randFloat(), randFloat(), randFloat(), randFloat(), randFloat());
    objects[3] = new Sphere(new Vector3(randFloat(), randFloat(), randFloat()), randFloat());

    simpleRoundTrip(objects);
}
项目:arcadelegends-gg    文件:LevelScreen.java   
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    lastMousePos.set(screenX, screenY);
    Ray ray = camera.getPickRay(screenX, screenY);
    Vector3 worldcoor = new Vector3();
    Intersector.intersectRayPlane(ray, arcadeWorld.getMapHitbox(), worldcoor);
    log.debug("Clicked: " + worldcoor.toString());
    Vector2 mapCoord = new Vector2(Math.round(worldcoor.x), Math.round(worldcoor.y));
    switch (button) {
        case Input.Buttons.LEFT:
            CharacterComponent input = arcadeWorld.getEntityWorld().getComponentOf(playerEnt, CharacterComponent.class);
            input.move.set((int) mapCoord.x, (int) mapCoord.y);
            break;
        case Input.Buttons.RIGHT:
            Tile t = arcadeWorld.getTile(mapCoord);
            try {
                int id = t.getEntities().first();
                input = arcadeWorld.getEntityWorld().getMapper(CharacterComponent.class).get(playerEnt);
                input.targetId = id;
                log.debug("{}", id);
            } catch (IllegalStateException ex) {

            }
            break;
    }

    return false;
}
项目:arcadelegends-gg    文件:Character.java   
/**
 * Sandbox method for getting the mouse-position.
 *
 * @return the mouse-position
 */
public Vector2 getMousePos() {
    Ray ray = arcadeWorld.getCam().getPickRay(AL.input.getX(), AL.input.getY());
    Vector3 vec = new Vector3();
    Intersector.intersectRayPlane(ray, arcadeWorld.getMapHitbox(), vec);
    return new Vector2(vec.x, vec.y);
}
项目:arcadelegends-gg    文件:Character.java   
/**
 * Same as {@link Character#getMousePos()}, only returning rounded coordinates.
 *
 * @return the rounded mouse-position
 */
public Vector2 getRoundMousePos() {
    Ray ray = arcadeWorld.getCam().getPickRay(AL.input.getX(), AL.input.getY());
    Vector3 vec = new Vector3();
    Intersector.intersectRayPlane(ray, arcadeWorld.getMapHitbox(), vec);
    return new Vector2(Math.round(vec.x), Math.round(vec.y));
}
项目:propan-jogl-examples    文件:StandardExample.java   
public static void drawRay(GL2 gl, Ray ray, FlyView view, float size) {
    Vector3 v = new Vector3(ray.direction);
    v.scl(size);

    gl.glBegin(GL.GL_LINES);
    gl.glVertex3d(view.getX(), view.getY()-0.1, view.getZ());
    gl.glVertex3d(view.getX()+v.x, view.getY()+v.y, view.getZ()+v.z);
    gl.glEnd();
}
项目:propan-jogl-examples    文件:PositionAxis.java   
private void drawRay(GL2 gl, Ray ray) {

        float axisSize = 50;

        Vector3 v = new Vector3(ray.direction);
        v.scl(axisSize);

        //Draw Camera Axis
        gl.glColor3d(0.0, 0.0, 1.0);

        gl.glBegin(GL.GL_LINES);
        gl.glVertex3d(view.getX(), 1, view.getZ());
        gl.glVertex3d(view.getX()+v.x, view.getY()+v.y, view.getZ()+v.z);
        gl.glEnd();
    }
项目:propan-jogl-examples    文件:RotationAxis.java   
private void drawRay(GL2 gl, Ray ray) {

        float axisSize = 50;

        Vector3 v = new Vector3(ray.direction);
        v.scl(axisSize);

        //Draw Camera Axis
        gl.glColor3d(0.0, 0.0, 1.0);

        gl.glBegin(GL.GL_LINES);
        gl.glVertex3d(view.getX(), 1, view.getZ());
        gl.glVertex3d(view.getX()+v.x, view.getY()+v.y, view.getZ()+v.z);
        gl.glEnd();
    }
项目:Argent    文件:Terrain.java   
public Vector3 getRayIntersection(Vector3 out, Ray ray) {
    float curDistance = 0;
    int rounds = 0;
    ray.getEndPoint(out, curDistance);
    boolean isUnder = isUnderTerrain(out);
    while(true) {
        rounds++;
        ray.getEndPoint(out, curDistance);
        boolean u = isUnderTerrain(out);
        if(u != isUnder || rounds >= 10000)
            return out;
        curDistance += u ? -.1f : .1f;
    }
}
项目:Argent    文件:LandscapeWorldActor.java   
public LandscapeCell rayIntersects() {
    if(true) return null;
    Ray ray = new Ray();
    Camera cam = world.renderer().camera();
    ray.origin.set(cam.position);
    ray.direction.set(cam.direction);
    return rayIntesects(ray, null);
}
项目:Argent    文件:LandscapeWorldActor.java   
public LandscapeCell rayIntesects(Ray ray, Vector3 intersection) {
    List<Vector3> triangleList = new ArrayList<>();
    packedCells().forEach(c -> triangleList.addAll(c.trianglePoints()));
    if(Intersector.intersectRayTriangles(ray, triangleList, intersection)) {
        for (LandscapeCell cell : packedCells) {
            if(cell.rayIntersects(ray)) return cell;
        }
    }
    return null;
}
项目:Argent    文件:PointLight.java   
public void testHit(Mesh mesh, Ray ray) {
    int numVertices = mesh.getNumVertices();
    float[] vertices = new float[numVertices];
    mesh.getVertices(vertices);

    int numIndices = mesh.getNumIndices();
    short[] indices = new short[numIndices];
    mesh.getIndices(indices);

    Vector3 intersection = new Vector3();
    if (Intersector.intersectRayTriangles(ray, vertices, indices, mesh.getVertexSize(), intersection))
        hit(ray, intersection);
}
项目:origin    文件:MousePicker.java   
public void update(Ray ray)
{
    float len = 0;

    _currentTerrainPoint = null;
    while (len < RAY_RANGE)
    {
        if (intersectionInRange(len, len + STEP_LEN, ray))
        {
            _currentTerrainPoint = binarySearch(0, len, len + STEP_LEN, ray);
            break;
        }
        len += STEP_LEN;
    }
}
项目:origin    文件:MousePicker.java   
private Vector3 getPointOnRay(Ray ray, float distance)
{
    Vector3 start = ray.origin.cpy();
    Vector3 dir = ray.direction.cpy();
    dir.nor();
    return start.add(dir.x * distance, dir.y * distance, dir.z * distance);
}
项目:eamaster    文件:WheelRenderer.java   
private void hover(Ray ray) {
    from.set(ray.origin);
    to.set(ray.direction).scl(500f).add(from);

    rayResultCallback.setCollisionObject(null);

    rayResultCallback.setClosestHitFraction(1f);
    rayResultCallback.setRayFromWorld(from);
    rayResultCallback.setRayToWorld(to);

    simulation.wheelWorld.bulletWorld.rayTest(from, to, rayResultCallback);


    if (rayResultCallback.hasHit()) {
        btCollisionObject hitObj = rayResultCallback.getCollisionObject();

        Entity hitEnt = (Entity) hitObj.userData;

        if (hitEnt != lastHovered && (selected == null || hitEnt != selected)) {
            if (lastHovered != null) {
                lastHovered.restoreColors();
            }
            lastHovered = hitEnt;
            hitEnt.applyColorFunc(c -> c.add(0.2f, 0.2f, 0.2f, 0f));
        }
    } else {
        if (lastHovered != null) {
            lastHovered.restoreColors();
            lastHovered = null;
        }
    }

}
项目:eamaster    文件:World.java   
public void hover(Ray ray) {
        Vector3 from = new Vector3(ray.origin);
        Vector3 to = new Vector3(ray.direction).scl(100f).add(from);

        rayCallback.setCollisionObject(null);

        rayCallback.setClosestHitFraction(1f);
        rayCallback.setRayFromWorld(from);
        rayCallback.setRayToWorld(to);

//        rayCallback.setCollisionFilterMask((short) -1);
        rayCallback.setCollisionFilterGroup((short) 64);

        bulletWorld.rayTest(from, to, rayCallback);


        if (rayCallback.hasHit()) {
            btCollisionObject hitObj = rayCallback.getCollisionObject();

            WorldEntity hitEnt = (WorldEntity) hitObj.userData;

            if (hitEnt != lastHovered) {
                if (lastHovered != null) {
                    lastHovered.restoreColors();
                }

                lastHovered = hitEnt;
                hitEnt.applyColorFunc(c -> c.add(0.2f, 0.2f, 0.2f, 0f));
            }
        } else {
            if (lastHovered != null) {
                lastHovered.restoreColors();
                lastHovered = null;
            }
        }
    }
项目:eamaster    文件:BaseBulletTest.java   
public BulletEntity shoot (final String what, final float x, final float y, final float impulse) {
    // Shoot a box
    Ray ray = camera.getPickRay(x, y);
    BulletEntity entity = world.add(what, ray.origin.x, ray.origin.y, ray.origin.z);
    entity.setColor(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(),
        1f);
    ((btRigidBody)entity.body).applyCentralImpulse(ray.direction.scl(impulse));
    return entity;
}