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

项目:propan-jogl-examples    文件:PositionAxis.java   
@Override
public void init(Graphics3D graphics) {
    view = new FlyView(30, 3.6f, 0);
    view.getAim().setAngleY(190);

    AWTGraphics3D g = (AWTGraphics3D) graphics;
    GL2 gl = g.getGL2(); // get the OpenGL graphics context

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f);      // set clear depth value to farthest
    gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL.GL_LEQUAL);  // the type of depth test to do
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // best perspective correction
    gl.glShadeModel(GL2.GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);

    xAxis = new BoundingBox(new Vector3(0, -axisWidth/2, -axisWidth/2), new Vector3(axisSize, axisWidth/2, axisWidth/2));
    yAxis = new BoundingBox(new Vector3(-axisWidth/2, 0, -axisWidth/2), new Vector3(axisWidth/2, axisSize, axisWidth/2));
    zAxis = new BoundingBox(new Vector3(-axisWidth/2, -axisWidth/2, 0), new Vector3(axisWidth/2, axisWidth/2, axisSize));
}
项目:propan-jogl-examples    文件:RotationAxis.java   
@Override
public void init(Graphics3D graphics) {
    view = new FlyView(30, 3.6f, 0);
    view.getAim().setAngleY(190);

    AWTGraphics3D g = (AWTGraphics3D) graphics;
    GL2 gl = g.getGL2(); // get the OpenGL graphics context

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f);      // set clear depth value to farthest
    gl.glEnable(GL.GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL.GL_LEQUAL);  // the type of depth test to do
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // best perspective correction
    gl.glShadeModel(GL2.GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);

    vAxis = new BoundingBox(new Vector3(-axisSize/8, -axisWidth/2, -axisSize/8), new Vector3(axisSize/8, axisWidth/2, axisSize/8));
    hAxis = new BoundingBox(new Vector3(-axisSize/8, -axisSize/8, -axisWidth/2), new Vector3(axisSize/8, axisSize/8, axisWidth/2));

}
项目:ZombieInvadersVR    文件:GameObject.java   
public GameObject(ScreenBase context, Model model, BoundingBox bounds) {
super(model);
this.context = context;
this.customBounds = bounds;

      this.bounds = this.customBounds != null ? this.customBounds : new BoundingBox();
      this.center = new Vector3();
      this.enabled = true;
      updateBox();

      this.animations = new AnimationController(this);
      this.blending = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

      for(Material item : materials){
        item.set(new DepthTestAttribute(GL20.GL_LEQUAL, 0.01f, 25f, true));
    item.set(FloatAttribute.createAlphaTest(0.01f));
        item.set(blending);
      }
  }
项目:GdxDemo3D    文件:CameraController.java   
public void setWorldBoundingBox(BoundingBox worldBoundingBox) {
    this.worldBoundingBox = new BoundingBox(worldBoundingBox);
    Vector3 min = new Vector3();
    Vector3 max = new Vector3();
    // Set height of bounding box to zero (y dimension)
    this.worldBoundingBox.getMax(max).y = 0;
    this.worldBoundingBox.getMin(min).y = 0;
    this.worldBoundingBox.set(min, max);

    ray.set(camera.targetPosition, camera.targetDirection);
    if (!Intersector.intersectRayBounds(ray, this.worldBoundingBox, worldGroundTarget)) {
        // TODO: What happens if the center of camera is not aimed at bounding box?
        // Probably move the camera until it is...
    }

}
项目:libgdxcn    文件:Frustum.java   
/** Returns whether the given {@link BoundingBox} is in the frustum.
 * 
 * @param bounds The bounding box
 * @return Whether the bounding box is in the frustum */
public boolean boundsInFrustum (BoundingBox bounds) {
    Vector3[] corners = bounds.getCorners();
    int len = corners.length;

    for (int i = 0, len2 = planes.length; i < len2; i++) {
        int out = 0;

        for (int j = 0; j < len; j++)
            if (planes[i].testPoint(corners[j]) == PlaneSide.Back) out++;

        if (out == 8) return false;
    }

    return true;
}
项目:libgdxcn    文件:Node.java   
/** Extends the bounding box with the bounds of this Node. This is a potential slow operation, it is advised to cache the
 * result. */
