Created
November 4, 2012 09:26
-
-
Save nazgee/4011051 to your computer and use it in GitHub Desktop.
BROKEN-and-OLD GLES2 testing of debug draw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From bf83c5e8e3b656795c85d0c321e72917900937ad Mon Sep 17 00:00:00 2001 | |
From: Michal Stawinski <michal.stawinski@gmail.com> | |
Date: Sun, 4 Nov 2012 09:20:21 +0100 | |
Subject: [PATCH] Testing of OLD-and-BROKEN degbugdraw on GLES2 | |
--- | |
project.properties | 1 + | |
.../examples/PhysicsRevoluteJointExample.java | 75 ++++++++++++++++++++ | |
2 files changed, 76 insertions(+) | |
diff --git a/project.properties b/project.properties | |
index 6218fea..75250c7 100644 | |
--- a/project.properties | |
+++ b/project.properties | |
@@ -21,3 +21,4 @@ android.library.reference.7=../AndEngineMultiplayerExtension | |
android.library.reference.8=../AndEngineLiveWallpaperExtension | |
android.library.reference.9=../AndEngineTMXTiledMapExtension | |
android.library.reference.10=../AndEngineScriptingExtension | |
+android.library.reference.11=../AndEngineDebugDrawExtension | |
diff --git a/src/org/andengine/examples/PhysicsRevoluteJointExample.java b/src/org/andengine/examples/PhysicsRevoluteJointExample.java | |
index 451e8cf..81f5e18 100644 | |
--- a/src/org/andengine/examples/PhysicsRevoluteJointExample.java | |
+++ b/src/org/andengine/examples/PhysicsRevoluteJointExample.java | |
@@ -4,16 +4,22 @@ import org.andengine.engine.options.EngineOptions; | |
import org.andengine.entity.primitive.Line; | |
import org.andengine.entity.scene.Scene; | |
import org.andengine.entity.sprite.AnimatedSprite; | |
+import org.andengine.extension.debugdraw.Box2dDebugRenderer; | |
import org.andengine.extension.physics.box2d.PhysicsConnector; | |
import org.andengine.extension.physics.box2d.PhysicsFactory; | |
+import org.andengine.extension.physics.box2d.util.Vector2Pool; | |
import org.andengine.extension.physics.box2d.util.constants.PhysicsConstants; | |
+import org.andengine.input.touch.TouchEvent; | |
import android.widget.Toast; | |
import com.badlogic.gdx.math.Vector2; | |
import com.badlogic.gdx.physics.box2d.Body; | |
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType; | |
+import com.badlogic.gdx.physics.box2d.CircleShape; | |
import com.badlogic.gdx.physics.box2d.FixtureDef; | |
+import com.badlogic.gdx.physics.box2d.PolygonShape; | |
+import com.badlogic.gdx.physics.box2d.Shape; | |
import com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef; | |
/** | |
@@ -108,6 +114,75 @@ public class PhysicsRevoluteJointExample extends BasePhysicsJointExample { | |
this.mPhysicsWorld.createJoint(revoluteJointDef); | |
} | |
+ Box2dDebugRenderer debug = new Box2dDebugRenderer(mPhysicsWorld, getVertexBufferObjectManager()); | |
+ debug.setZIndex(1000); | |
+ pScene.attachChild(debug); | |
+ } | |
+ | |
+ public static FixtureDef fixFromShape(FixtureDef pOtherFixDef, Shape pShape) { | |
+ FixtureDef f = new FixtureDef(); | |
+ f.shape = pShape; | |
+ f.density = pOtherFixDef.density; | |
+ f.friction = pOtherFixDef.friction; | |
+ f.restitution = pOtherFixDef.restitution; | |
+ f.isSensor = pOtherFixDef.isSensor; | |
+ f.filter.categoryBits = pOtherFixDef.filter.categoryBits; | |
+ f.filter.maskBits = pOtherFixDef.filter.maskBits; | |
+ f.filter.groupIndex = pOtherFixDef.filter.groupIndex; | |
+ return f; | |
+ } | |
+ | |
+ | |
+ @Override | |
+ public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { | |
+ if(this.mPhysicsWorld == null) { | |
+ return false; | |
+ } | |
+ | |
+ if(pSceneTouchEvent.isActionDown()) { | |
+ // Setup | |
+ final float w = 200; | |
+ final float h = 80; | |
+ final float p2m = PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT; | |
+ | |
+ final FixtureDef fixture = PhysicsFactory.createFixtureDef(0.5f, 0.5f, 0.5f); | |
+ final FixtureDef fixtureSensor = PhysicsFactory.createFixtureDef(0.5f, 0.5f, 0.5f); | |
+ fixtureSensor.isSensor = true; | |
+ PolygonShape polyShape = new PolygonShape(); | |
+ CircleShape circleShape = new CircleShape(); | |
+ final Vector2 vecA = Vector2Pool.obtain(0, 0); | |
+ final Vector2 vecB = Vector2Pool.obtain(0, 0); | |
+ | |
+ final float r = h / 2 / p2m; | |
+ final float edge_offset = w / 2 / p2m - r; | |
+ | |
+ // sensor region | |
+ Body body = PhysicsFactory.createBoxBody(mPhysicsWorld, pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 0.90f * w, 0.3f * h, 0, BodyType.DynamicBody, fixtureSensor); | |
+ | |
+ // edges | |
+ circleShape.setRadius(r); | |
+ | |
+ vecA.set(-edge_offset, 0); | |
+ circleShape.setPosition(vecA); | |
+ body.createFixture(fixFromShape(fixture, circleShape)); | |
+ | |
+ vecA.set( edge_offset, 0); | |
+ circleShape.setPosition(vecA); | |
+ body.createFixture(fixFromShape(fixture, circleShape)); | |
+ | |
+ body.setBullet(true); | |
+ body.setLinearDamping(0.3f); | |
+ body.setAngularDamping(0.3f); | |
+ | |
+ // Cleanup | |
+ Vector2Pool.recycle(vecA); | |
+ Vector2Pool.recycle(vecB); | |
+ polyShape.dispose(); | |
+ circleShape.dispose(); | |
+ } | |
+ | |
+ pScene.sortChildren(false); | |
+ return true; | |
} | |
// =========================================================== | |
-- | |
1.7.10.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment