OSDN Git Service

fixed up weak refs in bullet swig wrapper, added modified base bullet test, doesn...
authorbadlogic <badlogicgames@gmail.com>
Mon, 30 Sep 2013 00:10:20 +0000 (02:10 +0200)
committerbadlogic <badlogicgames@gmail.com>
Mon, 30 Sep 2013 00:10:20 +0000 (02:10 +0200)
extensions/gdx-bullet/jni/build-ios32.xml
extensions/gdx-bullet/jni/swig-src/gdxBullet_wrap.cpp
tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/BasicBulletTest.java [new file with mode: 0644]
tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/IOSRobovmTests.java
tests/gdx-tests/src/com/badlogic/gdx/tests/bullet/BaseBulletTest.java

index 9b20e78..ddfb1fa 100755 (executable)
        <property name="gcc-opts" value="-c -Wall -O2 -miphoneos-version-min=5.1"/>\r
        <fileset id="gcc-files" dir="./">\r
                <exclude name="target/"/>               \r
-                               <include name="memcpy_wrap.c"/>
-               <include name="**/*.c"/>
+                               <include name="memcpy_wrap.c"/>\r
+               <include name="**/*.c"/>\r
 \r
-                               <exclude name="src/bullet/BulletMultiThreaded/GpuSoftBodySolvers/**"/>
+                               <exclude name="src/bullet/BulletMultiThreaded/GpuSoftBodySolvers/**"/>\r
 \r
        </fileset>\r
        \r
        <!-- define g++ compiler, options and files to compile -->\r
        <property name="g++" value="${compilerPrefix}g++"/>\r
-       <property name="g++-opts" value="-c -Wall -O2 -miphoneos-version-min=5.1 -fno-strict-aliasing -fno-rtti -DBT_NO_PROFILE"/>\r
+       <property name="g++-opts" value="-g -c -Wall -O2 -miphoneos-version-min=5.1 -fno-strict-aliasing -fno-rtti -DBT_NO_PROFILE"/>\r
        <fileset id="g++-files" dir="./">\r
                <exclude name="target/"/>\r
-                               <include name="**/*.cpp"/>
+                               <include name="**/*.cpp"/>\r
 \r
-                               <exclude name="src/bullet/BulletMultiThreaded/GpuSoftBodySolvers/**"/>
+                               <exclude name="src/bullet/BulletMultiThreaded/GpuSoftBodySolvers/**"/>\r
 \r
        </fileset>\r
 \r
@@ -82,9 +82,9 @@
                        <arg value="-Ijni-headers"/>\r
                        <arg value="-Ijni-headers/${jniPlatform}"/>\r
                        <arg value="-I."/>\r
-                                               <arg value="-Isrc/bullet/"/>
-                       <arg value="-Isrc/custom/"/>
-                       <arg value="-Isrc/extras/Serialize/"/>
+                                               <arg value="-Isrc/bullet/"/>\r
+                       <arg value="-Isrc/custom/"/>\r
+                       <arg value="-Isrc/extras/Serialize/"/>\r
 \r
                        <srcfile/>\r
                        <arg value="-o"/>\r
                        <arg value="-Ijni-headers"/>\r
                        <arg value="-Ijni-headers/${jniPlatform}"/>\r
                        <arg value="-I."/>\r
-                                               <arg value="-Isrc/bullet/"/>
-                       <arg value="-Isrc/custom/"/>
-                       <arg value="-Isrc/extras/Serialize/"/>
+                                               <arg value="-Isrc/bullet/"/>\r
+                       <arg value="-Isrc/custom/"/>\r
+                       <arg value="-Isrc/extras/Serialize/"/>\r
 \r
                        <srcfile/>\r
                        <arg value="-o"/>\r
                        <arg value="-Ijni-headers"/>\r
                        <arg value="-Ijni-headers/${jniPlatform}"/>\r
                        <arg value="-I."/>\r