public BoundingBox extendBoundingBox (final BoundingBox out, boolean transform) {
    final int partCount = parts.size;
    for (int i = 0; i < partCount; i++) {
        final NodePart part = parts.get(i);
        if (part.enabled) {
            final MeshPart meshPart = part.meshPart;
            if (transform)
                meshPart.mesh.extendBoundingBox(out, meshPart.indexOffset, meshPart.numVertices, globalTransform);
            else
                meshPart.mesh.extendBoundingBox(out, meshPart.indexOffset, meshPart.numVertices);
        }
    }
    final int childCount = children.size;
    for (int i = 0; i < childCount; i++)
        children.get(i).extendBoundingBox(out);
    return out;
}
项目:NicolasRage    文件:Fireball.java   
@Override
protected void addToWold(World world, float x, float y)
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(x, y);
    body = world.createBody(bodyDef);
    body.setLinearDamping(0);
    bodyDef.angularDamping = 5f;
    body.setFixedRotation(false);
    body.setUserData(this);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;new BoundingBox(new Vector3(this.getX(), this.getY(), 0), new Vector3(this.getX() + this.getWidth(), this.getY() + this.getHeight(), 0));
    fixtureDef.restitution = 1;
    fixtureDef.density = 1;
    Fixture fixture = body.createFixture(fixtureDef);
    shape.dispose();
}
项目:TinyVoxel    文件:ArrayBundle.java   
@Override
public void init(String name, boolean load) {
    visible = true;
    solid = true;

    this.name = name;

    transform.idt();

    terrainMap = new Grid[SIZE][SIZE][SIZE];
    boundingBox = new BoundingBox();
    gridArray = new Array<Grid>(Grid.class);
    gridCount = new WrappedInteger(0);
    isLoading = new WrappedBoolean(false);
    references = new WrappedInteger(1);

    if (load) {
        loadAll();
    }

    updateMatrix();
}
项目:TinyVoxel    文件:TinyGrid.java   
public void copyTo(TinyGrid tiny) {
    tiny.checkBounds = checkBounds;
    tiny.minX = minX;
    tiny.minY = minY;
    tiny.minZ = minZ;
    tiny.maxX = maxX;
    tiny.maxY = maxY;
    tiny.maxZ = maxZ;

    for (int i = 0; i < fullSides.length; i++)
        tiny.fullSides[i] = fullSides[i];

    tiny.boundingBox = new BoundingBox(boundingBox);
    for (int tx = 0; tx < Config.TINY_GRID_SIZE; tx++)
        for (int ty = 0; ty < Config.TINY_GRID_SIZE; ty++)
            for (int tz = 0; tz < Config.TINY_GRID_SIZE; tz++) {
                tiny.data[tx][ty][tz] = data[tx][ty][tz];
            }

    tiny.notUpToDate = true;
}
项目:TinyVoxel    文件:SingleBundle.java   
@Override
public void init(String name, boolean load) {
    visible = true;
    solid = true;

    this.name = name;

    transform.idt();

    boundingBox = new BoundingBox();
    gridCount = new WrappedInteger(0);
    isLoading = new WrappedBoolean(false);
    references = new WrappedInteger(1);

    if (load) {
        loadAll();
    }

    updateMatrix();
}
项目:TinyVoxel    文件:GridBundle.java   
@Override
public void init(String name, boolean load) {
    visible = true;
    solid = true;

    this.name = name;

    transform.idt();

    terrainMap = new IntMap<IntMap<IntMap<Grid>>>();
    boundingBox = new BoundingBox();
    gridCount = new WrappedInteger(0);
    isLoading = new WrappedBoolean(false);
    references = new WrappedInteger(1);

    if (load) {
        loadAll();
    }

    updateMatrix();
}
项目:gdx-tilemap3d    文件:ModelTileMesh.java   
private void setupMesh(Model model, MaterialTileMapping textures) {
    int numVertices = countModelVertices(model);
    vertices = new Vertices(
            numVertices,
            VertexAttribute.Position(),
            VertexAttribute.ColorUnpacked(),
            VertexAttribute.Normal(),
            VertexAttribute.TexCoords(0)
    );

    model.calculateBoundingBox(tmpModelBounds);
    if (scaleToSize != null) {
        MathHelpers.getScaleFactor(tmpModelBounds.getDimensions(), scaleToSize, tmpScaleFactor);
        bounds = new BoundingBox().set(Vector3.Zero, scaleToSize);
    } else {
        bounds = new BoundingBox().set(Vector3.Zero, tmpModelBounds.getDimensions());
        tmpScaleFactor.set(1.0f, 1.0f, 1.0f);
    }

    for (int i = 0; i < model.nodes.size; ++i)
        collectModelNodeVertices(model.nodes.get(i), vertices, textures, color, tmpScaleFactor, positionOffset);
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static float getSquaredDistanceFromPointToBox(Vector3 point, BoundingBox box) {
    float distanceSq = 0.0f;
    float v;

    v = point.x;
    if (v < box.min.x)
        distanceSq += (box.min.x - v) * (box.min.x - v);
    if (v > box.max.x)
        distanceSq += (v - box.max.x) * (v - box.max.x);

    v = point.y;
    if (v < box.min.y)
        distanceSq += (box.min.y - v) * (box.min.y - v);
    if (v > box.max.y)
        distanceSq += (v - box.max.y) * (v - box.max.y);

    v = point.z;
    if (v < box.min.z)
        distanceSq += (box.min.z - v) * (box.min.z - v);
    if (v > box.max.z)
        distanceSq += (v - box.max.z) * (v - box.max.z);

    return distanceSq;
}
项目:ingress-indonesia-dev    文件:Frustum.java   
public boolean boundsInFrustum(BoundingBox paramBoundingBox)
{
  Vector3[] arrayOfVector3 = paramBoundingBox.getCorners();
  int i = arrayOfVector3.length;
  int j = this.planes.length;
  for (int k = 0; k < j; k++)
  {
    int m = 0;
    int n = 0;
    while (m < i)
    {
      if (this.planes[k].testPoint(arrayOfVector3[m]) == Plane.PlaneSide.Back)
        n++;
      m++;
    }
    if (n == 8)
      return false;
  }
  return true;
}
项目:Tower-Defense-Galaxy    文件:Entity.java   
public Entity(Matrix4 transform, int hp, int health, EnumSet<Types> types, EnumSet<Effects> effects, ModelInstance instance, btCollisionShape shape, btCollisionWorld world, IntMap<Entity> entities, Map<String, Sound> sounds){
    this.instance = instance;
    this.transform = transform;
    this.hp = hp;
    this.types = types;
    this.health = health;
    this.effects = effects;
    this.sounds = sounds;
    animation = new AnimationController(instance);
    this.instance.transform.set(transform);
    this.shape = shape;
    body = new btCollisionObject();
    body.setCollisionShape(shape);
    body.setWorldTransform(this.instance.transform);
    this.world = world;
    tempVector = new Vector3();
    tempVector2 = new Vector3();
    this.entities = entities;
    tempQuaternion = new Quaternion();
    quaternion = new Quaternion();
    if(this instanceof Enemy || this instanceof Projectile)
        body.setCollisionFlags(body.getCollisionFlags());
    int index = getNextIndex();
    entities.put(index, this);
    body.setUserValue(index);
    world.addCollisionObject(body);
    boundingBox = instance.calculateBoundingBox(new BoundingBox());
    //for(Node node: instance.nodes)
        //System.out.println();
}
项目:enklave    文件:RaiderMap.java   
public RaiderMap() {
    manager = ManagerAssets.getInstance();
    Model model = manager.getAssetsRaider().getModel(NameFiles.raiderMap);
    model.nodes.get(2).translation.set(-11,26.5f,-3f);
    instance = new ModelInstance(model);
    instance.transform.scl(1.5f);
    instance.transform.trn(50,50,5);
    instance.transform.rotate(1,0,0,55);
    box = new BoundingBox();
    position = new Vector3();
    dimension = new Vector3();
    instance.calculateBoundingBox(box).mul(instance.transform);
    box.getCenter(position);
    box.getDimensions(dimension);
}
项目:gdx-cclibs    文件:BoundingBoxSerializer.java   
@Override
public void write(Kryo kryo, Output output, BoundingBox boundingBox) {
    Vector3 min = boundingBox.min;
    output.writeFloat(min.x);
    output.writeFloat(min.y);
    output.writeFloat(min.z);
    Vector3 max = boundingBox.max;
    output.writeFloat(max.x);
    output.writeFloat(max.y);
    output.writeFloat(max.z);
}
项目:gdx-cclibs    文件:BoundingBoxSerializer.java   
@Override
public BoundingBox read(Kryo kryo, Input input, Class<BoundingBox> type) {
    Vector3 min = new Vector3();
    min.x = input.readFloat();
    min.y = input.readFloat();
    min.z = input.readFloat();
    Vector3 max = new Vector3();
    max.x = input.readFloat();
    max.y = input.readFloat();
    max.z = input.readFloat();
    return new BoundingBox(min, max);
}
项目: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);
}
项目:ZombieInvadersVR    文件:GameObject.java   
public void updateBox(){
Vector3 position = transform.getTranslation(new Vector3());
      if(customBounds != null) bounds = new BoundingBox(customBounds);
      else calculateBoundingBox(bounds);
      bounds.getCenter(center);
      bounds.set(bounds.min.add(position.x,position.y, position.z), bounds.max.add(position.x, position.y, position.z));
  }
