Created
November 4, 2012 09:22
-
-
Save nazgee/4010904 to your computer and use it in GitHub Desktop.
GLES2-AnchorCenter testing of debug draw
This file contains hidden or 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 237f2dd709e710fbe57413d847bd304f463a6a2a Mon Sep 17 00:00:00 2001 | |
From: Michal Stawinski <[email protected]> | |
Date: Sun, 4 Nov 2012 09:20:21 +0100 | |
Subject: [PATCH] Testing of degbugdraw | |
--- | |
project.properties | 1 + | |
.../examples/PhysicsRevoluteJointExample.java | 75 ++++++++++++++++++++ | |
2 files changed, 76 insertions(+) | |
diff --git a/project.properties b/project.properties | |
index ca03a32..3f4a9a5 100644 | |
--- a/project.properties | |
+++ b/project.properties | |
@@ -22,3 +22,4 @@ android.library.reference.8=../AndEngineTMXTiledMapExtension | |
android.library.reference.9=../AndEngineScriptingExtension | |
android.library.reference.10=../AndEngineCocosBuilderExtension | |
android.library.reference.11=../AndEngineCocosBuilderExtensionCCRotatingSpriteExtension | |
+android.library.reference.12=../AndEngineDebugDrawExtension | |
\ No newline at end of file | |
diff --git a/src/org/andengine/examples/PhysicsRevoluteJointExample.java b/src/org/andengine/examples/PhysicsRevoluteJointExample.java | |
index 62eca49..cbedb1d 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.DebugRenderer; | |
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; | |
/** | |
@@ -102,6 +108,75 @@ public class PhysicsRevoluteJointExample extends BasePhysicsJointExample { | |
this.mPhysicsWorld.createJoint(revoluteJointDef); | |
} | |
+ DebugRenderer debug = new DebugRenderer(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 = 100; | |
+ final float h = 20; | |
+ 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