@@ 0,0 1,109 @@
+package net.dermetfan.someLibgdxTests.screens;
+
+import java.util.Arrays;
+
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
+import com.badlogic.gdx.math.Circle;
+import com.badlogic.gdx.math.Polygon;
+import com.badlogic.gdx.math.Polyline;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.physics.box2d.Body;
+import com.badlogic.gdx.physics.box2d.BodyDef;
+import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
+import com.badlogic.gdx.physics.box2d.ChainShape;
+import com.badlogic.gdx.physics.box2d.CircleShape;
+import com.badlogic.gdx.physics.box2d.EdgeShape;
+import com.badlogic.gdx.physics.box2d.Fixture;
+import com.badlogic.gdx.physics.box2d.PolygonShape;
+import com.badlogic.gdx.utils.viewport.ScreenViewport;
+import net.dermetfan.gdx.math.GeometryUtils;
+import net.dermetfan.gdx.physics.box2d.Box2DUtils;
+
+public class Box2DAsTest extends Box2DScreen {
+
+ ShapeRenderer sr = new ShapeRenderer();
+ Fixture polygon, edge, chain, circle;
+
+ public Box2DAsTest() {
+ ((ScreenViewport) viewport).setUnitsPerPixel(1 / (32f * 2));
+
+ BodyDef bodyDef = new BodyDef();
+ bodyDef.type = BodyType.KinematicBody;
+ bodyDef.angularVelocity = 2;
+ Body body = world.createBody(bodyDef);
+
+ {
+ PolygonShape shape = new PolygonShape();
+ shape.set(new float[] {-1, -1, 0, -1, 1, 1, -1, 1});
+ polygon = body.createFixture(shape, 1);
+ }
+
+ {
+ EdgeShape shape = new EdgeShape();
+ shape.set(0, 3, 3, 3);
+ edge = body.createFixture(shape, 1);
+ }
+
+ {
+ ChainShape shape = new ChainShape();
+ shape.createChain(new float[] {0, 3, .5f, 3.5f, 1, 3, 1.5f, 3.5f});
+ chain = body.createFixture(shape, 1);
+ }
+
+ {
+ CircleShape shape = new CircleShape();
+ shape.setRadius(1);
+ shape.setPosition(new Vector2(3, 1));
+ circle = body.createFixture(shape, .5f);
+ }
+ }
+
+ @Override
+ public void resize(int width, int height) {
+ super.resize(width, height);
+ }
+
+ Polygon pGon = new Polygon(new float[12]);
+ Polyline pLine = new Polyline(new float[8]);
+ Circle c = new Circle();
+
+ @Override
+ public void render(float delta) {
+ super.render(delta);
+
+ sr.setProjectionMatrix(viewport.getCamera().combined);
+ sr.begin(ShapeType.Line);
+
+ Box2DUtils.as(polygon, pGon);
+ sr.setColor(Color.RED);
+ sr.polygon(pGon.getTransformedVertices());
+
+ Box2DUtils.as(circle, c);
+ sr.setColor(Color.WHITE);
+ sr.circle(c.x, c.y, c.radius, 15);
+
+ GeometryUtils.reset(pLine);
+ pLine = Box2DUtils.as(edge, pLine);
+ sr.setColor(Color.CYAN);
+ sr.polyline(pLine.getTransformedVertices());
+ System.out.println(Arrays.toString(pLine.getVertices()));
+ System.out.println(Arrays.toString(pLine.getTransformedVertices()));
+ System.out.println();
+
+ GeometryUtils.reset(pLine);
+ pLine = Box2DUtils.as(chain, pLine);
+ sr.setColor(Color.GREEN);
+ sr.polyline(pLine.getTransformedVertices());
+
+ sr.end();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ sr.dispose();
+ }
+
+}
@@ 155,6 155,7 @@ public class Menu extends ScreenAdapter
names.add("Box2DControllerTest");
names.add("MinimumTranslationVectorTest");
names.add("SutherlandHodgmanTest");
names.add("Box2DAsTest");
names.sort();
final List<String> tests = new List<>(skin);