项目:nhglib    文件:VehicleBuilder.java   
public VehicleBuilder buildChassis(float mass) {
    Vector3 chassisHalfExtents = chassisModel
            .calculateBoundingBox(new BoundingBox())
            .getDimensions(new Vector3())
            .scl(0.5f);

    btBoxShape boxShape = new btBoxShape(chassisHalfExtents);
    return buildChassis(boxShape, mass);
}
项目:nhglib    文件:VehicleBuilder.java   
public VehicleBuilder buildWheel(Vector3 point, Vector3 direction, Vector3 axis, float friction,
                                 boolean frontWheel) {
    Vector3 wheelHalfExtents = wheelModel
            .calculateBoundingBox(new BoundingBox())
            .getDimensions(new Vector3())
            .scl(0.5f);

    return buildWheel(point, direction, axis, wheelHalfExtents.z, wheelHalfExtents.z * 0.3f,
            friction, frontWheel);
}
项目:nhglib    文件:ModelComponent.java   
public void buildWithModel(ModelInstance m) {
    model = m;
    boundingBox = new BoundingBox();
    model.calculateBoundingBox(boundingBox);

    Vector3 dimensions = boundingBox.getDimensions(new Vector3());
    radius = dimensions.len() / 2f;

    state = ModelComponent.State.READY;

    if (m.animations.size > 0) {
        animationController = new AnimationController(model);
    }
}
项目:libgdxjam    文件:OverlapSceneLoader.java   
private Entity loadParticle(OverlapScene scene, JsonValue value) {
    Entity entity = new Entity();

    logger.info("loading particle: " + value.getString("particleName") + " " + value.getString("itemIdentifier", ""));

    NodeComponent node = new NodeComponent();
    TransformComponent transform = new TransformComponent();
    ParticleComponent particle = new ParticleComponent();
    ZIndexComponent index = new ZIndexComponent();
    SizeComponent size = new SizeComponent();
    IDComponent id = new IDComponent();

    id.value = value.getInt("uniqueId");

    loadTransform(transform, value);
    index.layer = value.getString("layerName");

    String particleName = value.getString("particleName");

    ParticleEffect effect = new ParticleEffect();
    effect.load(
        Gdx.files.internal(PARTICLES_DIR + particleName),
        atlas
    );

    particle.effect = effect;
    BoundingBox box = particle.effect.getBoundingBox(); 
    size.width = (box.max.x - box.min.x) * parameters.units;
    size.height = (box.max.y - box.min.y) * parameters.units;

    entity.add(node);
    entity.add(size);
    entity.add(transform);
    entity.add(particle);
    entity.add(index);
    entity.add(id);

    return entity;
}
项目:libgdxjam    文件:PlayerBulletContactListener.java   
private void spawnSmoke(Entity entity) {
    Entity smoke = new Entity();

    ParticleComponent particle = new ParticleComponent();
    NodeComponent node = new NodeComponent();
    TransformComponent transform = new TransformComponent();
    ZIndexComponent index = new ZIndexComponent();
    SizeComponent size = new SizeComponent();

    AssetManager assetManager = Env.getGame().getAssetManager();
    TextureAtlas atlas = assetManager.get(Env.SCENES_TEXTURES_FOLDER + "pack.atlas", TextureAtlas.class);
    particle.effect = new ParticleEffect();
    particle.effect.load(Gdx.files.internal(Env.PARTICLES_FOLDER + "playerDie"), atlas);
    particle.effect.start();

    Entity parent = NodeUtils.getParent(entity);
    node.parent = parent;
    Mappers.node.get(parent).children.add(smoke);

    transform.position.set(Mappers.transform.get(entity).position);

    ZIndexComponent entityIndex = Mappers.index.get(entity);
    index.index = entityIndex.index - 1;
    index.layer = entityIndex.layer;

    BoundingBox box = particle.effect.getBoundingBox();
    size.width = box.max.x - box.min.x;
    size.height = box.max.y - box.min.y;

    smoke.add(particle);
    smoke.add(node);
    smoke.add(transform);
    smoke.add(index);
    smoke.add(size);

    engine.addEntity(smoke);
}
项目:origin    文件:GridChunk.java   
public GridChunk(Grid grid, int cx, int cy)
{
    _grid = grid;

    _cx = cx;
    _cy = cy;

    // отступ данного грида в тайлах
    _gx = _grid.getTc().x;
    _gy = _grid.getTc().y;

    _waterMesh = null;

    fillVertex();
    fillNormals();
    makeMesh();

    // определим нужна ли вода в этом чанке?
    // хоть одна вершина ниже уровня воды?
    if (_minHeight < WATER_LEVEL)
    {
        makeWater();
    }

    _boundingBox = new BoundingBox(
            new Vector3(_gx + _cx, _minHeight, _gy + _cy),
            new Vector3(_gx + _cx + CHUNK_SIZE, _maxHeight, _gy + _cy + CHUNK_SIZE));

}
项目:eamaster    文件:BulletConstructor.java   
/** Creates a btBoxShape with the same dimensions as the shape. */
public BulletConstructor (final Model model, final float mass) {
    final BoundingBox boundingBox = new BoundingBox();
    model.calculateBoundingBox(boundingBox);
    final Vector3 dimensions = boundingBox.getDimensions();
    create(model, mass, dimensions.x, dimensions.y, dimensions.z);
}
项目:Radix    文件:LivingEntity.java   
public int getBlockInFeet(IWorld world) {
    int x = MathUtils.floor(getPosition().getX());
    int y = MathUtils.floor(getPosition().getY());
    int z = MathUtils.floor(getPosition().getZ());
    IChunk chunk = world.getChunk(x, z);
    if (chunk != null && y < world.getHeight()) {
        int cx = x & (world.getChunkSize() - 1);
        int cz = z & (world.getChunkSize() - 1);
        try {
            int id = chunk.getBlockId(cx, y, cz);
            Block block = RadixAPI.instance.getBlock(id);
            if (block == null) return 0;
            BoundingBox blockBox = block.calculateBoundingBox(chunk, cx, y, cz);
            float halfWidth = width / 2f;
            Vector3 bottomBackLeft = getPosition().cpy().add(-halfWidth, 0, -halfWidth);
            Vector3 bottomBackRight = bottomBackLeft.cpy().add(width, 0, 0);
            Vector3 bottomFrontRight = bottomBackRight.cpy().add(0, 0, width);
            Vector3 bottomFrontLeft = bottomBackLeft.cpy().add(width, 0, 0);

            boolean inFeet = blockBox.contains(bottomBackLeft) || blockBox.contains(bottomBackRight) || blockBox.contains(bottomFrontLeft) || blockBox.contains(bottomFrontRight);

            return inFeet ? id : 0;
        } catch (BlockStorage.CoordinatesOutOfBoundsException ex) {
            ex.printStackTrace();
            return 0;
        }
    } else {
        return 0;
    }
}
项目:Radix    文件:MovementHandler.java   
public boolean checkDeltaCollision(LivingEntity e, float deltaX, float deltaY, float deltaZ) {
    BoundingBox curBB = e.calculateBoundingBox();
    BoundingBox newBB = new BoundingBox(curBB.min.cpy().add(deltaX, deltaY, deltaZ), curBB.max.cpy().add(deltaX, deltaY, deltaZ));

    boolean collideSuccess = false;

    int x = MathUtils.floor(e.getPosition().x);
    int y = MathUtils.floor(e.getPosition().y);
    int z = MathUtils.floor(e.getPosition().z);

    IChunk chunk = game.getWorld().getChunk(x, z);
    if (chunk == null)
        return true;

    int cx = x & (game.getWorld().getChunkSize() - 1);
    int cz = z & (game.getWorld().getChunkSize() - 1);
    try {
        Block block = chunk.getBlock(cx, y, cz);

        for (Vector3 corner : getCorners(newBB)) {
            collideSuccess = collideSuccess || checkCollision(corner);
        }

        return collideSuccess ||
                (block != null && block.isSolid()
                        && block.calculateBoundingBox(chunk, cx, y, cz).intersects(newBB));
    } catch(CoordinatesOutOfBoundsException ex) {
        ex.printStackTrace();
        return true;
    }
}
项目:Radix    文件:Snow.java   
@Override
public BoundingBox calculateBoundingBox(IChunk c, int x, int y, int z) {
    short metadata = 0;
    try {
        metadata = c.getMeta(x, y, z);
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }

    return new BoundingBox(new Vector3(c.getStartPosition().x+x, y, c.getStartPosition().z+z),
            new Vector3(c.getStartPosition().x+x+1, y+getHeight(metadata), c.getStartPosition().z+z+1));
}
项目:Radix    文件:Liquid.java   
@Override
public BoundingBox calculateBoundingBox(IChunk c, int x, int y, int z) {
    short metadata = 0;
    try {
        metadata = c.getMeta(x, y, z);
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }

    return new BoundingBox(new Vector3(c.getStartPosition().x+x, y, c.getStartPosition().z+z),
            new Vector3(c.getStartPosition().x+x+1, y+getHeight(metadata), c.getStartPosition().z+z+1));
}
项目:libgdx-inGameConsole    文件:Box2DTest.java   
/** Creates an explosion that applies forces to the bodies relative to their position and the given x and y values.
 *
 * @param maxForce The maximum force to be applied to the bodies (diminishes as distance from touch increases). */
