From bfc8e96b46e0ca94e29edfa3212b115d5ab48516 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 1 Jan 2014 10:31:48 -0500 Subject: [PATCH] add ramp collision shape --- .../tilemap3d/tilemesh/CollisionShapes.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/ca/blarg/gdx/tilemap3d/tilemesh/CollisionShapes.java b/src/main/java/ca/blarg/gdx/tilemap3d/tilemesh/CollisionShapes.java index b85dbaa..34e3d47 100644 --- a/src/main/java/ca/blarg/gdx/tilemap3d/tilemesh/CollisionShapes.java +++ b/src/main/java/ca/blarg/gdx/tilemap3d/tilemesh/CollisionShapes.java @@ -24,6 +24,8 @@ public class CollisionShapes { shapes.put("box-1x2x1", buildBox(-0.5f, -0.5f, -0.5f, 0.5f, 1.5f, 0.5f)); shapes.put("box-0.7x2x0.7", buildBox(-0.35f, -0.5f, -0.35f, 0.35f, 1.5f, 0.35f)); + + shapes.put("ramp-1x1x1", buildRamp(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f)); } public static Model get(String shapeName) { @@ -37,6 +39,13 @@ public class CollisionShapes { return modelBuilder.end(); } + private static Model buildRamp(float ax, float ay, float az, float bx, float by, float bz) { + modelBuilder.begin(); + MeshPartBuilder partBuilder = modelBuilder.part("collisionShape", GL10.GL_TRIANGLES, VertexAttributes.Usage.Position, null); + addRampShape(partBuilder, ax, ay, az, bx, by, bz); + return modelBuilder.end(); + } + private static void addBoxShape(MeshPartBuilder partBuilder, float ax, float ay, float az, float bx, float by, float bz) { // TODO: for some reason, ModelBuilder's createBox() creates a box model in a way that BaseModelTileMesh // collects the vertices from it incorrectly. for now, we just manually create a box's vertices/indices ourself @@ -74,4 +83,32 @@ public class CollisionShapes { partBuilder.index((short)4, (short)6, (short)1); partBuilder.index((short)6, (short)3, (short)1); } + + private static void addRampShape(MeshPartBuilder partBuilder, float ax, float ay, float az, float bx, float by, float bz) { + partBuilder.vertex(ax, by, az); + partBuilder.vertex(bx, by, az); + partBuilder.vertex(bx, ay, bz); + partBuilder.vertex(ax, ay, bz); + partBuilder.vertex(bx, ay, az); + partBuilder.vertex(ax, ay, az); + + // top (ramp) + partBuilder.index((short)3, (short)2, (short)0); + partBuilder.index((short)2, (short)1, (short)0); + + // bottom + partBuilder.index((short)2, (short)3, (short)4); + partBuilder.index((short)3, (short)5, (short)4); + + // front + partBuilder.index((short)4, (short)5, (short)1); + partBuilder.index((short)5, (short)0, (short)1); + + // left + partBuilder.index((short)5, (short)3, (short)0); + + // right + partBuilder.index((short)4, (short)1, (short)2); + + } }