From 976afae4905f086d0887d8184945a204ca6f0696 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 3 Jan 2022 23:52:12 +0100 Subject: [PATCH] [DEV] remove dependency of ephysic --- .../CollisionTestApplication.java | 77 ++----- .../Log.java | 2 +- .../LoxelApplicationPerso.java | 60 +++-- .../MainLoxelEnginePerso.java | 2 +- .../atriasoft/ege/ControlCameraPlayer.java | 16 +- src/org/atriasoft/ege/Environement.java | 4 +- ...hysicsPerso.java => ComponentPhysics.java} | 166 +++++++++++--- .../ege/components/ComponentPosition.java | 15 +- ...nePhysicsPerso.java => EnginePhysics.java} | 46 ++-- src/org/atriasoft/phyligram/PhysicShape.java | 20 +- .../{ => math}/ToolCollisionOBBWithOBB.java | 217 +++++++++--------- ...ToolCollisionSphereWithHeightMapChunk.java | 4 +- .../ToolCollisionSphereWithSphere.java | 4 +- .../ToolCollisionSphereWithTriangle.java | 5 +- .../phyligram/shape/HeightMapChunk.java | 5 +- 15 files changed, 364 insertions(+), 279 deletions(-) rename samples/src/sample/atriasoft/ege/{loxelEnginePerso => loxelEngine}/Log.java (95%) rename samples/src/sample/atriasoft/ege/{loxelEnginePerso => loxelEngine}/LoxelApplicationPerso.java (93%) rename samples/src/sample/atriasoft/ege/{loxelEnginePerso => loxelEngine}/MainLoxelEnginePerso.java (91%) rename src/org/atriasoft/ege/components/{ComponentPhysicsPerso.java => ComponentPhysics.java} (65%) rename src/org/atriasoft/ege/engines/{EnginePhysicsPerso.java => EnginePhysics.java} (79%) rename src/org/atriasoft/phyligram/{ => math}/ToolCollisionOBBWithOBB.java (91%) rename src/org/atriasoft/phyligram/{ => math}/ToolCollisionSphereWithHeightMapChunk.java (94%) rename src/org/atriasoft/phyligram/{ => math}/ToolCollisionSphereWithSphere.java (91%) rename src/org/atriasoft/phyligram/{ => math}/ToolCollisionSphereWithTriangle.java (97%) diff --git a/samples/src/sample/atriasoft/ege/collisiontest/CollisionTestApplication.java b/samples/src/sample/atriasoft/ege/collisiontest/CollisionTestApplication.java index dd9b287..44526d8 100644 --- a/samples/src/sample/atriasoft/ege/collisiontest/CollisionTestApplication.java +++ b/samples/src/sample/atriasoft/ege/collisiontest/CollisionTestApplication.java @@ -19,12 +19,10 @@ import org.atriasoft.ege.components.ComponentPlayer; import org.atriasoft.ege.components.ComponentPosition; import org.atriasoft.ege.components.ComponentPositionPlayer; import org.atriasoft.ege.components.ComponentRenderColoredStaticMesh; -import org.atriasoft.ege.components.ComponentRenderTexturedMaterialsStaticMesh; import org.atriasoft.ege.components.ComponentRenderTexturedStaticMesh; import org.atriasoft.ege.components.ComponentStaticMesh; import org.atriasoft.ege.components.ComponentTexture; import org.atriasoft.ege.components.PhysicBodyType; -import org.atriasoft.ege.engines.EngineLight; import org.atriasoft.ege.engines.EnginePhysics; import org.atriasoft.ege.map.MapVoxel; import org.atriasoft.ege.tools.MeshGenerator; @@ -35,8 +33,8 @@ import org.atriasoft.etk.math.Quaternion; import org.atriasoft.etk.math.Transform3D; import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector3f; -import org.atriasoft.gale.GaleApplication; import org.atriasoft.gale.Gale; +import org.atriasoft.gale.GaleApplication; import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL.Flag; import org.atriasoft.gale.context.GaleContext; @@ -45,7 +43,7 @@ import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.key.KeyStatus; import org.atriasoft.gale.key.KeyType; import org.atriasoft.gale.resource.ResourceColored3DObject; -import org.atriasoft.phyligram.shape.Box; +import org.atriasoft.phyligram.PhysicBox; public class CollisionTestApplication extends GaleApplication { public static Vector3f box1HalfSize; @@ -112,19 +110,15 @@ public class CollisionTestApplication extends GaleApplication { localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj"))); localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/dirt.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); - if (false) { - final ComponentPhysics physics2 = new ComponentPhysics(this.env); - physics2.setBodyType(PhysicBodyType.BODY_STATIC); - physics2.setTransform(new Transform3D(Vector3f.ZERO, orientation)); - final Box box2 = new Box(); - box2.setSize(new Vector3f(5.0f, 5.0f, 0.5f)); - box2.setOrigin(Vector3f.ZERO); - box2.setMass(0); - physics2.addShape(box2); - localBox.addComponent(physics2); - } else { - localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0)))); - } + localBox.addComponent(new ComponentPosition(new Transform3D(Vector3f.ZERO, orientation))); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); + physics2.setBodyType(PhysicBodyType.BODY_STATIC); + final PhysicBox box2 = new PhysicBox(); + box2.setSize(new Vector3f(5.0f, 5.0f, 0.5f)); + box2.setOrigin(Vector3f.ZERO); + box2.setMass(0); + physics2.addShape(box2); + localBox.addComponent(physics2); this.env.addEntity(localBox); } /* @@ -158,40 +152,17 @@ public class CollisionTestApplication extends GaleApplication { this.env.addEntity(gird); final Entity player = new Entity(this.env); - if (false) { - final Transform3D playerTransform = new Transform3D(new Vector3f(0, -5, 13)); - //this.objectPosition = new ComponentPositionPlayer(); - //player.addComponent(this.objectPosition); - this.objectPlayer = new ComponentPlayer(); - player.addComponent(this.objectPlayer); - player.addComponent(new ComponentMaterial(new Material())); - //player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj"))); - player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj"))); - player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png"))); - player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"), - (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME))); - final ComponentPhysics physics = new ComponentPhysics(this.env, playerTransform); - physics.setBodyType(PhysicBodyType.BODY_DYNAMIC); - final Box box = new Box(); - box.setSize(new Vector3f(0.3f, 0.3f, 0.9f)); - box.setOrigin(new Vector3f(0, 0, 0.9f)); - box.setMass(100); - physics.addShape(box); - player.addComponent(physics); - this.env.addEntity(player); - } else { - final Transform3D playerTransform = new Transform3D(new Vector3f(0, -5, 0)); - this.objectPosition = new ComponentPositionPlayer(); - player.addComponent(this.objectPosition); - this.objectPlayer = new ComponentPlayer(); - player.addComponent(this.objectPlayer); - player.addComponent(new ComponentMaterial(new Material())); - //player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj"))); - player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj"))); - player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png"))); - //player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME))); - this.env.addEntity(player); - } + final Transform3D playerTransform = new Transform3D(new Vector3f(0, -5, 0)); + this.objectPosition = new ComponentPositionPlayer(); + player.addComponent(this.objectPosition); + this.objectPlayer = new ComponentPlayer(); + player.addComponent(this.objectPlayer); + player.addComponent(new ComponentMaterial(new Material())); + //player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj"))); + player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj"))); + player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png"))); + //player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME))); + this.env.addEntity(player); final Camera mainView = new Camera(); this.env.addCamera("default", mainView); mainView.setPitch((float) Math.PI * -0.25f); @@ -209,9 +180,9 @@ public class CollisionTestApplication extends GaleApplication { final Engine tmpEngine = this.env.getEngine("physics"); if (tmpEngine != null) { final EnginePhysics physicsEngine = (EnginePhysics) tmpEngine; - //Disable gravity for test ... + //Disable gravity for test ... //physicsEngine.setGravity(new Vector3f(0.0f, 0.0f, -1.0f)); - physicsEngine.setGravity(new Vector3f(0.0f, 0.0f, -10.0f)); + //physicsEngine.setGravity(new Vector3f(0.0f, 0.0f, -10.0f)); } // ready to let Gale & Ege manage the display diff --git a/samples/src/sample/atriasoft/ege/loxelEnginePerso/Log.java b/samples/src/sample/atriasoft/ege/loxelEngine/Log.java similarity index 95% rename from samples/src/sample/atriasoft/ege/loxelEnginePerso/Log.java rename to samples/src/sample/atriasoft/ege/loxelEngine/Log.java index e2a2ac6..42f1f4e 100644 --- a/samples/src/sample/atriasoft/ege/loxelEnginePerso/Log.java +++ b/samples/src/sample/atriasoft/ege/loxelEngine/Log.java @@ -1,4 +1,4 @@ -package sample.atriasoft.ege.loxelEnginePerso; +package sample.atriasoft.ege.loxelEngine; public class Log { private static final String LIBNAME = "LoxelEnginePerso"; diff --git a/samples/src/sample/atriasoft/ege/loxelEnginePerso/LoxelApplicationPerso.java b/samples/src/sample/atriasoft/ege/loxelEngine/LoxelApplicationPerso.java similarity index 93% rename from samples/src/sample/atriasoft/ege/loxelEnginePerso/LoxelApplicationPerso.java rename to samples/src/sample/atriasoft/ege/loxelEngine/LoxelApplicationPerso.java index e3ec266..27d8782 100644 --- a/samples/src/sample/atriasoft/ege/loxelEnginePerso/LoxelApplicationPerso.java +++ b/samples/src/sample/atriasoft/ege/loxelEngine/LoxelApplicationPerso.java @@ -1,4 +1,4 @@ -package sample.atriasoft.ege.loxelEnginePerso; +package sample.atriasoft.ege.loxelEngine; import java.util.ArrayList; import java.util.List; @@ -14,7 +14,7 @@ import org.atriasoft.ege.components.ComponentGravityStatic; import org.atriasoft.ege.components.ComponentLight; import org.atriasoft.ege.components.ComponentLightSun; import org.atriasoft.ege.components.ComponentMaterial; -import org.atriasoft.ege.components.ComponentPhysicsPerso; +import org.atriasoft.ege.components.ComponentPhysics; import org.atriasoft.ege.components.ComponentPlayer; import org.atriasoft.ege.components.ComponentPosition; import org.atriasoft.ege.components.ComponentPositionPlayer; @@ -116,7 +116,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f)))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 5)))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(1.001f, 1.001f, 1.001f)); box2.setOrigin(new Vector3f(0, 0, 0)); @@ -133,7 +133,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f)))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 4, 2.5f)))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(2.0f, 2.0f, 2.0f)); box2.setOrigin(new Vector3f(0, 0, 0)); @@ -149,7 +149,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2, 2, 1.5f)))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(3.0f, 3.0f, 3.0f)); box2.setOrigin(new Vector3f(0, 0, 0)); @@ -166,7 +166,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-5, -5, 0)))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(2, 2, 2)); box2.setOrigin(new Vector3f(0, 0, 0)); @@ -184,7 +184,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(15, 15, 0), orientation))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(4, 4, 4)); box2.setOrigin(new Vector3f(0, 0, 0)); @@ -202,7 +202,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2, -2, 0.2f), orientation))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); // TODO: physics2.setAngularReactionEnable(false); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(0.5f, 0.5f, 0.5f)); @@ -221,7 +221,7 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/dirt.png", "loxelEngine"))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0.0f), orientation))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); physics2.setBodyType(PhysicBodyType.BODY_STATIC); final PhysicBox box2 = new PhysicBox(); box2.setSize(new Vector3f(20.0f, 20.0f, 0.5f)); @@ -261,7 +261,7 @@ public class LoxelApplicationPerso extends GaleApplication { // new Uri("DATA", "basic.frag"))); // env.addEntity(localBox); // } - + boolean selectCase1 = true; if (!this.disable) { // add a cube to test collision ... final Entity localBox = new Entity(this.env); @@ -270,22 +270,31 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f)))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 3, 0)))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); physics2.setBodyType(PhysicBodyType.BODY_STATIC); PhysicTriangle box2 = new PhysicTriangle(); - box2.setPoints(new Vector3f(4, 0, 0), new Vector3f(0, 4, 0), new Vector3f(-2, -2, 1)); - box2.setOrigin(new Vector3f(0, 0, 0)); - box2.setMass(0); - physics2.addShape(box2); - box2 = new PhysicTriangle(); - box2.setPoints(new Vector3f(4, 0, 0), new Vector3f(0, 4, 0), new Vector3f(6, 6, 0)); - box2.setOrigin(new Vector3f(0, 0, 0)); - box2.setMass(0); + if (selectCase1) { + box2.setPoints(new Vector3f(4, 0, 0), new Vector3f(0, 4, 0), new Vector3f(-2, -2, 1)); + box2.setOrigin(new Vector3f(0, 0, 0)); + box2.setMass(0); + physics2.addShape(box2); + box2 = new PhysicTriangle(); + box2.setPoints(new Vector3f(4, 0, 0), new Vector3f(0, 4, 0), new Vector3f(600, 600, -100)); + box2.setOrigin(new Vector3f(0, 0, 0)); + box2.setMass(0); + box2.setFrictionCoefficient(1.0f); + box2.setBouncingCoefficient(0.5f); + } else { + box2.setPoints(new Vector3f(4, 0, 0), new Vector3f(0, 4, 0), new Vector3f(-2, -2, 1)); + box2.setOrigin(new Vector3f(0, 0, 0)); + box2.setMass(0); + box2.setBouncingCoefficient(0.5f); + } physics2.addShape(box2); localBox.addComponent(physics2); this.env.addEntity(localBox); } - if (true) { + if (selectCase1) { // add a cube to test collision ... final Entity localBox = new Entity(this.env); localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj"))); @@ -293,12 +302,13 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f)))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.1f, 5.1f, 1.0f), Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f))))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); final PhysicSphere box2 = new PhysicSphere(); physics2.setBodyType(PhysicBodyType.BODY_STATIC); box2.setSize(1.0f); box2.setOrigin(new Vector3f(0, 0, 0)); box2.setMass(0); + box2.setBouncingCoefficient(0.5f); physics2.addShape(box2); localBox.addComponent(physics2); this.env.addEntity(localBox); @@ -310,8 +320,8 @@ public class LoxelApplicationPerso extends GaleApplication { localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine"))); localBox.addComponent(new ComponentLight(new Light(new Color(0.0f, 1.0f, 0.0f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0.03f, 0.002f)))); localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert", "loxelEngine"), new Uri("DATA", "basic.frag", "loxelEngine"))); - localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1, 5, 4), Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f))))); - final ComponentPhysicsPerso physics2 = new ComponentPhysicsPerso(this.env); + localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1.8f, 5.8f, 4), Quaternion.fromEulerAngles(new Vector3f(0.15f, 0.95f, 0.3f))))); + final ComponentPhysics physics2 = new ComponentPhysics(this.env); physics2.setBodyType(PhysicBodyType.BODY_DYNAMIC); final PhysicSphere box2 = new PhysicSphere(); box2.setSize(1.0f); @@ -342,7 +352,7 @@ public class LoxelApplicationPerso extends GaleApplication { player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME))); player.addComponent(new ComponentPosition(playerTransform)); - final ComponentPhysicsPerso physics = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics = new ComponentPhysics(this.env); physics.setBodyType(PhysicBodyType.BODY_DYNAMIC); //physics.setAngularReactionEnable(false); //physics.setSleepingEnable(false); @@ -365,7 +375,7 @@ public class LoxelApplicationPerso extends GaleApplication { player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png"))); player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert", "loxelEngine"), new Uri("DATA", "basicMaterial.frag", "loxelEngine"), (EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME))); - final ComponentPhysicsPerso physics = new ComponentPhysicsPerso(this.env); + final ComponentPhysics physics = new ComponentPhysics(this.env); physics.setBodyType(PhysicBodyType.BODY_DYNAMIC); final PhysicBox box = new PhysicBox(); box.setSize(new Vector3f(0.6f, 0.6f, 1.8f)); diff --git a/samples/src/sample/atriasoft/ege/loxelEnginePerso/MainLoxelEnginePerso.java b/samples/src/sample/atriasoft/ege/loxelEngine/MainLoxelEnginePerso.java similarity index 91% rename from samples/src/sample/atriasoft/ege/loxelEnginePerso/MainLoxelEnginePerso.java rename to samples/src/sample/atriasoft/ege/loxelEngine/MainLoxelEnginePerso.java index 0513658..b0e50b9 100644 --- a/samples/src/sample/atriasoft/ege/loxelEnginePerso/MainLoxelEnginePerso.java +++ b/samples/src/sample/atriasoft/ege/loxelEngine/MainLoxelEnginePerso.java @@ -1,4 +1,4 @@ -package sample.atriasoft.ege.loxelEnginePerso; +package sample.atriasoft.ege.loxelEngine; import org.atriasoft.ege.Ege; import org.atriasoft.etk.Uri; diff --git a/src/org/atriasoft/ege/ControlCameraPlayer.java b/src/org/atriasoft/ege/ControlCameraPlayer.java index 6860272..577271f 100644 --- a/src/org/atriasoft/ege/ControlCameraPlayer.java +++ b/src/org/atriasoft/ege/ControlCameraPlayer.java @@ -1,17 +1,16 @@ package org.atriasoft.ege; import org.atriasoft.ege.camera.Camera; -import org.atriasoft.ege.components.ComponentPhysics; import org.atriasoft.ege.components.ComponentPlayer; import org.atriasoft.ege.components.ComponentPositionPlayer; import org.atriasoft.ege.internal.Log; import org.atriasoft.etk.math.Transform3D; import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector3f; -import org.atriasoft.gale.Gale; import org.atriasoft.ewol.event.EventEntry; import org.atriasoft.ewol.event.EventInput; import org.atriasoft.ewol.event.EventTime; +import org.atriasoft.gale.Gale; import org.atriasoft.gale.key.KeyKeyboard; import org.atriasoft.gale.key.KeyStatus; @@ -21,7 +20,6 @@ public class ControlCameraPlayer implements ControlInterface { private boolean fpsMode = false; private final Entity playerEntity; private ComponentPositionPlayer playerPosition; - private ComponentPhysics playerPhysics; private final ComponentPlayer player; private boolean moveUp = false; private boolean moveDown = false; @@ -34,8 +32,6 @@ public class ControlCameraPlayer implements ControlInterface { this.playerEntity = playerEntity; if (this.playerEntity.exist("position")) { this.playerPosition = (ComponentPositionPlayer) this.playerEntity.getComponent("position"); - } else if (this.playerEntity.exist("physics")) { - this.playerPhysics = (ComponentPhysics) this.playerEntity.getComponent("physics"); } this.player = (ComponentPlayer) this.playerEntity.getComponent("player"); } @@ -146,8 +142,6 @@ public class ControlCameraPlayer implements ControlInterface { this.playerPosition.setAngles(new Vector3f(0, 0, tmpAngle)); this.camera.setRoll(-playerZAngle); Log.info("Change camera: " + this.camera.getYaw() + " " + this.camera.getPitch()); - } else if (this.playerPhysics != null) { - //this.playerPhysics.applyTorque(new Vector3f(0, 0, (float) Math.toRadians(delta.x * this.player.getTurnSpeed()))); } } return false; @@ -155,9 +149,6 @@ public class ControlCameraPlayer implements ControlInterface { @Override public void periodicCall(final EventTime event) { - if (this.playerPhysics != null) { - //this.camera.setRoll(-this.playerPhysics.getAngles().z); - } float speed = 0; float walkFactor = 1; if (this.walk) { @@ -177,9 +168,6 @@ public class ControlCameraPlayer implements ControlInterface { if (this.playerPosition != null) { playerZAngle = this.playerPosition.getAngles().z(); playerTransform = this.playerPosition.getTransform(); - } else if (this.playerPhysics != null) { - playerZAngle = 0; // TODO ... - playerTransform = this.playerPhysics.getTransform(); } final float dx = -(float) (distance * Math.sin(playerZAngle)); final float dy = (float) (distance * Math.cos(playerZAngle)); @@ -200,8 +188,6 @@ public class ControlCameraPlayer implements ControlInterface { playerTransform = playerTransform.withPosition(tmpPos); if (this.playerPosition != null) { this.playerPosition.setTransform(playerTransform); - } else if (this.playerPhysics != null) { - this.playerPhysics.setTransform(playerTransform); } // here the camera is behind the player, we need to move the camera ... //Log.info(" pitch: " + Math.toDegrees(this.camera.getPitch()) + " " + Math.toDegrees(playerZAngle)); diff --git a/src/org/atriasoft/ege/Environement.java b/src/org/atriasoft/ege/Environement.java index ce717a1..3db8db7 100644 --- a/src/org/atriasoft/ege/Environement.java +++ b/src/org/atriasoft/ege/Environement.java @@ -13,7 +13,7 @@ import org.atriasoft.ege.engines.EngineDynamicMeshs; import org.atriasoft.ege.engines.EngineGravity; import org.atriasoft.ege.engines.EngineLight; import org.atriasoft.ege.engines.EngineParticle; -import org.atriasoft.ege.engines.EnginePhysicsPerso; +import org.atriasoft.ege.engines.EnginePhysics; import org.atriasoft.ege.engines.EnginePlayer; import org.atriasoft.ege.engines.EngineRender; import org.atriasoft.ege.internal.Log; @@ -72,7 +72,7 @@ public class Environement { addEngine(new EngineDynamicMeshs(this)); addEngine(new EngineRender(this)); //addEngine(new EnginePhysics(this)); - addEngine(new EnginePhysicsPerso(this)); + addEngine(new EnginePhysics(this)); addEngine(new EngineParticle(this)); addEngine(new EngineLight(this)); this.startClock = Clock.systemUTC(); diff --git a/src/org/atriasoft/ege/components/ComponentPhysicsPerso.java b/src/org/atriasoft/ege/components/ComponentPhysics.java similarity index 65% rename from src/org/atriasoft/ege/components/ComponentPhysicsPerso.java rename to src/org/atriasoft/ege/components/ComponentPhysics.java index e8eb9b6..53fd016 100644 --- a/src/org/atriasoft/ege/components/ComponentPhysicsPerso.java +++ b/src/org/atriasoft/ege/components/ComponentPhysics.java @@ -2,17 +2,21 @@ package org.atriasoft.ege.components; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import org.atriasoft.ege.Component; import org.atriasoft.ege.Environement; import org.atriasoft.ege.engines.EngineGravity; -import org.atriasoft.ege.engines.EnginePhysicsPerso; +import org.atriasoft.ege.engines.EnginePhysics; import org.atriasoft.ege.internal.Log; import org.atriasoft.etk.Color; +import org.atriasoft.etk.math.FMath; import org.atriasoft.etk.math.Matrix4f; +import org.atriasoft.etk.math.Transform3D; import org.atriasoft.etk.math.Vector3f; import org.atriasoft.gale.resource.ResourceColored3DObject; import org.atriasoft.phyligram.ColisionPoint; @@ -22,19 +26,24 @@ import org.atriasoft.phyligram.PhysicMapVoxel; import org.atriasoft.phyligram.PhysicShape; import org.atriasoft.phyligram.PhysicSphere; import org.atriasoft.phyligram.PhysicTriangle; -import org.atriasoft.phyligram.ToolCollisionOBBWithOBB; -import org.atriasoft.phyligram.ToolCollisionSphereWithHeightMapChunk; -import org.atriasoft.phyligram.ToolCollisionSphereWithSphere; -import org.atriasoft.phyligram.ToolCollisionSphereWithTriangle; +import org.atriasoft.phyligram.math.ToolCollisionOBBWithOBB; +import org.atriasoft.phyligram.math.ToolCollisionSphereWithHeightMapChunk; +import org.atriasoft.phyligram.math.ToolCollisionSphereWithSphere; +import org.atriasoft.phyligram.math.ToolCollisionSphereWithTriangle; import org.atriasoft.phyligram.shape.AABB; -public class ComponentPhysicsPerso extends Component { +public class ComponentPhysics extends Component { + public static float MINIMUM_BOUNCING_STOP = 0.0001f; + //public static float ANGLE_MAX_BOUNCING = 0.02f; public static float globalMaxSpeed = Float.MAX_VALUE; private AABB aabb; - private List aabbIntersection = new ArrayList<>(); - private Map> narrowIntersection = new HashMap<>(); + private List aabbIntersection = new ArrayList<>(); + private Set collisionPrevious = new HashSet<>(); + private Map> collisionCurrent = new HashMap<>(); //List collisionPoints = new ArrayList<>(); private List shapes = new ArrayList<>(); + // collision already exist ==> prepare friction: + Transform3D previousPosition; private ComponentPosition position; private boolean manageGravity = true; private float maxSpeed = globalMaxSpeed; @@ -48,11 +57,11 @@ public class ComponentPhysicsPerso extends Component { private Vector3f dynamicForce = new Vector3f(0, 0, 0); // Apply dynamic force on it private Vector3f dynamicForceGlobal = new Vector3f(0, 0, 0); - private EnginePhysicsPerso engine; + private EnginePhysics engine; private PhysicBodyType bodyType; - public ComponentPhysicsPerso(final Environement _env) { - this.engine = (EnginePhysicsPerso) _env.getEngine(getType()); + public ComponentPhysics(final Environement _env) { + this.engine = (EnginePhysics) _env.getEngine(getType()); } @Override @@ -66,7 +75,7 @@ public class ComponentPhysicsPerso extends Component { } } - public void addIntersection(ComponentPhysicsPerso component) { + public void addIntersection(ComponentPhysics component) { // do not add multiple times if (this.aabbIntersection.contains(component)) { return; @@ -78,16 +87,42 @@ public class ComponentPhysicsPerso extends Component { this.shapes.add(shape); } - public void applyColisionForce() { - Vector3f globalForce = Vector3f.ZERO; - for (Entry> elem : this.narrowIntersection.entrySet()) { + public void applyColisionForce(float timeStep) { + for (Entry> elem : this.collisionCurrent.entrySet()) { + Float globalBouncing = null; + if (!this.collisionPrevious.contains(elem.getKey())) { + globalBouncing = elem.getKey().getBouncingCoefficient(); + } + float globalFriction = elem.getKey().getFrictionCoefficient(); + Vector3f globalForce = Vector3f.ZERO; for (ColisionPoint impact : elem.getValue()) { globalForce = globalForce.add(impact.force); } + // nothing to apply ? + if (globalForce == Vector3f.ZERO) { + continue; + } + // when tuch a kinematy force is divide between the two + if (elem.getKey().getBodyType() == PhysicBodyType.BODY_DYNAMIC) { + globalForce = globalForce.multiply(0.5f); + } + if (globalBouncing != null) { + // detect new collision ==> apply bouncing + if (this.speed.length2() < MINIMUM_BOUNCING_STOP) { + this.speed = Vector3f.ZERO; + } else { + // this force is not depending on the mass... + this.speed = this.speed.reflect(globalForce.normalize()).multiply(globalBouncing); // apply the bouncing... + } + this.position.applyForce(globalForce); + } else { + // second consecutive time off collision ==> friction ... + this.position.applyForce(globalForce); + this.speed = this.position.getTransform().getPosition().less(this.previousPosition.getPosition());//.divide(timeStep); + globalFriction = 1.0f - FMath.avg(0.0f, globalFriction, 1.0f) * timeStep; + this.speed = this.speed.multiply(globalFriction); + } } - // this force is not depending on the mass... - this.speed = this.speed.add(globalForce); - this.position.applyForce(globalForce); } public void applyForces(float timeStep, EngineGravity gravity) { @@ -126,6 +161,54 @@ public class ComponentPhysicsPerso extends Component { this.position.setTransform(this.position.getTransform().withPosition(this.position.getTransform().getPosition().add(this.speed))); } + /* + + public void applyColisionForce(float timeStep) { + Vector3f globalForce = Vector3f.ZERO; + float globalBouncing = 1.0f; + this.haveBouncing = false; + for (Entry> elem : this.collisionCurrent.entrySet()) { + if (!this.collisionPrevious.contains(elem.getKey())) { + this.haveBouncing = true; + globalBouncing = FMath.min(globalBouncing, elem.getKey().getBouncingCoefficient()); + } + for (ColisionPoint impact : elem.getValue()) { + globalForce = globalForce.add(impact.force); + } + } + if (globalForce == Vector3f.ZERO) { + return; + } + if (this.haveBouncing) { + // detect new collision ==> apply bouncing + if (this.speed.length2() < MINIMUM_BOUNCING_STOP) { + this.speed = Vector3f.ZERO; + } else { + // this force is not depending on the mass... + this.speed = this.speed.reflect(globalForce.normalize()).multiply(globalBouncing); // apply the bouncing... + } + this.position.applyForce(globalForce); + } else { + this.position.applyForce(globalForce); + this.speed = this.position.getTransform().getPosition().less(this.previousPosition.getPosition());//.divide(timeStep); + } + } + + public void applyFriction(float timeStep) { + if (this.collisionCurrent.isEmpty()) { + return; + } + float globalFriction = 0.0f; + for (Entry> elem : this.collisionCurrent.entrySet()) { + globalFriction += elem.getKey().getFrictionCoefficient(); + } + globalFriction = 1.0f - FMath.avg(0.0f, globalFriction, 1.0f) * timeStep; + if (!this.haveBouncing) { + this.speed = this.speed.multiply(globalFriction); // c'est ini qu'il faut mettre en place l'absortion complète + } + } + */ + private boolean checkCollide(PhysicShape shapeCurrent) { if (shapeCurrent instanceof PhysicBox shape111) { for (PhysicShape shape : this.shapes) { @@ -196,7 +279,7 @@ public class ComponentPhysicsPerso extends Component { if (this.bodyType != PhysicBodyType.BODY_DYNAMIC) { return false; } - for (ComponentPhysicsPerso elem : this.aabbIntersection) { + for (ComponentPhysics elem : this.aabbIntersection) { boolean collide = false; for (PhysicShape shapeCurrent : this.shapes) { if (elem.checkCollide(shapeCurrent)) { @@ -205,11 +288,11 @@ public class ComponentPhysicsPerso extends Component { } } if (collide) { - if (!this.narrowIntersection.containsKey(elem)) { - this.narrowIntersection.put(elem, new ArrayList<>()); + if (!this.collisionCurrent.containsKey(elem)) { + this.collisionCurrent.put(elem, new ArrayList<>()); } - if (!elem.narrowIntersection.containsKey(this)) { - elem.narrowIntersection.put(this, new ArrayList<>()); + if (!elem.collisionCurrent.containsKey(this)) { + elem.collisionCurrent.put(this, new ArrayList<>()); } } } @@ -221,8 +304,11 @@ public class ComponentPhysicsPerso extends Component { } public void clearPreviousCollision() { + // store the previous list of collide elements + this.collisionPrevious = new HashSet<>(this.collisionCurrent.keySet()); + this.previousPosition = this.position.getTransform(); this.aabbIntersection.clear(); - this.narrowIntersection.clear(); + this.collisionCurrent.clear(); } public void clearShape() { @@ -233,7 +319,7 @@ public class ComponentPhysicsPerso extends Component { return this.aabb; } - public List getAabbIntersection() { + public List getAabbIntersection() { return this.aabbIntersection; } @@ -241,6 +327,14 @@ public class ComponentPhysicsPerso extends Component { return this.bodyType; } + private float getBouncingCoefficient() { + float total = 0.0f; + for (PhysicShape shape : this.shapes) { + total = FMath.max(total, shape.getBouncingCoefficient()); + } + return total; + } + private List getCollidePoints(PhysicShape shapeRemote) { List out = new ArrayList<>(); if (shapeRemote instanceof PhysicSphere remoteShere) { @@ -266,13 +360,21 @@ public class ComponentPhysicsPerso extends Component { return out; } + public float getFrictionCoefficient() { + float total = 0.0f; + for (PhysicShape shape : this.shapes) { + total = FMath.max(total, shape.getFrictionCoefficient()); + } + return total; + } + public float getMaxSpeed() { return this.maxSpeed; } @Override public String getType() { - return EnginePhysicsPerso.ENGINE_NAME; + return EnginePhysics.ENGINE_NAME; } public boolean isManageGravity() { @@ -280,7 +382,7 @@ public class ComponentPhysicsPerso extends Component { } public boolean isNarrowCollide() { - if (this.narrowIntersection.isEmpty()) { + if (this.collisionCurrent.isEmpty()) { return false; } return true; @@ -296,10 +398,10 @@ public class ComponentPhysicsPerso extends Component { if (this.bodyType != PhysicBodyType.BODY_DYNAMIC) { return; } - if (this.narrowIntersection.size() == 0) { + if (this.collisionCurrent.size() == 0) { return; } - for (Entry> elem : this.narrowIntersection.entrySet()) { + for (Entry> elem : this.collisionCurrent.entrySet()) { for (PhysicShape shapeCurrent : this.shapes) { //TODO Do a better method we do this many times ... /* @@ -321,7 +423,7 @@ public class ComponentPhysicsPerso extends Component { public void renderDebug(ResourceColored3DObject debugDrawProperty) { Color displayColor; displayColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); - for (Entry> elem : this.narrowIntersection.entrySet()) { + for (Entry> elem : this.collisionCurrent.entrySet()) { for (ColisionPoint impact : elem.getValue()) { debugDrawProperty.drawSquare(new Vector3f(0.02f, 0.02f, 0.02f), Matrix4f.createMatrixTranslate(impact.position), displayColor); } @@ -329,7 +431,7 @@ public class ComponentPhysicsPerso extends Component { if (this.aabbIntersection.size() == 0) { displayColor = new Color(1.0f, 1.0f, 1.0f, 1.0f); } else { - if (this.narrowIntersection.size() == 0) { + if (this.collisionCurrent.size() == 0) { displayColor = new Color(0.0f, 1.0f, 0.0f, 1.0f); } else { displayColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); @@ -375,7 +477,7 @@ public class ComponentPhysicsPerso extends Component { } public void updateForNarrowCollision() { - this.narrowIntersection.clear(); + this.collisionCurrent.clear(); if (this.aabbIntersection.size() == 0) { return; } diff --git a/src/org/atriasoft/ege/components/ComponentPosition.java b/src/org/atriasoft/ege/components/ComponentPosition.java index ad079f2..4522450 100644 --- a/src/org/atriasoft/ege/components/ComponentPosition.java +++ b/src/org/atriasoft/ege/components/ComponentPosition.java @@ -3,21 +3,18 @@ package org.atriasoft.ege.components; import org.atriasoft.ege.Component; import org.atriasoft.ege.Signal; import org.atriasoft.ege.components.part.PositionningInterface; -import org.atriasoft.ege.internal.Log; import org.atriasoft.etk.math.Transform3D; import org.atriasoft.etk.math.Vector3f; public class ComponentPosition extends Component implements PositionningInterface { public final Signal signalPosition = new Signal<>(); protected Transform3D transform; - //protected Vector3f speed; /** * Create a basic position component (no orientation and position (0,0,0)) */ public ComponentPosition() { this.transform = Transform3D.IDENTITY; - //this.speed = Vector3f.ZERO; } /** @@ -30,19 +27,13 @@ public class ComponentPosition extends Component implements PositionningInterfac @Override public void addFriendComponent(final Component component) { - if (component.getType().equals("physics")) { - Log.critical("Can not add a 'physics' component and a 'position' component ... ==> incompatible"); - } + } public void applyForce(Vector3f force) { this.transform = this.transform.withPosition(this.transform.getPosition().add(force)); } - //public Vector3f getSpeed() { - // return this.speed; - //} - /** * set a new transformation * @return Transformation of the position @@ -57,10 +48,6 @@ public class ComponentPosition extends Component implements PositionningInterfac return "position"; } - //public void setSpeed(Vector3f speed) { - // this.speed = speed; - //} - /** * set a new transformation * @param transform transformation of the position diff --git a/src/org/atriasoft/ege/engines/EnginePhysicsPerso.java b/src/org/atriasoft/ege/engines/EnginePhysics.java similarity index 79% rename from src/org/atriasoft/ege/engines/EnginePhysicsPerso.java rename to src/org/atriasoft/ege/engines/EnginePhysics.java index 8c3d26d..00a4795 100644 --- a/src/org/atriasoft/ege/engines/EnginePhysicsPerso.java +++ b/src/org/atriasoft/ege/engines/EnginePhysics.java @@ -6,24 +6,24 @@ import org.atriasoft.ege.Component; import org.atriasoft.ege.Engine; import org.atriasoft.ege.Environement; import org.atriasoft.ege.camera.Camera; -import org.atriasoft.ege.components.ComponentPhysicsPerso; +import org.atriasoft.ege.components.ComponentPhysics; import org.atriasoft.ege.components.PhysicBodyType; import org.atriasoft.ege.internal.Log; import org.atriasoft.gale.resource.ResourceColored3DObject; import org.atriasoft.phyligram.DebugDisplay; import org.atriasoft.phyligram.shape.AABB; -public class EnginePhysicsPerso extends Engine { - public static final String ENGINE_NAME = "physicsPerso"; +public class EnginePhysics extends Engine { + public static final String ENGINE_NAME = "physics"; private static final float TIME_STEP = 0.005f; private float accumulator = 0; private EngineGravity gravity; - protected EnginePhysicsPerso engine; - private Vector components = new Vector<>(); - private Vector componentsWithCollision = new Vector<>(); + protected EnginePhysics engine; + private Vector components = new Vector<>(); + private Vector componentsWithCollision = new Vector<>(); private ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create(); - public EnginePhysicsPerso(Environement env) { + public EnginePhysics(Environement env) { super(env); this.gravity = (EngineGravity) env.getEngine("gravity"); if (this.gravity == null) { @@ -31,7 +31,7 @@ public class EnginePhysicsPerso extends Engine { } } - private void addIncomponentWithCollision(ComponentPhysicsPerso elem) { + private void addIncomponentWithCollision(ComponentPhysics elem) { if (this.componentsWithCollision.contains(elem)) { return; } @@ -39,8 +39,8 @@ public class EnginePhysicsPerso extends Engine { } private void applyForces(float timeStep) { - for (ComponentPhysicsPerso it : this.components) { - it.applyForces(TIME_STEP, this.gravity); + for (ComponentPhysics it : this.components) { + it.applyForces(timeStep, this.gravity); } } @@ -48,17 +48,17 @@ public class EnginePhysicsPerso extends Engine { * Clear the previous data of collision. */ private void clearPreviousCycle() { - for (ComponentPhysicsPerso it : this.components) { + for (ComponentPhysics it : this.components) { it.clearPreviousCollision(); } } @Override public void componentAdd(Component ref) { - if (ref instanceof ComponentPhysicsPerso == false) { + if (ref instanceof ComponentPhysics == false) { return; } - this.components.add((ComponentPhysicsPerso) ref); + this.components.add((ComponentPhysics) ref); } @Override @@ -71,8 +71,8 @@ public class EnginePhysicsPerso extends Engine { * @param timeStep */ private void generateResultCollisionsForces(float timeStep) { - for (ComponentPhysicsPerso it : this.componentsWithCollision) { - it.applyColisionForce(); + for (ComponentPhysics it : this.componentsWithCollision) { + it.applyColisionForce(timeStep); } } @@ -85,7 +85,7 @@ public class EnginePhysicsPerso extends Engine { @Override public void render(long deltaMili, Camera camera) { // TODO Auto-generated method stub - for (ComponentPhysicsPerso it : this.components) { + for (ComponentPhysics it : this.components) { //Log.info("Render " + it); it.renderDebug(this.debugDrawProperty); } @@ -128,7 +128,7 @@ public class EnginePhysicsPerso extends Engine { * @param timeStep Delta time since the last check */ private void updateAABB(float timeStep) { - for (ComponentPhysicsPerso it : this.components) { + for (ComponentPhysics it : this.components) { it.updateAABB(); } } @@ -141,15 +141,15 @@ public class EnginePhysicsPerso extends Engine { private void updateCollisionsAABB(float timeStep) { this.componentsWithCollision.clear(); // clear all object intersection - for (ComponentPhysicsPerso it : this.components) { + for (ComponentPhysics it : this.components) { it.clearAABBIntersection(); } // update the current object intersection... for (int iii = 0; iii < this.components.size(); iii++) { - ComponentPhysicsPerso current = this.components.get(iii); + ComponentPhysics current = this.components.get(iii); AABB currentAABB = current.getAABB(); for (int jjj = iii + 1; jjj < this.components.size(); jjj++) { - ComponentPhysicsPerso remote = this.components.get(jjj); + ComponentPhysics remote = this.components.get(jjj); if (current.getBodyType() != PhysicBodyType.BODY_DYNAMIC && remote.getBodyType() != PhysicBodyType.BODY_DYNAMIC) { continue; } @@ -170,18 +170,18 @@ public class EnginePhysicsPerso extends Engine { */ private void updateCollisionsNarrowPhase(float timeStep) { // clear all object intersection - for (ComponentPhysicsPerso it : this.componentsWithCollision) { + for (ComponentPhysics it : this.componentsWithCollision) { it.updateForNarrowCollision(); } // check for every component if the narrow collision is available. for (int iii = 0; iii < this.componentsWithCollision.size(); iii++) { - ComponentPhysicsPerso current = this.componentsWithCollision.get(iii); + ComponentPhysics current = this.componentsWithCollision.get(iii); boolean collide = current.checkNarrowCollision(); } // update the force of collision available. for (int iii = 0; iii < this.components.size(); iii++) { - ComponentPhysicsPerso current = this.components.get(iii); + ComponentPhysics current = this.components.get(iii); current.narrowCollisionCreateContactAndForce(); } } diff --git a/src/org/atriasoft/phyligram/PhysicShape.java b/src/org/atriasoft/phyligram/PhysicShape.java index 9999843..964c101 100644 --- a/src/org/atriasoft/phyligram/PhysicShape.java +++ b/src/org/atriasoft/phyligram/PhysicShape.java @@ -16,7 +16,9 @@ public abstract class PhysicShape { // protected Vector3f origin; protected Transform3D transform; protected Transform3D transformGlobal; - protected float mass = 0; + protected float mass = 0.0f; + protected float frictionCoefficient = 0.0f; + protected float bouncingCoefficient = 0.0f; public PhysicShape() { this.transform = Transform3D.IDENTITY; @@ -36,6 +38,14 @@ public abstract class PhysicShape { this.colisionPoints.add(colision); } + public float getBouncingCoefficient() { + return this.bouncingCoefficient; + } + + public float getFrictionCoefficient() { + return this.frictionCoefficient; + } + public float getMass() { return this.mass; } @@ -62,6 +72,14 @@ public abstract class PhysicShape { public abstract void renderDebug(Transform3D transform, ResourceColored3DObject debugDrawProperty); + public void setBouncingCoefficient(float bouncingCoefficient) { + this.bouncingCoefficient = bouncingCoefficient; + } + + public void setFrictionCoefficient(float frictionCoefficient) { + this.frictionCoefficient = frictionCoefficient; + } + public void setMass(float mass) { this.mass = mass; } diff --git a/src/org/atriasoft/phyligram/ToolCollisionOBBWithOBB.java b/src/org/atriasoft/phyligram/math/ToolCollisionOBBWithOBB.java similarity index 91% rename from src/org/atriasoft/phyligram/ToolCollisionOBBWithOBB.java rename to src/org/atriasoft/phyligram/math/ToolCollisionOBBWithOBB.java index f4262f2..462a439 100644 --- a/src/org/atriasoft/phyligram/ToolCollisionOBBWithOBB.java +++ b/src/org/atriasoft/phyligram/math/ToolCollisionOBBWithOBB.java @@ -1,8 +1,11 @@ -package org.atriasoft.phyligram; +package org.atriasoft.phyligram.math; import org.atriasoft.etk.math.Quaternion; import org.atriasoft.etk.math.Vector3f; -import org.atriasoft.phyligram.internal.Log; +import org.atriasoft.phyligram.ColisionPoint; +import org.atriasoft.phyligram.Collision; +import org.atriasoft.phyligram.DebugDisplay; +import org.atriasoft.phyligram.PhysicBox; // set the relevant elements of our oriented bounding box class OBB { @@ -11,101 +14,17 @@ class OBB { public Vector3f axisY; public Vector3f axisZ; public Vector3f halfSize; - + public OBB() { - position = Vector3f.ZERO; - axisX = Vector3f.ZERO; - axisY = Vector3f.ZERO; - axisZ = Vector3f.ZERO; - halfSize = Vector3f.ZERO; + this.position = Vector3f.ZERO; + this.axisX = Vector3f.ZERO; + this.axisY = Vector3f.ZERO; + this.axisZ = Vector3f.ZERO; + this.halfSize = Vector3f.ZERO; } -}; +} public class ToolCollisionOBBWithOBB { - private ToolCollisionOBBWithOBB() {} - - // check if there's a separating plane in between the selected axes - private static boolean getSeparatingPlane(Vector3f rPos, Vector3f plane, OBB box1, OBB box2) { - return (Math.abs(rPos.dot(plane)) > (Math.abs(box1.axisX.multiply(box1.halfSize.x()).dot(plane)) + Math.abs(box1.axisY.multiply(box1.halfSize.y()).dot(plane)) - + Math.abs(box1.axisZ.multiply(box1.halfSize.z()).dot(plane)) + Math.abs(box2.axisX.multiply(box2.halfSize.x()).dot(plane)) - + Math.abs(box2.axisY.multiply(box2.halfSize.y()).dot(plane)) + Math.abs(box2.axisZ.multiply(box2.halfSize.z()).dot(plane)))); - } - - // test for separating planes in all 15 axes - public static boolean getCollision(OBB box1, OBB box2) { - Vector3f rPos = box2.position.less(box1.position); - boolean ret = getSeparatingPlane(rPos, box1.axisX, box1, box2) || getSeparatingPlane(rPos, box1.axisY, box1, box2) || getSeparatingPlane(rPos, box1.axisZ, box1, box2) - || getSeparatingPlane(rPos, box2.axisX, box1, box2) || getSeparatingPlane(rPos, box2.axisY, box1, box2) || getSeparatingPlane(rPos, box2.axisZ, box1, box2) - || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisX), box1, box2) || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisY), box1, box2) - || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisZ), box1, box2) || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisX), box1, box2) - || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisY), box1, box2) || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisZ), box1, box2) - || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisX), box1, box2) || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisY), box1, box2) - || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisZ), box1, box2); - return !ret; - } -// -// // a quick test to see the code working -// public static void main(String[] args) { -// // create two obbs -// OBB aaa = new OBB(); -// OBB bbb = new OBB(); -// -// // set the first obb's properties -// aaa.position = new Vector3f(0.0f, 0.0f, 0.0f); // set its center position -// -// // set the half size -// aaa.halfSize = new Vector3f(10.0f, 1.0f, 1.0f); -// -// // set the axes orientation -// aaa.axisX = new Vector3f(1.0f, 0.0f, 0.0f); -// aaa.axisY = new Vector3f(0.0f, 1.0f, 0.0f); -// aaa.axisZ = new Vector3f(0.0f, 0.0f, 1.0f); -// -// // set the second obb's properties -// bbb.position = new Vector3f(20.0f, 0.0f, 0.0f); // set its center position -// -// // set the half size -// bbb.halfSize = new Vector3f(10.0f, 1.0f, 1.0f); -// -// // set the axes orientation -// bbb.axisX = new Vector3f(1.0f, 0.0f, 0.0f); -// bbb.axisY = new Vector3f(0.0f, 1.0f, 0.0f); -// bbb.axisZ = new Vector3f(0.0f, 0.0f, 1.0f); -// -// // run the code and get the result as a message -// if (getCollision(aaa, bbb)) { -// Log.info("Collision!!!"); -// } else { -// Log.info("NO Collision!!!"); -// } -// } - - // check if there's a separating plane in between the selected axes - private static boolean getSeparatingPlane222(Vector3f rPos, Vector3f plane, PhysicBox box1, PhysicBox box2) { - return (Math.abs(rPos.dot(plane)) > (Math.abs(box1.narrowPhaseAxisX.multiply(box1.narrowPhaseHalfSize.x()).dot(plane)) - + Math.abs(box1.narrowPhaseAxisY.multiply(box1.narrowPhaseHalfSize.y()).dot(plane)) + Math.abs(box1.narrowPhaseAxisZ.multiply(box1.narrowPhaseHalfSize.z()).dot(plane)) - + Math.abs(box2.narrowPhaseAxisX.multiply(box2.narrowPhaseHalfSize.x()).dot(plane)) + Math.abs(box2.narrowPhaseAxisY.multiply(box2.narrowPhaseHalfSize.y()).dot(plane)) - + Math.abs(box2.narrowPhaseAxisZ.multiply(box2.narrowPhaseHalfSize.z()).dot(plane)))); - } - - public static boolean testCollide(PhysicBox box1, PhysicBox box2) { - - Vector3f rPos = box2.narrowPhaseGlobalPos.less(box1.narrowPhaseGlobalPos); - boolean ret = getSeparatingPlane222(rPos, box1.narrowPhaseAxisX, box1, box2) || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY, box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ, box1, box2) || getSeparatingPlane222(rPos, box2.narrowPhaseAxisX, box1, box2) - || getSeparatingPlane222(rPos, box2.narrowPhaseAxisY, box1, box2) || getSeparatingPlane222(rPos, box2.narrowPhaseAxisZ, box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisX), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisY), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisZ), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisX), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisY), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisZ), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisX), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisY), box1, box2) - || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisZ), box1, box2); - return !ret; - } - public static void getCollidePoints(PhysicBox box1, boolean isStatic1, PhysicBox box2, boolean isStatic2) { // Log.info("Try to calculare reverse force ........"); Vector3f rPos1 = box1.narrowPhaseGlobalPos.less(box2.narrowPhaseGlobalPos); @@ -116,7 +35,7 @@ public class ToolCollisionOBBWithOBB { Quaternion quatTransfer1 = Quaternion.diff(quat1, quat2); Quaternion quatTransfer2 = Quaternion.diff(quat2, quat1); // quatTransfer.normalize(); - + // DebugDisplay.relativeTest = quatTransfer; // Vector3f tmp = rPos.addNew(new Vector3f(0,0,14)); // DebugDisplay.relativeTestPos.getTransform().setPosition(tmp); @@ -133,7 +52,7 @@ public class ToolCollisionOBBWithOBB { DebugDisplay.testQTransfert = quatTransfer2; DebugDisplay.box1HalfSize = box2.narrowPhaseHalfSize; DebugDisplay.box2HalfSize = box1.narrowPhaseHalfSize; - + // DebugDisplay.relativeTestPos.getTransform().setPosition(tmp); // DebugDisplay.relativeTestPos.getTransform().setOrientation(quatTransfer); // DebugDisplay.boxTest.setSize(box1.getSize()); @@ -150,7 +69,7 @@ public class ToolCollisionOBBWithOBB { } } /* res = trensfert in generic plan the new res ... */ - + DebugDisplay.testRpos = quat1.inverse().getMatrix4().multiply(rPos2); DebugDisplay.testQTransfert = quatTransfer1; DebugDisplay.box1HalfSize = box1.narrowPhaseHalfSize; @@ -171,11 +90,11 @@ public class ToolCollisionOBBWithOBB { Collision colision = new Collision(collide2, box1, collide1, isStatic1); box2.addColision(colision); } - + } - + public static ColisionPoint[] getCollidePointsAABBCenteredWithOBB(Vector3f box1HalfSize, Vector3f box2HalfSize, Quaternion box2Orientation, Vector3f box2Position) { - + // point in AABB Vector3f topBackRight = box2Orientation.multiply(new Vector3f(+box2HalfSize.x(), +box2HalfSize.y(), +box2HalfSize.z())).add(box2Position); Vector3f topBackLeft = box2Orientation.multiply(new Vector3f(-box2HalfSize.x(), +box2HalfSize.y(), +box2HalfSize.z())).add(box2Position); @@ -288,18 +207,75 @@ public class ToolCollisionOBBWithOBB { return out; } // line in AABB - // TODO: + // TODO: // Log.info("Need to detect line inside ..."); // pas tot a fait... si ca colisione déja avec un point de l'autre ... return null; } - - public static boolean pointInAABB(Vector3f halfSize, Vector3f point) { - if (point.x() > -halfSize.x() && point.x() < halfSize.x() && point.y() > -halfSize.y() && point.y() < halfSize.y() && point.z() > -halfSize.z() && point.z() < halfSize.z()) { - return true; - } - return false; + + // test for separating planes in all 15 axes + public static boolean getCollision(OBB box1, OBB box2) { + Vector3f rPos = box2.position.less(box1.position); + boolean ret = getSeparatingPlane(rPos, box1.axisX, box1, box2) || getSeparatingPlane(rPos, box1.axisY, box1, box2) || getSeparatingPlane(rPos, box1.axisZ, box1, box2) + || getSeparatingPlane(rPos, box2.axisX, box1, box2) || getSeparatingPlane(rPos, box2.axisY, box1, box2) || getSeparatingPlane(rPos, box2.axisZ, box1, box2) + || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisX), box1, box2) || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisY), box1, box2) + || getSeparatingPlane(rPos, box1.axisX.cross(box2.axisZ), box1, box2) || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisX), box1, box2) + || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisY), box1, box2) || getSeparatingPlane(rPos, box1.axisY.cross(box2.axisZ), box1, box2) + || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisX), box1, box2) || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisY), box1, box2) + || getSeparatingPlane(rPos, box1.axisZ.cross(box2.axisZ), box1, box2); + return !ret; } - + // + // // a quick test to see the code working + // public static void main(String[] args) { + // // create two obbs + // OBB aaa = new OBB(); + // OBB bbb = new OBB(); + // + // // set the first obb's properties + // aaa.position = new Vector3f(0.0f, 0.0f, 0.0f); // set its center position + // + // // set the half size + // aaa.halfSize = new Vector3f(10.0f, 1.0f, 1.0f); + // + // // set the axes orientation + // aaa.axisX = new Vector3f(1.0f, 0.0f, 0.0f); + // aaa.axisY = new Vector3f(0.0f, 1.0f, 0.0f); + // aaa.axisZ = new Vector3f(0.0f, 0.0f, 1.0f); + // + // // set the second obb's properties + // bbb.position = new Vector3f(20.0f, 0.0f, 0.0f); // set its center position + // + // // set the half size + // bbb.halfSize = new Vector3f(10.0f, 1.0f, 1.0f); + // + // // set the axes orientation + // bbb.axisX = new Vector3f(1.0f, 0.0f, 0.0f); + // bbb.axisY = new Vector3f(0.0f, 1.0f, 0.0f); + // bbb.axisZ = new Vector3f(0.0f, 0.0f, 1.0f); + // + // // run the code and get the result as a message + // if (getCollision(aaa, bbb)) { + // Log.info("Collision!!!"); + // } else { + // Log.info("NO Collision!!!"); + // } + // } + + // check if there's a separating plane in between the selected axes + private static boolean getSeparatingPlane(Vector3f rPos, Vector3f plane, OBB box1, OBB box2) { + return (Math.abs(rPos.dot(plane)) > (Math.abs(box1.axisX.multiply(box1.halfSize.x()).dot(plane)) + Math.abs(box1.axisY.multiply(box1.halfSize.y()).dot(plane)) + + Math.abs(box1.axisZ.multiply(box1.halfSize.z()).dot(plane)) + Math.abs(box2.axisX.multiply(box2.halfSize.x()).dot(plane)) + + Math.abs(box2.axisY.multiply(box2.halfSize.y()).dot(plane)) + Math.abs(box2.axisZ.multiply(box2.halfSize.z()).dot(plane)))); + } + + // check if there's a separating plane in between the selected axes + private static boolean getSeparatingPlane222(Vector3f rPos, Vector3f plane, PhysicBox box1, PhysicBox box2) { + return (Math.abs(rPos.dot(plane)) > (Math.abs(box1.narrowPhaseAxisX.multiply(box1.narrowPhaseHalfSize.x()).dot(plane)) + + Math.abs(box1.narrowPhaseAxisY.multiply(box1.narrowPhaseHalfSize.y()).dot(plane)) + Math.abs(box1.narrowPhaseAxisZ.multiply(box1.narrowPhaseHalfSize.z()).dot(plane)) + + Math.abs(box2.narrowPhaseAxisX.multiply(box2.narrowPhaseHalfSize.x()).dot(plane)) + Math.abs(box2.narrowPhaseAxisY.multiply(box2.narrowPhaseHalfSize.y()).dot(plane)) + + Math.abs(box2.narrowPhaseAxisZ.multiply(box2.narrowPhaseHalfSize.z()).dot(plane)))); + } + public static Vector3f pointDistanceInAABB(Vector3f halfSize, Vector3f point) { float outX = 0; float outY = 0; @@ -375,4 +351,31 @@ public class ToolCollisionOBBWithOBB { outY = 0; return new Vector3f(outX, outY, outZ); } + + public static boolean pointInAABB(Vector3f halfSize, Vector3f point) { + if (point.x() > -halfSize.x() && point.x() < halfSize.x() && point.y() > -halfSize.y() && point.y() < halfSize.y() && point.z() > -halfSize.z() && point.z() < halfSize.z()) { + return true; + } + return false; + } + + public static boolean testCollide(PhysicBox box1, PhysicBox box2) { + + Vector3f rPos = box2.narrowPhaseGlobalPos.less(box1.narrowPhaseGlobalPos); + boolean ret = getSeparatingPlane222(rPos, box1.narrowPhaseAxisX, box1, box2) || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY, box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ, box1, box2) || getSeparatingPlane222(rPos, box2.narrowPhaseAxisX, box1, box2) + || getSeparatingPlane222(rPos, box2.narrowPhaseAxisY, box1, box2) || getSeparatingPlane222(rPos, box2.narrowPhaseAxisZ, box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisX), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisY), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisX.cross(box2.narrowPhaseAxisZ), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisX), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisY), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisY.cross(box2.narrowPhaseAxisZ), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisX), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisY), box1, box2) + || getSeparatingPlane222(rPos, box1.narrowPhaseAxisZ.cross(box2.narrowPhaseAxisZ), box1, box2); + return !ret; + } + + private ToolCollisionOBBWithOBB() {} } diff --git a/src/org/atriasoft/phyligram/ToolCollisionSphereWithHeightMapChunk.java b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithHeightMapChunk.java similarity index 94% rename from src/org/atriasoft/phyligram/ToolCollisionSphereWithHeightMapChunk.java rename to src/org/atriasoft/phyligram/math/ToolCollisionSphereWithHeightMapChunk.java index e506061..32b8cc2 100644 --- a/src/org/atriasoft/phyligram/ToolCollisionSphereWithHeightMapChunk.java +++ b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithHeightMapChunk.java @@ -1,7 +1,9 @@ -package org.atriasoft.phyligram; +package org.atriasoft.phyligram.math; import org.atriasoft.ege.geometry.Triangle; import org.atriasoft.etk.math.Vector3f; +import org.atriasoft.phyligram.PhysicHeightMapChunk; +import org.atriasoft.phyligram.PhysicSphere; public class ToolCollisionSphereWithHeightMapChunk { //intersection entre 2 droite (en 2d avec estimation en 3D diff --git a/src/org/atriasoft/phyligram/ToolCollisionSphereWithSphere.java b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithSphere.java similarity index 91% rename from src/org/atriasoft/phyligram/ToolCollisionSphereWithSphere.java rename to src/org/atriasoft/phyligram/math/ToolCollisionSphereWithSphere.java index f67cea8..70132b2 100644 --- a/src/org/atriasoft/phyligram/ToolCollisionSphereWithSphere.java +++ b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithSphere.java @@ -1,6 +1,8 @@ -package org.atriasoft.phyligram; +package org.atriasoft.phyligram.math; import org.atriasoft.etk.math.Vector3f; +import org.atriasoft.phyligram.ColisionPoint; +import org.atriasoft.phyligram.PhysicSphere; import org.atriasoft.phyligram.internal.Log; public class ToolCollisionSphereWithSphere { diff --git a/src/org/atriasoft/phyligram/ToolCollisionSphereWithTriangle.java b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithTriangle.java similarity index 97% rename from src/org/atriasoft/phyligram/ToolCollisionSphereWithTriangle.java rename to src/org/atriasoft/phyligram/math/ToolCollisionSphereWithTriangle.java index 86808fe..49dba4f 100644 --- a/src/org/atriasoft/phyligram/ToolCollisionSphereWithTriangle.java +++ b/src/org/atriasoft/phyligram/math/ToolCollisionSphereWithTriangle.java @@ -1,8 +1,11 @@ -package org.atriasoft.phyligram; +package org.atriasoft.phyligram.math; import org.atriasoft.ege.geometry.Plane; import org.atriasoft.etk.math.FMath; import org.atriasoft.etk.math.Vector3f; +import org.atriasoft.phyligram.ColisionPoint; +import org.atriasoft.phyligram.PhysicSphere; +import org.atriasoft.phyligram.PhysicTriangle; // https://realtimecollisiondetection.net/blog/?p=103 public class ToolCollisionSphereWithTriangle { diff --git a/src/org/atriasoft/phyligram/shape/HeightMapChunk.java b/src/org/atriasoft/phyligram/shape/HeightMapChunk.java index 80be6b4..6dff3fd 100644 --- a/src/org/atriasoft/phyligram/shape/HeightMapChunk.java +++ b/src/org/atriasoft/phyligram/shape/HeightMapChunk.java @@ -1,15 +1,16 @@ package org.atriasoft.phyligram.shape; -import org.atriasoft.ephysics.collision.Triangle; +import org.atriasoft.ege.geometry.Triangle; public class HeightMapChunk extends Shape { private Triangle[] triangles; + public HeightMapChunk(Triangle[] triangles) { this.triangles = triangles; } + @Override public void display() { - // TODO Auto-generated method stub super.display(); }