use of org.jbox2d.common.Vec2 in project HackerHop by nicovank.
the class PlayerTest method playerShapeTest.
@Test
void playerShapeTest() {
World world = new World(new Vec2(0, -50));
Vec2 position = new Vec2(0, 10);
Player p = new Player(world, position);
Shape s = p.getBody().getFixtureList().m_shape;
PolygonShape r = new PolygonShape();
r.setAsBox(3, 3);
assertEquals(s.getType(), r.getType());
}
use of org.jbox2d.common.Vec2 in project SnapStudio by reportmill.
the class PhysicsRunner method createShape.
/**
* Creates a Box2D shape for given snap shape.
*/
public org.jbox2d.collision.shapes.Shape createShape(Polygon aPoly) {
// If invalid, just return null
if (!aPoly.isSimple() || !aPoly.isConvex() || aPoly.getPointCount() > 8)
return null;
// Create Box2D PolygonShape and return
int pc = aPoly.getPointCount();
Vec2[] vecs = new Vec2[pc];
for (int i = 0; i < pc; i++) vecs[i] = viewToBox(aPoly.getX(i), aPoly.getY(i));
PolygonShape pshape = new PolygonShape();
pshape.set(vecs, vecs.length);
return pshape;
}
use of org.jbox2d.common.Vec2 in project SnapStudio by reportmill.
the class PhysicsRunner method updateBody.
/**
* Updates a body from a view.
*/
public void updateBody(View aView) {
// Get ViewPhysics and body
ViewPhysics<Body> phys = aView.getPhysics();
if (phys == null || phys.isDynamic() || phys.isJoint())
return;
Body body = phys.getNative();
// Get/set position
Vec2 pos0 = body.getPosition();
Vec2 pos1 = viewToBox(aView.getMidX(), aView.getMidY());
double vx = (pos1.x - pos0.x) * 25;
double vy = (pos1.y - pos0.y) * 25;
body.setLinearVelocity(new Vec2((float) vx, (float) vy));
// Get/set rotation
double rot0 = body.getAngle();
double rot1 = Math.toRadians(-aView.getRotate());
double dr = rot1 - rot0;
if (dr > Math.PI || dr < -Math.PI)
dr = MathUtils.mod(dr + Math.PI, Math.PI * 2) - Math.PI;
body.setAngularVelocity((float) dr * 25);
}
use of org.jbox2d.common.Vec2 in project SnapStudio by reportmill.
the class PhysicsRunner method updateDrag.
/**
* Updates drag view's body.
*/
void updateDrag(View aView, double dragX, double dragY) {
ViewPhysics<Body> phys = aView.getPhysics();
Body body = phys.getNative();
Vec2 pos0 = body.getPosition();
Vec2 pos1 = viewToBox(dragX, dragY);
double dx = pos1.x - pos0.x;
double dy = pos1.y - pos0.y;
double vx = (pos1.x - pos0.x) * 25;
double vy = (pos1.y - pos0.y) * 25;
body.setLinearVelocity(new Vec2((float) vx, (float) vy));
}
use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class WorldRayCastWrapper method drawDebugData.
/**
* Call this to draw shapes and other debug draw data.
*/
public void drawDebugData() {
if (m_debugDraw == null) {
return;
}
int flags = m_debugDraw.getFlags();
boolean wireframe = (flags & DebugDraw.e_wireframeDrawingBit) != 0;
if ((flags & DebugDraw.e_shapeBit) != 0) {
for (Body b = m_bodyList; b != null; b = b.getNext()) {
xf.set(b.getTransform());
for (Fixture f = b.getFixtureList(); f != null; f = f.getNext()) {
if (b.isActive() == false) {
color.set(0.5f, 0.5f, 0.3f);
drawShape(f, xf, color, wireframe);
} else if (b.getType() == BodyType.STATIC) {
color.set(0.5f, 0.9f, 0.3f);
drawShape(f, xf, color, wireframe);
} else if (b.getType() == BodyType.KINEMATIC) {
color.set(0.5f, 0.5f, 0.9f);
drawShape(f, xf, color, wireframe);
} else if (b.isAwake() == false) {
color.set(0.5f, 0.5f, 0.5f);
drawShape(f, xf, color, wireframe);
} else {
color.set(0.9f, 0.7f, 0.7f);
drawShape(f, xf, color, wireframe);
}
}
}
drawParticleSystem(m_particleSystem);
}
if ((flags & DebugDraw.e_jointBit) != 0) {
for (Joint j = m_jointList; j != null; j = j.getNext()) {
drawJoint(j);
}
}
if ((flags & DebugDraw.e_pairBit) != 0) {
color.set(0.3f, 0.9f, 0.9f);
for (Contact c = m_contactManager.m_contactList; c != null; c = c.getNext()) {
Fixture fixtureA = c.getFixtureA();
Fixture fixtureB = c.getFixtureB();
fixtureA.getAABB(c.getChildIndexA()).getCenterToOut(cA);
fixtureB.getAABB(c.getChildIndexB()).getCenterToOut(cB);
m_debugDraw.drawSegment(cA, cB, color);
}
}
if ((flags & DebugDraw.e_aabbBit) != 0) {
color.set(0.9f, 0.3f, 0.9f);
for (Body b = m_bodyList; b != null; b = b.getNext()) {
if (b.isActive() == false) {
continue;
}
for (Fixture f = b.getFixtureList(); f != null; f = f.getNext()) {
for (int i = 0; i < f.m_proxyCount; ++i) {
FixtureProxy proxy = f.m_proxies[i];
AABB aabb = m_contactManager.m_broadPhase.getFatAABB(proxy.proxyId);
if (aabb != null) {
Vec2[] vs = avs.get(4);
vs[0].set(aabb.lowerBound.x, aabb.lowerBound.y);
vs[1].set(aabb.upperBound.x, aabb.lowerBound.y);
vs[2].set(aabb.upperBound.x, aabb.upperBound.y);
vs[3].set(aabb.lowerBound.x, aabb.upperBound.y);
m_debugDraw.drawPolygon(vs, 4, color);
}
}
}
}
}
if ((flags & DebugDraw.e_centerOfMassBit) != 0) {
for (Body b = m_bodyList; b != null; b = b.getNext()) {
xf.set(b.getTransform());
xf.p.set(b.getWorldCenter());
m_debugDraw.drawTransform(xf);
}
}
if ((flags & DebugDraw.e_dynamicTreeBit) != 0) {
m_contactManager.m_broadPhase.drawTree(m_debugDraw);
}
m_debugDraw.flush();
}
Aggregations