/** Ray-cast the world for all fixtures in the path of the ray. The ray-cast ignores shapes that contain the starting point. * @param callback a user implemented callback class. * @param point1 the ray starting point * @param point2 the ray ending point */ public void rayCast (RayCastCallback callback, Vector2 point1, Vector2 point2) { rayCast(callback, point1.x, point1.y, point2.x, point2.y); }
public void rayCast (final RayCastCallback callback, Vector2 point1, Vector2 point2) { rayCast(callback, point1.x, point1.y, point2.x, point2.y); }
/** translate particle given amount. Continuous collision detection achieved by using RayCast from oldPos to newPos. * * @param velocityX * @param velocityY */ @Override public void translate (float velocityX, float velocityY) { /** If velocities squares summed is shorter than Epsilon it could lead ~0 length rayCast that cause nasty c++ assertion * inside box2d. This is so short distance that moving particle has no effect so this return early. */ if ((velocityX * velocityX + velocityY * velocityY) < EPSILON) return; /** Position offset is half of sprite texture size. */ final float x = getX() + getWidth() / 2f; final float y = getY() + getHeight() / 2f; /** collision flag to false */ particleCollided = false; startPoint.set(x, y); endPoint.set(x + velocityX, y + velocityY); if (world != null) world.rayCast(rayCallBack, startPoint, endPoint); /** If ray collided boolean has set to true at rayCallBack */ if (particleCollided) { // perfect reflection angle = 2f * normalAngle - angle - 180f; angleCos = MathUtils.cosDeg(angle); angleSin = MathUtils.sinDeg(angle); velocityX *= angleCos; velocityY *= angleSin; } super.translate(velocityX, velocityY); } }
/** Ray-cast the world for all fixtures in the path of the ray. The ray-cast ignores shapes that contain the starting point. * @param callback a user implemented callback class. * @param point1 the ray starting point * @param point2 the ray ending point */ public void rayCast (RayCastCallback callback, Vector2 point1, Vector2 point2) { rayCast(callback, point1.x, point1.y, point2.x, point2.y); }
final void doRaycast( Light requestingLight, Vector2 start, Vector2 end ) { ray.requestingLight = requestingLight; world.rayCast( ray, start, end ); }
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; }
protected void updateMesh() { for (int i = 0; i < rayNum; i++) { m_index = i; f[i] = 1f; tmpEnd.x = endX[i] + start.x; mx[i] = tmpEnd.x; tmpEnd.y = endY[i] + start.y; my[i] = tmpEnd.y; if (rayHandler.world != null && !xray) { rayHandler.world.rayCast(ray, start, tmpEnd); } } setMesh(); }
protected void updateMesh() { for (int i = 0; i < rayNum; i++) { m_index = i; f[i] = 1f; tmpEnd.x = endX[i] + start.x; mx[i] = tmpEnd.x; tmpEnd.y = endY[i] + start.y; my[i] = tmpEnd.y; if (rayHandler.world != null && !xray) { rayHandler.world.rayCast(ray, start, tmpEnd); } } setMesh(); }
protected void updateMesh() { for (int i = 0; i < rayNum; i++) { m_index = i; f[i] = 1f; tmpEnd.x = endX[i]; mx[i] = tmpEnd.x; tmpEnd.y = endY[i]; my[i] = tmpEnd.y; tmpStart.x = startX[i]; tmpStart.y = startY[i]; if (rayHandler.world != null && !xray) { rayHandler.world.rayCast(ray, tmpStart, tmpEnd); } } setMesh(); }
protected void updateMesh() { for (int i = 0; i < rayNum; i++) { m_index = i; f[i] = 1f; tmpEnd.x = endX[i]; mx[i] = tmpEnd.x; tmpEnd.y = endY[i]; my[i] = tmpEnd.y; tmpStart.x = startX[i]; tmpStart.y = startY[i]; if (rayHandler.world != null && !xray) { rayHandler.world.rayCast(ray, tmpStart, tmpEnd); } } setMesh(); }
protected boolean checkCanKickBomb(Body body, Vector2 fromV, Vector2 toV) { World b2dWorld = body.getWorld(); kickingBomb = null; kicking = false; RayCastCallback rayCastCallback = new RayCastCallback() { @Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { Entity bombEntity = (Entity) fixture.getBody().getUserData(); kickingBomb = bombEntity.getComponent(Bomb.class); return 0; } return 0; } }; b2dWorld.rayCast(rayCastCallback, fromV, toV); if (kickingBomb != null) { kicking = true; } return kicking; }
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; } }
public void update() { long startTime = TimeUtils.nanoTime(); Gdx.app.log(TAG, " -- Begining of Update tick (" + requestQueue.size() + ") --"); RayCastRequest rr = requestQueue.poll(); while(rr != null && TimeUtils.timeSinceNanos(startTime) < budgetTime * 1000000000f){ //budgetTime * seconds to nano world.rayCast(rr.callback, rr.point1, rr.point2); Gdx.app.log(TAG, " " + rr.point1 + " - " + rr.point2 + " processed at (" + (TimeUtils.timeSinceNanos(startTime) / 1000000000f) + ") with priority: " + rr.priority); rr = requestQueue.poll(); } Gdx.app.log(TAG, " -- End of Update tick --"); }
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; }
protected boolean hitBombVertical(final Body body, Vector2 fromV, Vector2 toV) { World b2dWorld = body.getWorld(); hitting = false; RayCastCallback rayCastCallback = new RayCastCallback() { @Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getBody() == body) { return 1; } if (fraction < 1.0f && fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { hitting = 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 hitting; }
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; }
protected boolean hitBombHorizontal(final Body body, Vector2 fromV, Vector2 toV) { World b2dWorld = body.getWorld(); hitting = false; RayCastCallback rayCastCallback = new RayCastCallback() { @Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getBody() == body) { return 1; } if (fraction < 1.0f && fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { hitting = 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 hitting; } }
@Override public boolean touchDragged(int x, int y, int pointer) { viewport.getCamera().unproject(point.set(x, y, 0)); if(Gdx.input.isButtonPressed(Buttons.LEFT)) { if(p1.x != point.x && p1.y != point.y) { p2.set(point.x, point.y); world.rayCast(callback, p1, p2); return true; } } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Screen coordinates to World coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { p1.set(point.x, point.y); p2.set(point.x, point.y+0.00001f); // +.00001 because otherwise it will crash normal.set(Vector2.Zero); collision.set(Vector2.Zero); world.rayCast(callback, p1, p2); return true; } return false; }
/** translate particle given amount. Continuous collision detection achieved by using RayCast from oldPos to newPos. * * @param velocityX * @param velocityY */ @Override public void translate (float velocityX, float velocityY) { /** If velocities squares summed is shorter than Epsilon it could lead ~0 length rayCast that cause nasty c++ assertion * inside box2d. This is so short distance that moving particle has no effect so this return early. */ if ((velocityX * velocityX + velocityY * velocityY) < EPSILON) return; /** Position offset is half of sprite texture size. */ final float x = getX() + getWidth() / 2f; final float y = getY() + getHeight() / 2f; /** collision flag to false */ particleCollided = false; startPoint.set(x, y); endPoint.set(x + velocityX, y + velocityY); if (world != null) world.rayCast(rayCallBack, startPoint, endPoint); /** If ray collided boolean has set to true at rayCallBack */ if (particleCollided) { // perfect reflection angle = 2f * normalAngle - angle - 180f; angleCos = MathUtils.cosDeg(angle); angleSin = MathUtils.sinDeg(angle); velocityX *= angleCos; velocityY *= angleSin; } super.translate(velocityX, velocityY); } }