private void createExplosion (float x, float y, float maxForce) {
    float force;
    Vector2 touch = new Vector2(x, y);
    for (int i = 0; i < bodies.length; i++) {
        Body b = bodies[i];
        Vector2 v = b.getPosition();
        float dist = v.dst2(touch);

        if (dist == 0)
            force = maxForce;
        else
            force = MathUtils.clamp(maxForce / dist, 0, maxForce);

        float angle = v.cpy().sub(touch).angle();
        float xForce = force * MathUtils.cosDeg(angle);
        float yForce = force * MathUtils.sinDeg(angle);

        Vector3 touch3, v3, boundMin, boundMax, intersection;
        touch3 = new Vector3(touch.x, touch.y, 0);
        v3 = new Vector3(v.x, v.y, 0);
        boundMin = new Vector3(v.x - 1, v.y - 1, 0);
        boundMax = new Vector3(v.x + 1, v.y + 1, 0);
        intersection = Vector3.Zero;

        Intersector.intersectRayBounds(new Ray(touch3, v3), new BoundingBox(boundMin, boundMax), intersection);

        b.applyForce(new Vector2(xForce, yForce), new Vector2(intersection.x, intersection.y), true);
    }
}
项目:ForgE    文件:TerrainEngine.java   
public TerrainEngine(Level level) {
  this.frustrumOctreeQuery  = new FrustrumClassFilterOctreeQuery();
  this.tempObjects          = new Array<OctreeObject>();
  this.visibleChunks        = new Array<Chunk>();
  this.visibleTerrainFaces  = new Array<VoxelChunkRenderable>();
  this.visibleWaterFaces    = new Array<VoxelChunkRenderable>();
  this.chunks               = new Array<Chunk>();
  this.map                  = level.terrainMap;
  this.octree               = level.octree;
  this.geometryProvider     = level.terrainGeometryProvider;
  this.tempBox              = new BoundingBox();
  frustrumOctreeQuery.setKlass(Chunk.class);
}
项目:ForgE    文件:OctreeNode.java   
public OctreeNode() {
  this.tempA    = new Vector3();
  this.tempB    = new Vector3();
  this.tempC    = new Vector3();
  this.level    = 0;
  this.objects  = new Array<OctreeObject>();
  this.nodes    = new Array<OctreeNode>();
  this.bounds   = new BoundingBox();
  this.parent   = null;
  this.maxObjects = 24;
  clear();
}
项目:ForgE    文件:OctreeNode.java   
public int getIndex(BoundingBox pRect) {
  int index = -1;
  if (haveNodes()) {
    for (int i = 0; i < nodes.size; i++) {
      OctreeNode node = nodes.get(i);
      if (node.contains(pRect)) {
        index = i;
        break;
      }
    }
  }
  return index;
}
项目:ForgE    文件:OctreeNode.java   
public void retrieve(Array<OctreeObject> returnObjects, BoundingBox object) {
  int index = getIndex(object);
  if (index != -1 && haveNodes()) {
    nodes.get(index).retrieve(returnObjects, object);
  }
  returnObjects.addAll(objects);
}
项目:ForgE    文件:StorageManager.java   
public Kryo create () {
  Kryo kryo = new Kryo();
  kryo.register(GameDatabase.class, new GameDatabaseSerializer());
  kryo.register(LevelState.class, new FullLevelStateSerializer());
  kryo.register(ChunkMap.class, new ChunkMapDataSerializer());
  kryo.register(Voxel.class, new VoxelSerializer());
  kryo.register(Vector3.class, new Vector3Serializer());
  kryo.register(LevelEnv.class, new LevelEnvSerializer());
  kryo.register(Vector2.class, new Vector2Serializer());
  kryo.register(Color.class, new ColorSerializer());
  kryo.register(DirectionalLight.class, new DirectionalLightSerializer());
  kryo.register(Asset.class, new AssetSerializer());
  kryo.register(BoundingBox.class, new BoundingBoxSerializer());
  kryo.register(VoxelChunkRenderable.class, new VoxelFaceRenderableSerializer());
  kryo.register(Matrix4.class, new Matrix4Serializer());
  kryo.register(Vector3i.class, new Vector3iSerializer());
  kryo.register(Teleport.class, new PlayerStartPositionSerializer());
  kryo.register(TextureAsset.class, new AssetSerializer());
  kryo.register(ModelAsset.class, new AssetSerializer());
  kryo.register(CubemapAsset.class, new AssetSerializer());
  kryo.setDefaultSerializer(TaggedFieldSerializer.class);
  kryo.register(Skybox.class, new SkyboxSerializer());
  kryo.register(CubemapSkybox.class, new SkyboxSerializer());
  kryo.register(DayNightSkybox.class, new SkyboxSerializer());
  kryo.register(WaterEnv.class, new WaterEnvSerializer());
  kryo.register(DynamicGeometryProvider.class, new TerrainGeometryProviderSerializer());
  kryo.register(VoxelChunkRenderableFactory.class, new VoxelChunkRenderableFactorySerializer());
  kryo.register(ChunkPartCollider.class, new ChunkPartColliderSerializer());
  kryo.register(OrthographicDirectionalLight.class, new OrthographicDirectionalLightSerializer());
  return kryo;
}
项目:ForgE    文件:VoxelFaceRenderableSerializer.java   
@Override
public VoxelChunkRenderable read(Kryo kryo, Input input, Class<VoxelChunkRenderable> type) {
  VoxelChunkRenderable renderable = new VoxelChunkRenderable();
  renderable.material             = kryo.readObjectOrNull(input, Material.class);
  renderable.direction            = kryo.readObject(input, Vector3.class);
  renderable.boundingBox          = kryo.readObject(input, BoundingBox.class);
  renderable.primitiveType        = input.readInt();
  renderable.triangleCount        = input.readInt();
  renderable.worldTransform.set(kryo.readObject(input, Matrix4.class));

  int maxVerticies                = input.readInt();
  float[] vertBuff                = new float[maxVerticies];

  for (int pos = 0; pos < maxVerticies; pos++) {
    vertBuff[pos] = input.readFloat();
  }

  int numIndicies         = input.readInt();
  short[] indiBuff        = new short[numIndicies];

  for (int pos = 0; pos < numIndicies; pos++) {
    indiBuff[pos] = input.readShort();
  }

  renderable.meshFactory = new MeshFactory(vertBuff, indiBuff, MeshVertexInfo.voxelAttributes());
  return renderable;
}
项目:ForgE    文件:DebugSystem.java   
public DebugSystem(Level level) {
  super();
  this.entities         = new Array<Entity>();
  this.family           = Family.getFor(PositionComponent.class);
  this.level            = level;
  this.batch            = level.batch;
  this.context          = level.renderContext;
  this.dynamicOctree    = level.octree;
  this.terrainOctree    = level.octree;
  this.camera           = level.camera;
  this.terrain          = level.terrainEngine;
  this.frustrumDebugger = level.frustrumDebugger;
  this.tempBox          = new BoundingBox();
  this.tempVec          = new Vector3();
}
项目:libgdxcn    文件:Model.java   
/** Extends the bounding box with the bounds of this model instance. This is a potential slow operation, it is advised to cache
 * the result.
 * @param out the {@link BoundingBox} that will be extended with the bounds.
 * @return the out parameter for chaining */
public BoundingBox extendBoundingBox (final BoundingBox out) {
    final int n = nodes.size;
    for (int i = 0; i < n; i++)
        nodes.get(i).extendBoundingBox(out);
    return out;
}