本文整理汇总了Java中com.badlogic.gdx.physics.box2d.RayCastCallback类的典型用法代码示例。如果您正苦于以下问题:Java RayCastCallback类的具体用法?Java RayCastCallback怎么用?Java RayCastCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RayCastCallback类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了RayCastCallback类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkBottomCollision
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
private void checkBottomCollision() {
float raySize = -(verticalSpeed+Gdx.graphics.getDeltaTime())*Gdx.graphics.getDeltaTime();
if(raySize < 5f) raySize = 5f;
if(verticalSpeed > 0) return;
final Vector2 rayFrom = new Vector2((item.getX() + item.getWidth() / 2) * PhysicsBodyLoader.SCALE,
(item.getY() + item.getHeight()/2) * PhysicsBodyLoader.SCALE);
final Vector2 rayTo = new Vector2((item.getX() + item.getWidth() / 2) * PhysicsBodyLoader.SCALE,
(item.getY() - raySize) * PhysicsBodyLoader.SCALE);
gameStage.getWorld().rayCast(new RayCastCallback(){
public float reportRayFixture(final Fixture fixture, final Vector2 point, final Vector2 normal, final float fraction){
verticalSpeed = 0;
item.setY(point.y/PhysicsBodyLoader.SCALE+0.1f);
return 0;
}
}, rayFrom, rayTo);
}
示例2: checkMovable
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
private boolean checkMovable(Body body, Vector2 from, Vector2 to) {
World b2dWorld = body.getWorld();
moveable = true;
RayCastCallback rayCastCallback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT
| fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT
| fixture.getFilterData().categoryBits == GameManager.BOMB_BIT
| fixture.getFilterData().categoryBits == GameManager.ENEMY_BIT
| fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT) {
moveable = false;
return 0;
}
return 0;
}
};
b2dWorld.rayCast(rayCastCallback, from, to);
return moveable;
}
示例3: checkCanExplodeThrough
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
private boolean checkCanExplodeThrough(Vector2 fromV, Vector2 toV) {
canExplodeThrough = true;
RayCastCallback rayCastCallback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (fixture.getFilterData().categoryBits == GameManager.INDESTRUCTIIBLE_BIT) {
canExplodeThrough = false;
return 0;
}
if (fixture.getFilterData().categoryBits == GameManager.BREAKABLE_BIT) {
canExplodeThrough = false;
Entity e = (Entity) fixture.getBody().getUserData();
Breakable breakable = e.getComponent(Breakable.class);
breakable.state = Breakable.State.EXPLODING;
return 0;
}
return 0;
}
};
b2dWorld.rayCast(rayCastCallback, fromV, toV);
return canExplodeThrough;
}
示例4: raycast
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
public static List<RaycastHit> raycast(Vector2 start, Vector2 direction) {
final List<RaycastHit> hits = new ArrayList<RaycastHit>();
Vector2 end = start.add(direction);
//TODO move to static single object
physic.physicWorld.rayCast(new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
hits.add(new RaycastHit(fixture, point, normal, fraction));
return 1;
}
}, start, end);
return hits;
}
示例5: checkMovable
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
private boolean checkMovable(Body body, MoveDir dir) {
canMove = true;
World world = body.getWorld();
RayCastCallback rayCastCallback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
if (fixture.getFilterData().categoryBits == GameManager.WALL_BIT || fixture.getFilterData().categoryBits == GameManager.GATE_BIT) {
canMove = false;
return 0;
}
return 0;
}
};
for (int i = 0; i < 2; i++) {
tmpV1.set(body.getPosition());
switch (dir) {
case UP:
tmpV2.set(body.getPosition().x - (i - 0.5f) * 0.2f, body.getPosition().y + 0.6f);
break;
case DOWN:
tmpV2.set(body.getPosition().x - (i - 0.5f) * 0.2f, body.getPosition().y - 0.6f);
break;
case LEFT:
tmpV2.set(body.getPosition().x - 0.6f, body.getPosition().y - (i - 0.5f) * 0.2f);
break;
case RIGHT:
tmpV2.set(body.getPosition().x + 0.6f, body.getPosition().y - (i - 0.5f) * 0.2f);
break;
default:
break;
}
world.rayCast(rayCastCallback, tmpV1, tmpV2);
}
return canMove;
}
示例6: hitSomethingVertical
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
protected boolean hitSomethingVertical(final Body body, Vector2 fromV, Vector2 toV) {
World b2dWorld = body.getWorld();
hit = false;
RayCastCallback rayCastCallback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
// if hit the player, ignore it
if (fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT || fixture.getFilterData().categoryBits == GameManager.POWERUP_BIT) {
return 0;
}
if (fraction < 1.0f) {
hit = true;
}
return 0;
}
};
for (int i = 0; i < 3; i++) {
Vector2 tmpV = new Vector2(toV);
b2dWorld.rayCast(rayCastCallback, fromV, tmpV.add((1 - i) * 0.4f, 0));
}
return hit;
}
示例7: hitSomethingHorizontal
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
protected boolean hitSomethingHorizontal(final Body body, Vector2 fromV, Vector2 toV) {
World b2dWorld = body.getWorld();
hit = false;
RayCastCallback rayCastCallback = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
// if hit the player or power-up item, ignore it
if (fixture.getFilterData().categoryBits == GameManager.PLAYER_BIT || fixture.getFilterData().categoryBits == GameManager.POWERUP_BIT) {
return 0;
}
if (fraction < 1.0f) {
hit = true;
}
return 0;
}
};
for (int i = 0; i < 3; i++) {
Vector2 tmpV = new Vector2(toV);
b2dWorld.rayCast(rayCastCallback, fromV, tmpV.add(0, (1 - i) * 0.4f));
}
return hit;
}
示例8: checkForCollision
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
private void checkForCollision() {
float rayGap = item.getHeight() / 2;
float raySize = -(Life.verticalSpeed + Gdx.graphics.getDeltaTime())
* Gdx.graphics.getDeltaTime();
if (raySize < 5f)
raySize = 5f;
if (Life.verticalSpeed > 0)
return;
Vector2 rayFrom = new Vector2((item.getX() + item.getWidth() / 2)
* PhysicsBodyLoader.SCALE, (item.getY() + rayGap)
* PhysicsBodyLoader.SCALE);
Vector2 rayTo = new Vector2((item.getX() + item.getWidth() / 2)
* PhysicsBodyLoader.SCALE, (item.getY() - raySize)
* PhysicsBodyLoader.SCALE);
// cast the ray
stage.getWorld().rayCast(new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point,
Vector2 normal, float fraction) {
// stop the player
Life.verticalSpeed = 0;
// reposition player slightly upper the collision point
item.setY(point.y / PhysicsBodyLoader.SCALE + 0.1f);
// make sure it is grounded, to allow jumping again
Life.grounded = true;
// jumpCounter = 0;
return 0;
}
}, rayFrom, rayTo);
}
示例9: rayCast
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
public void rayCast(final RayCastCallback pRayCastCallback, final Vector2 pPoint1, final Vector2 pPoint2) {
this.mWorld.rayCast(pRayCastCallback, pPoint1, pPoint2);
}
示例10: getCrubsOnSuffering
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
public List<MushroomedCrab> getCrubsOnSuffering(Player player) {
final List<MushroomedCrab> crabs = level.getCrabs();
final List<MushroomedCrab> suffered = new ArrayList<MushroomedCrab>();
Vector2 ppos = player.getBody().getPosition();
Vector2 fireTo = null;
if (player.getDirX() == DirectionX.RIGHT) {
switch (player.getDirY()) {
case CROSSHAIR_UP:
fireTo = new Vector2(ppos.x + 8, ppos.y + 8);
break;
case CROSSHAIR_DOWN:
fireTo = new Vector2(ppos.x + 8, ppos.y - 8);
break;
case CROSSHAIR_MIDDLE:
fireTo = new Vector2(ppos.x + 8, ppos.y);
break;
}
} else {
switch (player.getDirY()) {
case CROSSHAIR_UP:
fireTo = new Vector2(ppos.x - 8, ppos.y + 8);
break;
case CROSSHAIR_DOWN:
fireTo = new Vector2(ppos.x - 8, ppos.y - 8);
break;
case CROSSHAIR_MIDDLE:
fireTo = new Vector2(ppos.x - 8, ppos.y);
break;
}
}
// find all concats with player shot
level.getWorld().rayCast(new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point,
Vector2 normal, float fraction) {
for (MushroomedCrab crab : crabs) {
if (crab.getBody() == fixture.getBody()) {
suffered.add(crab);
return 0;
}
}
return -1;
}
}, player.getBody().getPosition(), fireTo);
return suffered;
}
示例11: raycast
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
public void raycast(int worldId, RayCastCallback callback, Vector2 point1, Vector2 point2) {
universe.get(worldId).rayCast(callback, point1, point2);
}
示例12: process
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
@Override
protected void process(final Entity e) {
Particle p = (Particle) e.getComponent(Particle.class);
// Move the particle
Vector2 pos = p.getPosition().cpy();
Vector2 deltaX = new Vector2(p.getLinearVelocity().x * deltaSeconds(),
p.getLinearVelocity().y * deltaSeconds());
// DO RAY CASTING FOR COLLIDABLE CHECK
LogManager.debug("Physics", "Started raycasting for particle");
if (e.hasComponent(Collidable.class)) {
if (p.getLinearVelocity().len() == 0) {
throw new GdxRuntimeException("Cannot raycast for particle with speed of 0.");
}
World c = world.getBox2DWorld();
// Perform the raycast
c.rayCast(new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point,
Vector2 normal, float fraction) {
// If collision occurs
final Collidable col = (Collidable) e
.getComponent(Collidable.class);
// Get the victim
if (fixture.isSensor())
return 0;
final Entity victim = (Entity) fixture.getBody()
.getUserData();
float continueCol = col.continueCollision(e, victim);
if (continueCol == 0)
// Call the on collide event for the entity and
// terminate if appropriate.
rayCastCollisions.addCallback(new Object(),
new EventCallback() {
@Override
public void invoke(Entity es,
Object... args) {
col.onBeginContact(e, victim);
}
});
// Return whether or not the ray cast should be terminated.
return col.continueCollision(e, victim);
}
}, pos, pos.cpy().add(deltaX));
}
LogManager.debug("Physics", "Finished raycasting for particle");
// Move and set the final position of the entity.
pos.add(deltaX);
p.setPosition(pos);
float angularVelocity = p.getAngularVelocity() * deltaSeconds();
p.setRotation(p.getRotation() + angularVelocity);
}
示例13: inLineOfSight
import com.badlogic.gdx.physics.box2d.RayCastCallback; //导入依赖的package包/类
public static boolean inLineOfSight(Vector2 a, Vector2 b){
RayCastCallback cb = new RayCastCallback() {
@Override
public float reportRayFixture(Fixture arg0, Vector2 arg1,
Vector2 arg2, float arg3) {
return 0;
}
};
MySidekick.getWorld().rayCast(cb, null, null);
return true;
}