List of usage examples for com.badlogic.gdx.physics.box2d Transform getPosition
public Vector2 getPosition()
From source file:com.altportalgames.colorrain.utils.Box2DDebugRenderer.java
License:Apache License
private void drawJoint(Joint joint) { Body bodyA = joint.getBodyA();/* ww w. j av a 2s. c o m*/ Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint) joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
From source file:com.blindtigergames.werescrewed.debug.SBox2DDebugRenderer.java
License:Apache License
private void drawAABB(Fixture fixture, Transform transform) { if (fixture.getType() == Type.Circle) { CircleShape shape = (CircleShape) fixture.getShape(); float radius = shape.getRadius(); vertices[0].set(shape.getPosition()); vertices[0].rotate(transform.getRotation()).add(transform.getPosition()); lower.set(vertices[0].x - radius, vertices[0].y - radius); upper.set(vertices[0].x + radius, vertices[0].y + radius); // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); drawSolidPolygon(vertices, 4, AABB_COLOR); } else if (fixture.getType() == Type.Polygon) { PolygonShape shape = (PolygonShape) fixture.getShape(); int vertexCount = shape.getVertexCount(); shape.getVertex(0, vertices[0]); lower.set(transform.mul(vertices[0])); upper.set(lower);/* w w w . ja v a2 s .co m*/ for (int i = 1; i < vertexCount; i++) { shape.getVertex(i, vertices[i]); transform.mul(vertices[i]); lower.x = Math.min(lower.x, vertices[i].x); lower.y = Math.min(lower.y, vertices[i].y); upper.x = Math.max(upper.x, vertices[i].x); upper.y = Math.max(upper.y, vertices[i].y); } // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); drawSolidPolygon(vertices, 4, AABB_COLOR); } }
From source file:com.blindtigergames.werescrewed.debug.SBox2DDebugRenderer.java
License:Apache License
private void drawJoint(Joint joint) { Body bodyA = joint.getBodyA();//from w ww .j a v a2 s . com Body bodyB = joint.getBodyB(); Transform xf1 = bodyA.getTransform(); Transform xf2 = bodyB.getTransform(); Vector2 x1 = xf1.getPosition(); Vector2 x2 = xf2.getPosition(); Vector2 p1 = joint.getAnchorA(); Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { drawSegment(p1, p2, JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { PulleyJoint pulley = (PulleyJoint) joint; Vector2 s1 = pulley.getGroundAnchorA(); Vector2 s2 = pulley.getGroundAnchorB(); drawSegment(s1, p1, JOINT_COLOR); drawSegment(s2, p2, JOINT_COLOR); drawSegment(s1, s2, JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR); } else { drawSegment(x1, p1, JOINT_COLOR); drawSegment(p1, p2, JOINT_COLOR); drawSegment(x2, p2, JOINT_COLOR); } }
From source file:com.me.mygdxgame.Entities.MydebugRenderer.java
License:Apache License
private void drawAABB(Fixture fixture, Transform transform) { if (fixture.getType() == Type.Circle) { CircleShape shape = (CircleShape) fixture.getShape(); float radius = shape.getRadius(); vertices[0].set(shape.getPosition()); vertices[0].rotate(transform.getRotation()).add(transform.getPosition()); lower.set(vertices[0].x - radius, vertices[0].y - radius); upper.set(vertices[0].x + radius, vertices[0].y + radius); // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); drawSolidPolygon(vertices, 4, AABB_COLOR, true); } else if (fixture.getType() == Type.Polygon) { PolygonShape shape = (PolygonShape) fixture.getShape(); int vertexCount = shape.getVertexCount(); shape.getVertex(0, vertices[0]); lower.set(transform.mul(vertices[0])); upper.set(lower);/* w w w.j ava2s. co m*/ for (int i = 1; i < vertexCount; i++) { shape.getVertex(i, vertices[i]); transform.mul(vertices[i]); lower.x = Math.min(lower.x, vertices[i].x); lower.y = Math.min(lower.y, vertices[i].y); upper.x = Math.max(upper.x, vertices[i].x); upper.y = Math.max(upper.y, vertices[i].y); } // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); drawSolidPolygon(vertices, 4, AABB_COLOR, true); } }
From source file:org.box2d.r3.gdx.GDXBox2DDebugRenderer.java
License:Apache License
private void drawAABB(final Fixture fixture, final Transform transform) { if (fixture.getType() == Type.Circle) { final CircleShape shape = (CircleShape) fixture.getShape(); final float radius = shape.getRadius(); vertices[0].set(shape.getPosition()); vertices[0].rotate(transform.getRotation()).add(transform.getPosition()); lower.set(vertices[0].x - radius, vertices[0].y - radius); upper.set(vertices[0].x + radius, vertices[0].y + radius); // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); this.drawSolidPolygon(vertices, 4, this.AABB_COLOR, true); } else if (fixture.getType() == Type.Polygon) { final PolygonShape shape = (PolygonShape) fixture.getShape(); final int vertexCount = shape.getVertexCount(); shape.getVertex(0, vertices[0]); lower.set(transform.mul(vertices[0])); upper.set(lower);//ww w .ja v a 2s .c om for (int i = 1; i < vertexCount; i++) { shape.getVertex(i, vertices[i]); transform.mul(vertices[i]); lower.x = Math.min(lower.x, vertices[i].x); lower.y = Math.min(lower.y, vertices[i].y); upper.x = Math.max(upper.x, vertices[i].x); upper.y = Math.max(upper.y, vertices[i].y); } // define vertices in ccw fashion... vertices[0].set(lower.x, lower.y); vertices[1].set(upper.x, lower.y); vertices[2].set(upper.x, upper.y); vertices[3].set(lower.x, upper.y); this.drawSolidPolygon(vertices, 4, this.AABB_COLOR, true); } }
From source file:org.box2d.r3.gdx.GDXBox2DDebugRenderer.java
License:Apache License
private void drawJoint(final Joint joint) { final Body bodyA = joint.getBodyA(); final Body bodyB = joint.getBodyB(); final Transform xf1 = bodyA.getTransform(); final Transform xf2 = bodyB.getTransform(); final Vector2 x1 = xf1.getPosition(); final Vector2 x2 = xf2.getPosition(); final Vector2 p1 = joint.getAnchorA(); final Vector2 p2 = joint.getAnchorB(); if (joint.getType() == JointType.DistanceJoint) { this.drawSegment(p1, p2, this.JOINT_COLOR); } else if (joint.getType() == JointType.PulleyJoint) { final PulleyJoint pulley = (PulleyJoint) joint; final Vector2 s1 = pulley.getGroundAnchorA(); final Vector2 s2 = pulley.getGroundAnchorB(); this.drawSegment(s1, p1, this.JOINT_COLOR); this.drawSegment(s2, p2, this.JOINT_COLOR); this.drawSegment(s1, s2, this.JOINT_COLOR); } else if (joint.getType() == JointType.MouseJoint) { this.drawSegment(joint.getAnchorA(), joint.getAnchorB(), this.JOINT_COLOR); } else {/*from w w w .j av a 2 s .co m*/ this.drawSegment(x1, p1, this.JOINT_COLOR); this.drawSegment(p1, p2, this.JOINT_COLOR); this.drawSegment(x2, p2, this.JOINT_COLOR); } }
From source file:org.catrobat.catroid.physics.PhysicsObject.java
License:Open Source License
private void calculateAabb(Fixture fixture, Transform transform) { fixtureAabbLowerLeft = new Vector2(Integer.MAX_VALUE, Integer.MAX_VALUE); fixtureAabbUpperRight = new Vector2(Integer.MIN_VALUE, Integer.MIN_VALUE); if (fixture.getType() == Shape.Type.Circle) { CircleShape shape = (CircleShape) fixture.getShape(); float radius = shape.getRadius(); tmpVertice.set(shape.getPosition()); tmpVertice.rotate(transform.getRotation()).add(transform.getPosition()); fixtureAabbLowerLeft.set(tmpVertice.x - radius, tmpVertice.y - radius); fixtureAabbUpperRight.set(tmpVertice.x + radius, tmpVertice.y + radius); } else if (fixture.getType() == Shape.Type.Polygon) { PolygonShape shape = (PolygonShape) fixture.getShape(); int vertexCount = shape.getVertexCount(); shape.getVertex(0, tmpVertice);// w w w. j a va2 s .c o m fixtureAabbLowerLeft.set(transform.mul(tmpVertice)); fixtureAabbUpperRight.set(fixtureAabbLowerLeft); for (int i = 1; i < vertexCount; i++) { shape.getVertex(i, tmpVertice); transform.mul(tmpVertice); fixtureAabbLowerLeft.x = Math.min(fixtureAabbLowerLeft.x, tmpVertice.x); fixtureAabbLowerLeft.y = Math.min(fixtureAabbLowerLeft.y, tmpVertice.y); fixtureAabbUpperRight.x = Math.max(fixtureAabbUpperRight.x, tmpVertice.x); fixtureAabbUpperRight.y = Math.max(fixtureAabbUpperRight.y, tmpVertice.y); } } bodyAabbLowerLeft.x = Math.min(fixtureAabbLowerLeft.x, bodyAabbLowerLeft.x); bodyAabbLowerLeft.y = Math.min(fixtureAabbLowerLeft.y, bodyAabbLowerLeft.y); bodyAabbUpperRight.x = Math.max(fixtureAabbUpperRight.x, bodyAabbUpperRight.x); bodyAabbUpperRight.y = Math.max(fixtureAabbUpperRight.y, bodyAabbUpperRight.y); }