-                                               <arg value="-Isrc/bullet/"/>
-                       <arg value="-Isrc/custom/"/>
-                       <arg value="-Isrc/extras/Serialize/"/>
+                                               <arg value="-Isrc/bullet/"/>\r
+                       <arg value="-Isrc/custom/"/>\r
+                       <arg value="-Isrc/extras/Serialize/"/>\r
 \r
                        <srcfile/>\r
                        <arg value="-o"/>\r
                        <arg value="-Ijni-headers"/>\r
                        <arg value="-Ijni-headers/${jniPlatform}"/>\r
                        <arg value="-I."/>\r
-                                               <arg value="-Isrc/bullet/"/>
-                       <arg value="-Isrc/custom/"/>
-                       <arg value="-Isrc/extras/Serialize/"/>
+                                               <arg value="-Isrc/bullet/"/>\r
+                       <arg value="-Isrc/custom/"/>\r
+                       <arg value="-Isrc/extras/Serialize/"/>\r
 \r
                        <srcfile/>\r
                        <arg value="-o"/>\r
index 7ddaa29..4830837 100755 (executable)
@@ -238,6 +238,7 @@ namespace Swig {
 \r
     bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) {\r
       if (!jthis_) {\r
+          weak_global = false;\r
         weak_global_ = weak_global || !mem_own; // hold as weak global if explicitly requested or not owned\r
         if (jobj)\r
           jthis_ = weak_global_ ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj);\r
diff --git a/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/BasicBulletTest.java b/tests/gdx-tests-iosrobovm/src/com/badlogic/gdx/tests/BasicBulletTest.java
new file mode 100644 (file)
index 0000000..3b3353a
--- /dev/null
@@ -0,0 +1,190 @@
+package com.badlogic.gdx.tests;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.Color;
+import com.badlogic.gdx.graphics.GL10;
+import com.badlogic.gdx.graphics.PerspectiveCamera;
+import com.badlogic.gdx.graphics.VertexAttributes.Usage;
+import com.badlogic.gdx.graphics.g3d.Environment;
+import com.badlogic.gdx.graphics.g3d.Material;
+import com.badlogic.gdx.graphics.g3d.Model;
+import com.badlogic.gdx.graphics.g3d.ModelBatch;
+import com.badlogic.gdx.graphics.g3d.ModelInstance;
+import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
+import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
+import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
+import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
+import com.badlogic.gdx.math.MathUtils;
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.physics.bullet.btBoxShape;
+import com.badlogic.gdx.physics.bullet.btBroadphaseInterface;
+import com.badlogic.gdx.physics.bullet.btCollisionConfiguration;
+import com.badlogic.gdx.physics.bullet.btCollisionDispatcher;
+import com.badlogic.gdx.physics.bullet.btCollisionShape;
+import com.badlogic.gdx.physics.bullet.btConstraintSolver;
+import com.badlogic.gdx.physics.bullet.btDbvtBroadphase;
+import com.badlogic.gdx.physics.bullet.btDefaultCollisionConfiguration;
+import com.badlogic.gdx.physics.bullet.btDefaultMotionState;
+import com.badlogic.gdx.physics.bullet.btDiscreteDynamicsWorld;
+import com.badlogic.gdx.physics.bullet.btDynamicsWorld;
+import com.badlogic.gdx.physics.bullet.btRigidBody;
+import com.badlogic.gdx.physics.bullet.btRigidBodyConstructionInfo;
+import com.badlogic.gdx.physics.bullet.btSequentialImpulseConstraintSolver;
+import com.badlogic.gdx.physics.bullet.btSphereShape;
+import com.badlogic.gdx.tests.bullet.BaseBulletTest;
+import com.badlogic.gdx.tests.bullet.BulletTest;
+import com.badlogic.gdx.utils.Array;
+
+/** @author xoppa */
+public class BasicBulletTest extends BulletTest {
+       ModelBatch modelBatch;
+       Environment lights;
+       ModelBuilder modelBuilder = new ModelBuilder();
+       
+       btCollisionConfiguration collisionConfiguration;
+       btCollisionDispatcher dispatcher;
+       btBroadphaseInterface broadphase;
+       btConstraintSolver solver;
+       btDynamicsWorld collisionWorld;
+       Vector3 gravity = new Vector3(0, -9.81f, 0);
+       Vector3 tempVector = new Vector3();
+
+       Array<Model> models = new Array<Model>();
+       Array<ModelInstance> instances = new Array<ModelInstance>();
+       Array<btDefaultMotionState> motionStates = new Array<btDefaultMotionState>();
+       Array<btRigidBodyConstructionInfo> bodyInfos = new Array<btRigidBodyConstructionInfo>();
+       Array<btCollisionShape> shapes = new Array<btCollisionShape>();
+       Array<btRigidBody> bodies = new Array<btRigidBody>();   
+
+       @Override
+       public void create () {
+               super.create();
+               instructions = "Swipe for next test";
+               
+               lights = new Environment();
+               lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.2f, 0.2f, 0.2f, 1.f));
+               lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1f, -0.7f));
+               
+               // Set up the camera
+               final float width = Gdx.graphics.getWidth();
+               final float height = Gdx.graphics.getHeight();
+               if (width > height)
+                       camera = new PerspectiveCamera(67f, 3f * width / height, 3f);
+               else
+                       camera = new PerspectiveCamera(67f, 3f, 3f * height / width);
+               camera.position.set(10f, 10f, 10f);
+               camera.lookAt(0, 0, 0);
+               camera.update();
+               // Create the model batch
+               modelBatch = new ModelBatch();
+               // Create some basic models
+               final Model groundModel = modelBuilder.createRect(20f, 0f, -20f, -20f, 0f, -20f, -20f, 0f, 20f, 20f, 0f, 20f, 0, 1, 0, 
+                       new Material(ColorAttribute.createDiffuse(Color.BLUE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)),
+                       Usage.Position | Usage.Normal);
+               models.add(groundModel);
+               final Model sphereModel = modelBuilder.createSphere(1f, 1f, 1f, 10, 10,
+                       new Material(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), 
+                       Usage.Position | Usage.Normal);
+               models.add(sphereModel);
+               // Load the bullet library
+               BaseBulletTest.init(); // Normally use: Bullet.init();
+               // Create the bullet world
+               collisionConfiguration = new btDefaultCollisionConfiguration();
+               dispatcher = new btCollisionDispatcher(collisionConfiguration);
+               broadphase = new btDbvtBroadphase();
+               solver = new btSequentialImpulseConstraintSolver();
+               collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
+               collisionWorld.setGravity(gravity);
+               // Create the shapes and body construction infos
+               btCollisionShape groundShape = new btBoxShape(tempVector.set(20, 0, 20));
+               shapes.add(groundShape);
+               btRigidBodyConstructionInfo groundInfo = new btRigidBodyConstructionInfo(0f, null, groundShape, Vector3.Zero);
+               bodyInfos.add(groundInfo);
+               btCollisionShape sphereShape = new btSphereShape(0.5f);
+               shapes.add(sphereShape);
+               sphereShape.calculateLocalInertia(1f, tempVector);
+               btRigidBodyConstructionInfo sphereInfo = new btRigidBodyConstructionInfo(1f, null, sphereShape, tempVector);
+               bodyInfos.add(sphereInfo);
+               // Create the ground
+               ModelInstance ground = new ModelInstance(groundModel);
+               instances.add(ground);
+               btDefaultMotionState groundMotionState = new btDefaultMotionState();
+               groundMotionState.setWorldTransform(ground.transform);
+               motionStates.add(groundMotionState);
+               btRigidBody groundBody = new btRigidBody(groundInfo);
+               groundBody.setMotionState(groundMotionState);
+               bodies.add(groundBody);
+               collisionWorld.addRigidBody(groundBody);
+               // Create the spheres
+               for (float x = -10f; x <= 10f; x += 2f) {
+                       for (float y = 5f; y <= 15f; y += 2f) {
+                               for (float z = 0f; z <= 0f; z+= 2f) {
+                                       ModelInstance sphere = new ModelInstance(sphereModel);
+                                       instances.add(sphere);
+                                       sphere.transform.trn(x+0.1f*MathUtils.random(), y+0.1f*MathUtils.random(), z+0.1f*MathUtils.random());
+                                       btDefaultMotionState sphereMotionState = new btDefaultMotionState();
+                                       sphereMotionState.setWorldTransform(sphere.transform);
+                                       motionStates.add(sphereMotionState);
+                                       btRigidBody sphereBody = new btRigidBody(sphereInfo);
+                                       sphereBody.setMotionState(sphereMotionState);
+                                       bodies.add(sphereBody);
+                                       collisionWorld.addRigidBody(sphereBody);
+                               }
+                       }
+               }
+       }
+       
+       @Override
+       public void render () {
+               Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+               Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+               
+               fpsCounter.put(Gdx.graphics.getFramesPerSecond());
+               
+               performanceCounter.tick();
+               performanceCounter.start();
+               ((btDynamicsWorld)collisionWorld).stepSimulation(Gdx.graphics.getDeltaTime(), 5);
+               performanceCounter.stop();
+               
+               int c = motionStates.size;
+               for (int i = 0; i < c; i++) {
+                       motionStates.get(i).getWorldTransform(instances.get(i).transform);
+               }
+               
+               modelBatch.begin(camera);
+               modelBatch.render(instances, lights);
+               modelBatch.end();
+               
+               performance.setLength(0);
+               performance.append("FPS: ").append(fpsCounter.value).append(", Bullet: ")
+                       .append((int)(performanceCounter.load.value*100f)).append("%");
+       }
+       
+       @Override
+       public void dispose () {
+               collisionWorld.dispose();
+               solver.dispose();
+               broadphase.dispose();
+               dispatcher.dispose();
+               collisionConfiguration.dispose();
+               
+               for (btRigidBody body : bodies)
+                       body.dispose();
+               bodies.clear();
+               for (btDefaultMotionState motionState : motionStates)
+                       motionState.dispose();
+               motionStates.clear();
+               for (btCollisionShape shape : shapes)
+                       shape.dispose();
+               shapes.clear();
+               for (btRigidBodyConstructionInfo info : bodyInfos)
+                       info.dispose();
+               bodyInfos.clear();
+               
+               modelBatch.dispose();
+               instances.clear();
+               for (Model model : models)
+                       model.dispose();
+               models.clear();
+       }
+}
\ No newline at end of file
index 46b4056..d1fa9ac 100644 (file)
@@ -14,7 +14,7 @@ public class IOSRobovmTests extends IOSApplication.Delegate {
        @Override
        protected IOSApplication createApplication() {
                IOSApplicationConfiguration config = new IOSApplicationConfiguration();
-               return new IOSApplication(new PingPongSocketExample(), config);
+               return new IOSApplication(new BulletTestCollection(), config);
        }
 
        public static void main(String[] argv) {
index 32a7465..16f20d1 100644 (file)
@@ -72,7 +72,7 @@ public class BaseBulletTest extends BulletTest {
        }
        
        public Environment lights;
-       public DirectionalShadowLight shadowLight;
+       public DirectionalLight shadowLight;
        public ModelBatch shadowBatch;
 
        public BulletWorld world;
@@ -92,9 +92,9 @@ public class BaseBulletTest extends BulletTest {
                lights = new Environment();
                lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
                lights.add(
-                       (shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f)
+                       (shadowLight = new DirectionalLight()).set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f)
                );
-               lights.shadowMap = shadowLight;
+//             lights.shadowMap = shadowLight;
                shadowBatch = new ModelBatch(new DepthShaderProvider());
                
                modelBatch = new ModelBatch();
@@ -143,7 +143,7 @@ public class BaseBulletTest extends BulletTest {
                shadowBatch.dispose();
                shadowBatch = null;
                
-               shadowLight.dispose();
+//             shadowLight.dispose();
                shadowLight = null;
                
                super.dispose();
@@ -182,11 +182,11 @@ public class BaseBulletTest extends BulletTest {
        }
        
        protected void renderWorld() {
-               shadowLight.begin(Vector3.Zero, camera.direction);
-               shadowBatch.begin(shadowLight.getCamera());
-               world.render(shadowBatch, null);
-               shadowBatch.end();
-               shadowLight.end();
+//             shadowLight.begin(Vector3.Zero, camera.direction);
+//             shadowBatch.begin(shadowLight.getCamera());
+//             world.render(shadowBatch, null);
+//             shadowBatch.end();
+//             shadowLight.end();
                
                modelBatch.begin(camera);
                world.render(modelBatch, lights);