/** * Performs a ray cast from start point to end point. * * @param start start point * @param end end point * @return ray cast result */ public RaycastResult raycast(Point2D start, Point2D end) { raycastCallback.reset(); jboxWorld.raycast(raycastCallback, toPoint(start), toPoint(end)); Entity entity = null; Point2D point = null; if (raycastCallback.getFixture() != null) entity = raycastCallback.getFixture().getBody().getEntity(); if (raycastCallback.getPoint() != null) point = toPoint(raycastCallback.getPoint()); if (entity == null && point == null) return RaycastResult.NONE; return new RaycastResult(entity, point); }
/** * Performs a ray cast from start point to end point. * * @param start start point * @param end end point * @return ray cast result */ public RaycastResult raycast(Point2D start, Point2D end) { raycastCallback.reset(); jboxWorld.raycast(raycastCallback, toPoint(start), toPoint(end)); Entity entity = null; Point2D point = null; if (raycastCallback.getFixture() != null) entity = raycastCallback.getFixture().getBody().getEntity(); if (raycastCallback.getPoint() != null) point = toPoint(raycastCallback.getPoint()); if (entity == null && point == null) return RaycastResult.NONE; return new RaycastResult(entity, point); }
@Override public void endContact(Contact contact) { Entity e1 = contact.getFixtureA().getBody().getEntity(); Entity e2 = contact.getFixtureB().getBody().getEntity(); // check sensors first if (contact.getFixtureA().isSensor()) { notifySensorCollisionEnd(e1, e2, contact.getFixtureA().getHitBox()); return; } else if (contact.getFixtureB().isSensor()) { notifySensorCollisionEnd(e2, e1, contact.getFixtureB().getHitBox()); return; } if (!areCollidable(e1, e2)) return; CollisionHandler handler = getHandler(e1, e2); if (handler != null) { int pairIndex = getPairIndex(e1, e2); // collision registered, so remove it and put pair back to pool if (pairIndex != -1) { CollisionPair pair = collisions.get(pairIndex); collisions.removeIndex(pairIndex); pair.collisionEnd(); Pools.free(pair); } } }
@Override public void endContact(Contact contact) { Entity e1 = contact.getFixtureA().getBody().getEntity(); Entity e2 = contact.getFixtureB().getBody().getEntity(); // check sensors first if (contact.getFixtureA().isSensor()) { HitBox box = (HitBox) contact.getFixtureA().getUserData(); SensorCollisionHandler h = e1.getComponent(PhysicsComponent.class).getSensorHandlers().get(box); h.onCollisionEnd(e2); return; } else if (contact.getFixtureB().isSensor()) { HitBox box = (HitBox) contact.getFixtureB().getUserData(); SensorCollisionHandler h = e2.getComponent(PhysicsComponent.class).getSensorHandlers().get(box); h.onCollisionEnd(e1); return; } if (!areCollidable(e1, e2)) return; CollisionHandler handler = getHandler(e1, e2); if (handler != null) { int pairIndex = getPairIndex(e1, e2); // collision registered, so remove it and put pair back to pool if (pairIndex != -1) { CollisionPair pair = collisions.get(pairIndex); collisions.removeIndex(pairIndex); pair.collisionEnd(); Pools.free(pair); } } }