[DEV] remove dependency with ephysic to manage only the internal physic engine phyligram.
This commit is contained in:
parent
1ecc20a08c
commit
13198ca95d
17
.classpath
17
.classpath
@ -6,17 +6,6 @@
|
|||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="resources"/>
|
<classpathentry kind="src" path="resources"/>
|
||||||
<classpathentry including="**/*.java" kind="src" output="out/eclipse/classes-test" path="test/src">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="test" value="true"/>
|
|
||||||
<attribute name="optional" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-ephysics">
|
|
||||||
<attributes>
|
|
||||||
<attribute name="module" value="true"/>
|
|
||||||
</attributes>
|
|
||||||
</classpathentry>
|
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-ewol">
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-ewol">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
@ -27,7 +16,11 @@
|
|||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package sample.atriasoft.ege.loxelEngine;
|
|
||||||
|
|
||||||
public class Log {
|
|
||||||
private static final String LIBNAME = "LoxelEngine";
|
|
||||||
|
|
||||||
public static void critical(String data) {
|
|
||||||
System.out.println("[C] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void debug(String data) {
|
|
||||||
System.out.println("[D] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void error(String data) {
|
|
||||||
System.out.println("[E] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(String data) {
|
|
||||||
System.out.println("[I] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void print(String data) {
|
|
||||||
System.out.println(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void todo(String data) {
|
|
||||||
System.out.println("[TODO] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void verbose(String data) {
|
|
||||||
System.out.println("[V] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void warning(String data) {
|
|
||||||
System.out.println("[W] " + Log.LIBNAME + " | " + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Log() {}
|
|
||||||
}
|
|
@ -1,437 +0,0 @@
|
|||||||
package sample.atriasoft.ege.loxelEngine;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.ege.ControlCameraPlayer;
|
|
||||||
import org.atriasoft.ege.Engine;
|
|
||||||
import org.atriasoft.ege.Entity;
|
|
||||||
import org.atriasoft.ege.Environement;
|
|
||||||
import org.atriasoft.ege.GameStatus;
|
|
||||||
import org.atriasoft.ege.Light;
|
|
||||||
import org.atriasoft.ege.Material;
|
|
||||||
import org.atriasoft.ege.camera.Camera;
|
|
||||||
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.ComponentPhysics;
|
|
||||||
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;
|
|
||||||
import org.atriasoft.etk.Color;
|
|
||||||
import org.atriasoft.etk.Uri;
|
|
||||||
import org.atriasoft.etk.math.Matrix4f;
|
|
||||||
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.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;
|
|
||||||
import org.atriasoft.gale.key.KeyKeyboard;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class LoxelApplication extends GaleApplication {
|
|
||||||
public static Vector3f box1HalfSize;
|
|
||||||
public static Vector3f box2HalfSize;
|
|
||||||
// public static ComponentPosition relativeTestPos;
|
|
||||||
// public static Box boxTest;
|
|
||||||
public static List<Vector3f> testPoints = new ArrayList<>();
|
|
||||||
public static List<Vector3f> testPointsBox = new ArrayList<>();
|
|
||||||
public static List<Boolean> testPointsCollide = new ArrayList<>();
|
|
||||||
public static Quaternion testQTransfert;
|
|
||||||
public static Vector3f testRpos;
|
|
||||||
private float angleLight = 0;
|
|
||||||
private Quaternion basicRotation = Quaternion.IDENTITY;
|
|
||||||
private Quaternion basicRotation2 = Quaternion.IDENTITY;
|
|
||||||
private ResourceColored3DObject debugDrawProperty;
|
|
||||||
private Environement env;
|
|
||||||
private ComponentPosition lightPosition;
|
|
||||||
private MapVoxel map;
|
|
||||||
private ComponentPlayer objectPlayer;
|
|
||||||
private ComponentPosition objectPosition;
|
|
||||||
private ControlCameraPlayer simpleControl;
|
|
||||||
|
|
||||||
public LoxelApplication() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(final GaleContext context) {
|
|
||||||
// set the system global max speed
|
|
||||||
//ComponentPhysics.globalMaxSpeed = 3;
|
|
||||||
Gale.getContext().grabPointerEvents(true, new Vector2f(0, 0));
|
|
||||||
this.env = new Environement();
|
|
||||||
setSize(new Vector2f(1500, 1500));
|
|
||||||
setTitle("Loxel sample");
|
|
||||||
this.map = new MapVoxel(this.env);
|
|
||||||
// this.env.addEngine(map);
|
|
||||||
// map.init();
|
|
||||||
|
|
||||||
// simple sun to have a global light ...
|
|
||||||
final Entity globalGravity = new Entity(this.env);
|
|
||||||
globalGravity.addComponent(new ComponentGravityStatic(new Vector3f(0, 0, -1)));
|
|
||||||
this.env.addEntity(globalGravity);
|
|
||||||
|
|
||||||
// simple sun to have a global light ...
|
|
||||||
final Entity sun = new Entity(this.env);
|
|
||||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
|
||||||
sun.addComponent(new ComponentLightSun(new Light(new Color(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
|
||||||
this.env.addEntity(sun);
|
|
||||||
|
|
||||||
// add a cube to show where in the light ...
|
|
||||||
final Entity localLight = new Entity(this.env);
|
|
||||||
this.lightPosition = new ComponentPosition(new Transform3D(new Vector3f(-10, -10, 17)));
|
|
||||||
// localLight.addComponent(lightPosition);
|
|
||||||
// localLight.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
|
||||||
// localLight.addComponent(new ComponentTexture(new Uri("RES", "grass.png")));
|
|
||||||
// localLight.addComponent(new ComponentLight(new Light(new Vector3f(0,1,0), new Vector3f(0,0,0), new Vector3f(0.8f,0.03f,0.002f))));
|
|
||||||
// localLight.addComponent(new ComponentRenderTexturedStaticMesh(
|
|
||||||
// new Uri("DATA", "basic.vert"),
|
|
||||||
// new Uri("DATA", "basic.frag")));
|
|
||||||
// env.addEntity(localLight);
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(0, 0, 5)));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(0.5f, 0.5f, 0.5f));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(0, 4, 12.5f)));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(0.5f, 0.5f, 0.5f));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(-2, 2, 14.5f)));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(0.5f, 0.5f, 0.5f));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(-5, -5, 14)));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(2, 2, 2));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
Quaternion orientation = new Quaternion(0.5f, 0.2f, 0.4f, 1);
|
|
||||||
orientation = orientation.normalize();
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(15, 15, 14), orientation));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(4, 4, 4));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// add a cube to test collision ...
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
final Quaternion orientation = new Quaternion(0.3f, 1.3f, 0.4f, 1);
|
|
||||||
//orientation.normalize();
|
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(2, -2, 14.2f), orientation));
|
|
||||||
physics2.setAngularReactionEnable(false);
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(0.5f, 0.5f, 0.5f));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(1);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// this is the floor
|
|
||||||
final Entity localBox = new Entity(this.env);
|
|
||||||
Quaternion orientation = new Quaternion(0, 0, 0, 1);
|
|
||||||
orientation = orientation.normalize();
|
|
||||||
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")));
|
|
||||||
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
|
||||||
physics2.setBodyType(PhysicBodyType.BODY_STATIC);
|
|
||||||
physics2.setTransform(new Transform3D(new Vector3f(0, 0, 0.0f), orientation));
|
|
||||||
final Box box2 = new Box();
|
|
||||||
box2.setSize(new Vector3f(20.0f, 20.0f, 0.5f));
|
|
||||||
box2.setOrigin(new Vector3f(0, 0, 0));
|
|
||||||
box2.setMass(0);
|
|
||||||
physics2.addShape(box2);
|
|
||||||
localBox.addComponent(physics2);
|
|
||||||
this.env.addEntity(localBox);
|
|
||||||
}
|
|
||||||
// {
|
|
||||||
// // add a cube to test collision ...
|
|
||||||
// Entity localBox = new Entity(this.env);
|
|
||||||
// relativeTestPos = new ComponentPosition(new Transform3D(new Vector3f(0,0,14),new Quaternion(0.5f,0.2f,0.4f,1)));
|
|
||||||
// localBox.addComponent(relativeTestPos);
|
|
||||||
//// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
//// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
|
||||||
//// localBox.addComponent(new ComponentLight(new Light(new Vector3f(0,1,0), new Vector3f(0,0,0), new Vector3f(0.8f,0.03f,0.002f))));
|
|
||||||
//// localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
|
||||||
//// new Uri("DATA", "basic.vert"),
|
|
||||||
//// new Uri("DATA", "basic.frag")));
|
|
||||||
// ComponentPhysics physics2 = new ComponentPhysics(true);
|
|
||||||
// boxTest = new Box();
|
|
||||||
// boxTest.setSize(new Vector3f(1,1,1));
|
|
||||||
// boxTest.setOrigin(new Vector3f(0,0,0));
|
|
||||||
// boxTest.setMass(1);
|
|
||||||
// physics2.addShape(boxTest);
|
|
||||||
// localBox.addComponent(physics2);
|
|
||||||
// env.addEntity(localBox);
|
|
||||||
// }
|
|
||||||
// {
|
|
||||||
// Entity localBox = new Entity(this.env);
|
|
||||||
// localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,14))));
|
|
||||||
// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
|
||||||
// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png", "loxelEngine")));
|
|
||||||
// localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
|
||||||
// new Uri("DATA", "basic.vert"),
|
|
||||||
// new Uri("DATA", "basic.frag")));
|
|
||||||
// env.addEntity(localBox);
|
|
||||||
// }
|
|
||||||
|
|
||||||
final Entity gird = new Entity(this.env);
|
|
||||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 0))));
|
|
||||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
|
||||||
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA", "wireColor.vert", "ege"), new Uri("DATA", "wireColor.frag", "ege")));
|
|
||||||
this.env.addEntity(gird);
|
|
||||||
|
|
||||||
final Entity player = new Entity(this.env);
|
|
||||||
if (false) {
|
|
||||||
final Transform3D playerTransform = new Transform3D(new Vector3f(0, -5, 1));
|
|
||||||
//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);
|
|
||||||
physics.setAngularReactionEnable(false);
|
|
||||||
physics.setSleepingEnable(false);
|
|
||||||
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(1);
|
|
||||||
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 Camera mainView = new Camera();
|
|
||||||
this.env.addCamera("default", mainView);
|
|
||||||
mainView.setPitch((float) Math.PI * -0.25f);
|
|
||||||
mainView.setPosition(new Vector3f(0, -5, 5));
|
|
||||||
|
|
||||||
this.simpleControl = new ControlCameraPlayer(mainView, player);
|
|
||||||
this.env.addControlInterface(this.simpleControl);
|
|
||||||
|
|
||||||
// start the engine.
|
|
||||||
this.env.setPropertyStatus(GameStatus.gameStart);
|
|
||||||
|
|
||||||
this.basicRotation = Quaternion.fromEulerAngles(new Vector3f(0.005f, 0.005f, 0.01f));
|
|
||||||
this.basicRotation2 = Quaternion.fromEulerAngles(new Vector3f(0.003f, 0.01f, 0.001f));
|
|
||||||
|
|
||||||
final Engine tmpEngine = this.env.getEngine("physics");
|
|
||||||
if (tmpEngine != null) {
|
|
||||||
final EnginePhysics physicsEngine = (EnginePhysics) tmpEngine;
|
|
||||||
//Disable gravity for test ...
|
|
||||||
physicsEngine.setGravity(new Vector3f(0.0f, 0.0f, -9.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ready to let Gale & Ege manage the display
|
|
||||||
Log.info("==> Init APPL (END)");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDraw(final GaleContext context) {
|
|
||||||
//Log.info("==> appl Draw ...");
|
|
||||||
final Vector2f size = getSize();
|
|
||||||
// Store openGl context.
|
|
||||||
OpenGL.push();
|
|
||||||
// set projection matrix:
|
|
||||||
final Matrix4f tmpProjection = Matrix4f.createMatrixPerspective(3.14f * 0.5f, getAspectRatio(), 0.1f, 50000);
|
|
||||||
OpenGL.setMatrix(tmpProjection);
|
|
||||||
|
|
||||||
// set the basic openGL view port: (Draw in all the windows...)
|
|
||||||
OpenGL.setViewPort(new Vector2f(0, 0), size);
|
|
||||||
|
|
||||||
// clear background
|
|
||||||
final Color bgColor = new Color(0.18f, 0.43f, 0.95f, 1.0f);
|
|
||||||
OpenGL.clearColor(bgColor);
|
|
||||||
// real clear request:
|
|
||||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
|
||||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_depthBuffer);
|
|
||||||
OpenGL.enable(Flag.flag_depthTest);
|
|
||||||
|
|
||||||
//Log.info("==> appl Draw ...");
|
|
||||||
this.env.render(20, "default");
|
|
||||||
if (this.debugDrawProperty == null) {
|
|
||||||
this.debugDrawProperty = ResourceColored3DObject.create();
|
|
||||||
}
|
|
||||||
// now render the point test collision ...
|
|
||||||
for (int iii = 0; iii < LoxelApplication.testPoints.size(); iii++) {
|
|
||||||
final Vector3f elem = LoxelApplication.testPoints.get(iii);
|
|
||||||
final boolean collide = LoxelApplication.testPointsCollide.get(iii);
|
|
||||||
if (collide) {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(1, 0, 0, 1));
|
|
||||||
} else if (iii == 0) {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(0, 1, 0, 1));
|
|
||||||
} else if (iii == 7) {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(1, 1, 0, 1));
|
|
||||||
} else {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(1, 1, 1, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int iii = 0; iii < LoxelApplication.testPointsBox.size(); iii++) {
|
|
||||||
final Vector3f elem = LoxelApplication.testPointsBox.get(iii);
|
|
||||||
if (iii == 0) {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(0, 1, 0, 1));
|
|
||||||
} else if (iii == 7) {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(1, 1, 0, 1));
|
|
||||||
} else {
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(new Vector3f(elem.x(), elem.y(), elem.z() + 14))),
|
|
||||||
new Color(0, 0, 1, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LoxelApplication.testRpos != null) {
|
|
||||||
//debugDrawProperty.drawSquare(box2HalfSize, testQTransfert.getMatrix4().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z+14))), new Color(0,1,0,0.5f));
|
|
||||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
|
||||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
|
||||||
//Matrix4f transformation = testQTransfert.getMatrix4().multiply(Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z))).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
|
||||||
final Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(LoxelApplication.testRpos.x(), LoxelApplication.testRpos.y(), LoxelApplication.testRpos.z()))
|
|
||||||
.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14))).multiply(LoxelApplication.testQTransfert.getMatrix4());
|
|
||||||
// OK sans la box1 orientation ...
|
|
||||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
|
||||||
//Matrix4f transformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(testQTransfert.getMatrix4()).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)));
|
|
||||||
this.debugDrawProperty.drawSquare(LoxelApplication.box2HalfSize, transformation, new Color(0, 1, 0, 0.5f));
|
|
||||||
this.debugDrawProperty.drawSquare(LoxelApplication.box1HalfSize, Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore context of matrix
|
|
||||||
OpenGL.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
|
||||||
if (type == KeyKeyboard.F1) {
|
|
||||||
Gale.getContext().grabPointerEvents(false, new Vector2f(0, 0));
|
|
||||||
}
|
|
||||||
if (type == KeyKeyboard.F2) {
|
|
||||||
Gale.getContext().grabPointerEvents(true, new Vector2f(0, 0));
|
|
||||||
}
|
|
||||||
if (type == KeyKeyboard.F12) {
|
|
||||||
Gale.getContext().setFullScreen(!Gale.getContext().getFullScreen());
|
|
||||||
}
|
|
||||||
this.env.onKeyboard(special, type, value, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
|
|
||||||
this.env.onPointer(special, type, pointerID, pos, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRegenerateDisplay(final GaleContext context) {
|
|
||||||
//Log.verbose("Regenerate Gale Application");
|
|
||||||
this.angleLight += 0.01;
|
|
||||||
this.lightPosition.setTransform(this.lightPosition.getTransform()
|
|
||||||
.withPosition(new Vector3f(5 + (float) Math.cos(this.angleLight) * 7.0f, 5 + (float) Math.sin(this.angleLight) * 7.0f, this.lightPosition.getTransform().getPosition().z())));
|
|
||||||
this.env.periodicCall();
|
|
||||||
markDrawingIsNeeded();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package sample.atriasoft.ege.loxelEngine;
|
|
||||||
|
|
||||||
import org.atriasoft.ege.Ege;
|
|
||||||
import org.atriasoft.etk.Uri;
|
|
||||||
import org.atriasoft.gale.Gale;
|
|
||||||
|
|
||||||
import sample.atriasoft.ege.collisiontest.MainCollisionTest;
|
|
||||||
|
|
||||||
public class MainLoxelEngine {
|
|
||||||
public static void main(final String[] args) {
|
|
||||||
Gale.init();
|
|
||||||
Ege.init();
|
|
||||||
Uri.setGroup("DATA", "data/");
|
|
||||||
Uri.setGroup("RES", "res");
|
|
||||||
Uri.addLibrary("loxelEngine", MainLoxelEngine.class, "testDataLoxelEngine/");
|
|
||||||
Uri.setApplication(MainLoxelEngine.class, "");
|
|
||||||
Gale.run(new LoxelApplication(), args);
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,7 +28,7 @@ open module org.atriasoft.ege {
|
|||||||
requires transitive org.atriasoft.gale;
|
requires transitive org.atriasoft.gale;
|
||||||
requires transitive org.atriasoft.etk;
|
requires transitive org.atriasoft.etk;
|
||||||
requires transitive org.atriasoft.ewol;
|
requires transitive org.atriasoft.ewol;
|
||||||
requires transitive org.atriasoft.ephysics;
|
//requires transitive org.atriasoft.ephysics;
|
||||||
requires transitive org.atriasoft.loader3d;
|
requires transitive org.atriasoft.loader3d;
|
||||||
requires org.atriasoft.iogami;
|
requires org.atriasoft.iogami;
|
||||||
}
|
}
|
||||||
|
@ -1,574 +0,0 @@
|
|||||||
package org.atriasoft.ege.components;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.ege.Component;
|
|
||||||
import org.atriasoft.ege.Environement;
|
|
||||||
import org.atriasoft.ege.Signal;
|
|
||||||
import org.atriasoft.ege.camera.Camera;
|
|
||||||
import org.atriasoft.ege.components.part.PositionningInterface;
|
|
||||||
import org.atriasoft.ege.engines.EnginePhysics;
|
|
||||||
import org.atriasoft.ege.internal.Log;
|
|
||||||
import org.atriasoft.ephysics.body.BodyType;
|
|
||||||
import org.atriasoft.ephysics.body.RigidBody;
|
|
||||||
import org.atriasoft.ephysics.collision.ProxyShape;
|
|
||||||
import org.atriasoft.ephysics.collision.TriangleMesh;
|
|
||||||
import org.atriasoft.ephysics.collision.TriangleVertexArray;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.BoxShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.CapsuleShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.CollisionShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.ConcaveMeshShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.ConcaveShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.ConeShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.CylinderShape;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.SphereShape;
|
|
||||||
import org.atriasoft.etk.Color;
|
|
||||||
import org.atriasoft.etk.math.Matrix4f;
|
|
||||||
import org.atriasoft.etk.math.Quaternion;
|
|
||||||
import org.atriasoft.etk.math.Transform3D;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
|
||||||
import org.atriasoft.phyligram.shape.Box;
|
|
||||||
import org.atriasoft.phyligram.shape.Capsule;
|
|
||||||
import org.atriasoft.phyligram.shape.Concave;
|
|
||||||
import org.atriasoft.phyligram.shape.Cone;
|
|
||||||
import org.atriasoft.phyligram.shape.ConvexHull;
|
|
||||||
import org.atriasoft.phyligram.shape.Cylinder;
|
|
||||||
import org.atriasoft.phyligram.shape.Shape;
|
|
||||||
import org.atriasoft.phyligram.shape.Sphere;
|
|
||||||
|
|
||||||
public class ComponentPhysics extends Component implements PositionningInterface {
|
|
||||||
public Signal<Transform3D> signalPosition = new Signal<>();
|
|
||||||
protected Transform3D lastTransformEmit;
|
|
||||||
protected EnginePhysics engine;
|
|
||||||
protected RigidBody rigidBody;
|
|
||||||
protected List<CollisionShape> listShape = new ArrayList<>();
|
|
||||||
protected List<ProxyShape> listProxyShape = new ArrayList<>();
|
|
||||||
|
|
||||||
protected Vector3f staticForceApplyCenterOfMass = new Vector3f(0, 0, 0);
|
|
||||||
|
|
||||||
protected Vector3f staticTorqueApply = new Vector3f(0, 0, 0);
|
|
||||||
|
|
||||||
protected List<Shape> shape = new ArrayList<>(); //!< collision shape module ... (independent of bullet lib)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a basic position component (no orientation and position (0,0,0))
|
|
||||||
*/
|
|
||||||
public ComponentPhysics(final Environement _env) {
|
|
||||||
this.engine = (EnginePhysics) _env.getEngine(getType());
|
|
||||||
// Initial position and orientation of the rigid body
|
|
||||||
this.lastTransformEmit = new Transform3D(new Vector3f(0, 0, 0), Quaternion.IDENTITY);
|
|
||||||
this.rigidBody = this.engine.getDynamicsWorld().createRigidBody(this.lastTransformEmit);
|
|
||||||
this.rigidBody.setUserData(this);
|
|
||||||
// set collision callback:
|
|
||||||
//this.engine.getDynamicWorld().testCollision(this.rigidBody, this);
|
|
||||||
this.rigidBody.getMaterial().setBounciness(0.0f);
|
|
||||||
this.rigidBody.setAngularDamping(0.9f);
|
|
||||||
this.rigidBody.setLinearDamping(0.9f);
|
|
||||||
//this.rigidBody.getMaterial().setFrictionCoefficient(0.01f);
|
|
||||||
//this.rigidBody.getMaterial().setRollingResistance(0.01f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a basic position component
|
|
||||||
* @param _transform transformation of the position
|
|
||||||
*/
|
|
||||||
public ComponentPhysics(final Environement _env, final Transform3D _transform) {
|
|
||||||
this.engine = (EnginePhysics) _env.getEngine(getType());
|
|
||||||
// Create a rigid body in the world
|
|
||||||
this.rigidBody = this.engine.getDynamicsWorld().createRigidBody(_transform);
|
|
||||||
this.rigidBody.setUserData(this);
|
|
||||||
this.lastTransformEmit = _transform;
|
|
||||||
// set collision callback:
|
|
||||||
//this.engine.getDynamicWorld().testCollision(this.rigidBody, this);
|
|
||||||
Log.error("Bounciness=" + this.rigidBody.getMaterial().getBounciness());
|
|
||||||
Log.error("FrictionCoefficient=" + this.rigidBody.getMaterial().getFrictionCoefficient());
|
|
||||||
Log.error("RollingResistance=" + this.rigidBody.getMaterial().getRollingResistance());
|
|
||||||
Log.error("LinearDamping=" + this.rigidBody.getLinearDamping());
|
|
||||||
Log.error("AngularDamping=" + this.rigidBody.getAngularDamping());
|
|
||||||
this.rigidBody.getMaterial().setBounciness(0.0f);
|
|
||||||
//this.rigidBody.getMaterial().setFrictionCoefficient(0.01f);
|
|
||||||
//this.rigidBody.getMaterial().setRollingResistance(0.01f);
|
|
||||||
this.rigidBody.setAngularDamping(0.9f);
|
|
||||||
this.rigidBody.setLinearDamping(0.9f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addFriendComponent(final Component component) {
|
|
||||||
if (component.getType().contains("position")) {
|
|
||||||
Log.critical("Can not add a 'physic' component and a 'position' component ... ==> incompatible");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addShape(final Shape _shape) {
|
|
||||||
this.shape.add(_shape);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply an external force to the body at a given point (in world-space coordinates).
|
|
||||||
* If the point is not at the center of mass of the body, it will also generate some torque and therefore, change the angular velocity of the body.
|
|
||||||
* If the body is sleeping, calling this method will wake it up. Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the DynamicsWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.
|
|
||||||
* @param _force The force to apply on the body
|
|
||||||
* @param _point The point where the force is applied (in world-space coordinates)
|
|
||||||
*/
|
|
||||||
public void applyForce(final Vector3f _force, final Vector3f _point) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.applyForce(_force, _point);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply an external force to the body at its center of mass.
|
|
||||||
* If the body is sleeping, calling this method will wake it up.
|
|
||||||
* @note The force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the DynamicsWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.
|
|
||||||
* @param _force The external force to apply on the center of mass of the body
|
|
||||||
*/
|
|
||||||
public void applyForceToCenterOfMass(final Vector3f _force) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.applyForceToCenterOfMass(_force);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyForceToCenterOfMassStatic(final Vector3f _force) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.staticForceApplyCenterOfMass = _force;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply an external force to the body at its center of mass.
|
|
||||||
* If the body is sleeping, calling this method will wake it up.
|
|
||||||
* @note The force is apply with a relative axis of the object
|
|
||||||
* @note The force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the DynamicsWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.
|
|
||||||
* @param _force The external force to apply on the center of mass of the body
|
|
||||||
*/
|
|
||||||
public void applyRelativeForceToCenterOfMass(final Vector3f _force) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Vector3f force = this.rigidBody.getTransform().getOrientation().multiply(_force);
|
|
||||||
this.rigidBody.applyForceToCenterOfMass(force);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyRelativeForceToCenterOfMassStatic(final Vector3f _force) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.staticForceApplyCenterOfMass = this.rigidBody.getTransform().getOrientation().multiply(_force);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply an external torque to the body.
|
|
||||||
* If the body is sleeping, calling this method will wake it up.
|
|
||||||
* @note The torque is apply with a relative axis of the object
|
|
||||||
* @note The force will we added to the sum of the applied torques and that this sum will be reset to zero at the end of each call of the DynamicsWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.
|
|
||||||
* @param _torque The external torque to apply on the body
|
|
||||||
*/
|
|
||||||
public void applyRelativeTorque(final Vector3f _torque) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Vector3f torque = this.rigidBody.getTransform().getOrientation().multiply(_torque);
|
|
||||||
this.rigidBody.applyTorque(torque);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyRelativeTorqueStatic(final Vector3f _torque) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.staticTorqueApply = this.rigidBody.getTransform().getOrientation().multiply(_torque);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply an external torque to the body.
|
|
||||||
* If the body is sleeping, calling this method will wake it up.
|
|
||||||
* @note The force will we added to the sum of the applied torques and that this sum will be reset to zero at the end of each call of the DynamicsWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.
|
|
||||||
* @param _torque The external torque to apply on the body
|
|
||||||
*/
|
|
||||||
public void applyTorque(final Vector3f _torque) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.applyTorque(_torque);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void applyTorqueStatic(final Vector3f _torque) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.staticTorqueApply = _torque;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a new contact point is found between two bodies that were separated before.
|
|
||||||
* @param _other The other component that have the impact
|
|
||||||
* @param _normal Normal of the impact
|
|
||||||
* @param _pos Position of the impact at the current object
|
|
||||||
* @param _posOther Position of the impact at the other object
|
|
||||||
* @param _penetrationDepth Depth penetration in the object
|
|
||||||
*/
|
|
||||||
public void beginContact(final Component _other, final Vector3f _normal, final Vector3f _pos, final Vector3f _posOther, final float _penetrationDepth) {
|
|
||||||
Log.warning(" collision [BEGIN] " + _pos + " depth=" + _penetrationDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawShape(final ResourceColored3DObject _draw, final Camera _camera) {
|
|
||||||
final Transform3D transform = getTransform();
|
|
||||||
//final float[] mmm = new float[16];
|
|
||||||
// Get the OpenGL matrix array of the transform
|
|
||||||
final Matrix4f mmm = transform.getOpenGLMatrix();
|
|
||||||
|
|
||||||
final Matrix4f transformationMatrix = mmm.transpose();
|
|
||||||
final Color tmpColor = new Color(1.0f, 0.0f, 0.0f, 0.3f);
|
|
||||||
for (final Shape it : this.shape) {
|
|
||||||
if (it instanceof Box tmpElement) {
|
|
||||||
Log.debug(" Box");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrix.multiply(transformationMatrixLocal);
|
|
||||||
_draw.drawSquare(tmpElement.getSize(), transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof Cylinder tmpElement) {
|
|
||||||
Log.debug(" Cylinder");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrix.multiply(transformationMatrixLocal);
|
|
||||||
_draw.drawCylinder(tmpElement.getRadius(), tmpElement.getSize(), 10, 10, transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof Capsule tmpElement) {
|
|
||||||
Log.debug(" Capsule");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrix.multiply(transformationMatrixLocal);
|
|
||||||
_draw.drawCapsule(tmpElement.getRadius(), tmpElement.getSize(), 10, 10, transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof Cone tmpElement) {
|
|
||||||
Log.debug(" Cone");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrix.multiply(transformationMatrixLocal);
|
|
||||||
_draw.drawCone(tmpElement.getRadius(), tmpElement.getSize(), 10, 10, transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof Sphere tmpElement) {
|
|
||||||
|
|
||||||
Log.debug(" Sphere");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrix.multiply(transformationMatrixLocal);
|
|
||||||
_draw.drawSphere(tmpElement.getRadius(), 10, 10, transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof Concave tmpElement) {
|
|
||||||
|
|
||||||
Log.debug(" concave");
|
|
||||||
final Transform3D transformLocal = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
|
|
||||||
Matrix4f transformationMatrixLocal = transformLocal.getOpenGLMatrix();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.transpose();
|
|
||||||
transformationMatrixLocal = transformationMatrixLocal.multiply(transformationMatrixLocal);
|
|
||||||
|
|
||||||
_draw.drawTriangles(tmpElement.getVertex(), tmpElement.getIndices(), transformationMatrixLocal, tmpColor);
|
|
||||||
} else if (it instanceof ConvexHull tmpElement) {
|
|
||||||
Log.debug(" convexHull");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// call done after all cycle update of the physical engine
|
|
||||||
public void emitAll() {
|
|
||||||
// emit only of new ...
|
|
||||||
final Transform3D transform = getTransform();
|
|
||||||
if (this.lastTransformEmit != transform) {
|
|
||||||
this.lastTransformEmit = transform;
|
|
||||||
this.signalPosition.emit(transform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate() {
|
|
||||||
if (this.shape.size() == 0) {
|
|
||||||
Log.warning("No Shape Availlable ...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: support more than one shape for each elements... (ProxyShape)
|
|
||||||
for (final Shape it : this.shape) {
|
|
||||||
if (it == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (it instanceof Box tmpElement) {
|
|
||||||
Log.debug(" Box");
|
|
||||||
// Half extents of the box in the x, y and z directions
|
|
||||||
final Vector3f halfExtents = new Vector3f(tmpElement.getSize().x(), tmpElement.getSize().y(), tmpElement.getSize().z());
|
|
||||||
// Create the box shape
|
|
||||||
final BoxShape shape = new BoxShape(halfExtents, 0.0001f);
|
|
||||||
this.listShape.add(shape);
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
//orientation = orientation * ephysics::Quaternion(-0.707107, 0, 0, 0.707107);
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else if (it instanceof Cylinder tmpElement) {
|
|
||||||
Log.debug(" Cylinder");
|
|
||||||
// Create the Cylinder shape
|
|
||||||
// Create the Cylinder shape
|
|
||||||
final CylinderShape shape = new CylinderShape(tmpElement.getRadius(), tmpElement.getSize());
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
final Quaternion orientation = it.getOrientation().multiply(new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f));
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), orientation);
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else if (it instanceof Capsule tmpElement) {
|
|
||||||
Log.debug(" Capsule");
|
|
||||||
// Create the Capsule shape
|
|
||||||
final CapsuleShape shape = new CapsuleShape(tmpElement.getRadius(), tmpElement.getSize());
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
final Quaternion orientation = it.getOrientation().multiply(new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f));
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), orientation);
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else if (it instanceof Cone tmpElement) {
|
|
||||||
Log.debug(" Cone");
|
|
||||||
// Create the Cone shape
|
|
||||||
final ConeShape shape = new ConeShape(tmpElement.getRadius(), tmpElement.getSize());
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
final Quaternion orientation = it.getOrientation().multiply(new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f));
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), orientation);
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else if (it instanceof Sphere tmpElement) {
|
|
||||||
Log.debug(" Sphere");
|
|
||||||
// Create the box shape
|
|
||||||
final SphereShape shape = new SphereShape(tmpElement.getRadius());
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
final Quaternion orientation = it.getOrientation().multiply(new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f));
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), orientation);
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else if (it instanceof Concave tmpElement) {
|
|
||||||
Log.debug(" Concave");
|
|
||||||
//static etk::Vector<Vector3f> vertices = {Vector3f(-100.0f,-100.0f,-50.0f),Vector3f(100.0f,-100.0f,-50.0f),Vector3f(100.0f,100.0f,-50.0f)};
|
|
||||||
//static etk::Vector<uint32_t> indices = {0,1,2};
|
|
||||||
|
|
||||||
//ephysics::TriangleVertexArray* triangleArray = ETK_NEW(ephysics::TriangleVertexArray, vertices, indices);
|
|
||||||
final TriangleVertexArray triangleArray = new TriangleVertexArray(tmpElement.getVertex(), tmpElement.getIndices());
|
|
||||||
// Now that we have a TriangleVertexArray, we need to create a TriangleMesh and add the TriangleVertexArray into it as a subpart.
|
|
||||||
// Once this is done, we can create the actual ConcaveMeshShape and add it to the body we want to simulate as in the following example:
|
|
||||||
final TriangleMesh triangleMesh = new TriangleMesh();
|
|
||||||
// Add the triangle vertex array to the triangle mesh
|
|
||||||
triangleMesh.addSubpart(triangleArray);
|
|
||||||
// Create the concave mesh shape
|
|
||||||
// TODO : Manage memory leak ...
|
|
||||||
final ConcaveShape shape = new ConcaveMeshShape(triangleMesh);
|
|
||||||
// The ephysic use Y as UP ==> ege use Z as UP
|
|
||||||
final Quaternion orientation = it.getOrientation().multiply(new Quaternion(-0.707107f, 0.0f, 0.0f, 0.707107f));
|
|
||||||
final Transform3D transform = new Transform3D(it.getOrigin(), it.getOrientation());
|
|
||||||
final ProxyShape proxyShape = this.rigidBody.addCollisionShape(shape, transform, it.getMass());
|
|
||||||
proxyShape.setUserData(this);
|
|
||||||
this.listProxyShape.add(proxyShape);
|
|
||||||
} else {
|
|
||||||
Log.debug(" ???");
|
|
||||||
// TODO UNKNOWN type ...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the angular velocity (whole world).
|
|
||||||
* @return The angular velocity vector of the body
|
|
||||||
*/
|
|
||||||
public Vector3f getAngularVelocity() {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return new Vector3f(0, 0, 0);
|
|
||||||
}
|
|
||||||
return this.rigidBody.getAngularVelocity();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the linear velocity (whole world).
|
|
||||||
* @return The linear velocity vector of the body
|
|
||||||
*/
|
|
||||||
public Vector3f getLinearVelocity() {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return new Vector3f(0, 0, 0);
|
|
||||||
}
|
|
||||||
return this.rigidBody.getLinearVelocity();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the angular velocity (local Body).
|
|
||||||
* @return The angular velocity vector of the body
|
|
||||||
*/
|
|
||||||
public Vector3f getRelativeAngularVelocity() {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return new Vector3f(0, 0, 0);
|
|
||||||
}
|
|
||||||
final Vector3f value = this.rigidBody.getAngularVelocity();
|
|
||||||
return this.rigidBody.getTransform().getOrientation().inverse().multiply(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the linear velocity (local Body).
|
|
||||||
* @return The linear velocity vector of the body
|
|
||||||
*/
|
|
||||||
public Vector3f getRelativeLinearVelocity() {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return new Vector3f(0, 0, 0);
|
|
||||||
}
|
|
||||||
final Vector3f value = this.rigidBody.getLinearVelocity();
|
|
||||||
return this.rigidBody.getTransform().getOrientation().inverse().multiply(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Shape> getShape() {
|
|
||||||
return this.shape;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set a new transformation
|
|
||||||
* @return Transformation of the position
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Transform3D getTransform() {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return Transform3D.IDENTITY;
|
|
||||||
}
|
|
||||||
return this.rigidBody.getTransform();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
return "physics";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a new contact point is found between two bodies.
|
|
||||||
* @param _other The other component that have the impact
|
|
||||||
* @param _normal Normal of the impact
|
|
||||||
* @param _pos Position of the impact at the current object
|
|
||||||
* @param _posOther Position of the impact at the other object
|
|
||||||
* @param _penetrationDepth Depth penetration in the object
|
|
||||||
*/
|
|
||||||
public void newContact(final Component _other, final Vector3f _normal, final Vector3f _pos, final Vector3f _posOther, final float _penetrationDepth) {
|
|
||||||
Log.warning(" collision [ NEW ] " + _pos + " depth=" + _penetrationDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void renderDebug(final ResourceColored3DObject _draw, final Camera _camera) {
|
|
||||||
if (this.rigidBody == null) {}
|
|
||||||
/*
|
|
||||||
final Matrix4f transformationMatrix = Matrix4f.IDENTITY;
|
|
||||||
final Color tmpColor = new Color(0.0f, 1.0f, 0.0f, 0.8f);
|
|
||||||
final AABB value = this.rigidBody.getAABB();
|
|
||||||
_draw.drawCubeLine(value.getMin(), value.getMax(), tmpColor, transformationMatrix, true, true);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAngularReactionEnable(final boolean value) {
|
|
||||||
this.rigidBody.setAngularReactionEnable(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the angular velocity (whole world).
|
|
||||||
* @param _angularVelocity The angular velocity vector of the body
|
|
||||||
*/
|
|
||||||
public void setAngularVelocity(final Vector3f _angularVelocity) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.setAngularVelocity(_angularVelocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBodyType(final PhysicBodyType _type) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (_type) {
|
|
||||||
case BODY_STATIC -> this.rigidBody.setType(BodyType.STATIC);
|
|
||||||
case BODY_KINEMATIC -> this.rigidBody.setType(BodyType.KINEMATIC);
|
|
||||||
case BODY_DYNAMIC -> this.rigidBody.setType(BodyType.DYNAMIC);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the linear velocity (whole world).
|
|
||||||
* @param _linearVelocity The linear velocity vector of the body
|
|
||||||
*/
|
|
||||||
public void setLinearVelocity(final Vector3f _linearVelocity) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.setLinearVelocity(_linearVelocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the angular velocity (local Body).
|
|
||||||
* @param _angularVelocity The angular velocity vector of the body
|
|
||||||
*/
|
|
||||||
public void setRelativeAngularVelocity(final Vector3f _angularVelocity) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Vector3f value = this.rigidBody.getTransform().getOrientation().multiply(_angularVelocity);
|
|
||||||
this.rigidBody.setAngularVelocity(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the linear velocity (local Body).
|
|
||||||
* @param _linearVelocity The linear velocity vector of the body
|
|
||||||
*/
|
|
||||||
public void setRelativeLinearVelocity(final Vector3f _linearVelocity) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Vector3f value = this.rigidBody.getTransform().getOrientation().multiply(_linearVelocity);
|
|
||||||
this.rigidBody.setLinearVelocity(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShape(final List<Shape> _prop) {
|
|
||||||
this.shape = _prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSleepingEnable(final boolean value) {
|
|
||||||
this.rigidBody.setIsAllowedToSleep(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set a new transformation
|
|
||||||
* @param _transform transformation of the position
|
|
||||||
*/
|
|
||||||
public void setTransform(final Transform3D _transform) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.rigidBody.setTransform(_transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
// call of this function every time the call will be done
|
|
||||||
public void update(final float _delta) {
|
|
||||||
if (this.rigidBody == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.staticForceApplyCenterOfMass.isZero()) {
|
|
||||||
final Vector3f tmp = this.staticForceApplyCenterOfMass.multiply(_delta);
|
|
||||||
Log.error("FORCE : " + tmp);
|
|
||||||
this.rigidBody.applyForceToCenterOfMass(tmp);
|
|
||||||
}
|
|
||||||
if (!this.staticTorqueApply.isZero()) {
|
|
||||||
final Vector3f tmp = this.staticTorqueApply.multiply(_delta);
|
|
||||||
Log.error("TORQUE : " + tmp);
|
|
||||||
this.rigidBody.applyTorque(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,227 +0,0 @@
|
|||||||
package org.atriasoft.ege.engines;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
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.ComponentPhysics;
|
|
||||||
import org.atriasoft.ege.internal.Log;
|
|
||||||
import org.atriasoft.ephysics.body.RigidBody;
|
|
||||||
import org.atriasoft.ephysics.collision.ContactManifold;
|
|
||||||
import org.atriasoft.ephysics.collision.shapes.AABB;
|
|
||||||
import org.atriasoft.ephysics.constraint.ContactPoint;
|
|
||||||
import org.atriasoft.ephysics.constraint.ContactPointInfo;
|
|
||||||
import org.atriasoft.ephysics.engine.DynamicsWorld;
|
|
||||||
import org.atriasoft.ephysics.engine.EventListener;
|
|
||||||
import org.atriasoft.ephysics.engine.Island;
|
|
||||||
import org.atriasoft.etk.Color;
|
|
||||||
import org.atriasoft.etk.math.Matrix4f;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
|
||||||
|
|
||||||
public class EnginePhysics extends Engine implements EventListener {
|
|
||||||
public static final String ENGINE_NAME = "physics";
|
|
||||||
// Constant physics time step
|
|
||||||
private static final float TIME_STEP = 0.016f;//1.0f / 60.0f;
|
|
||||||
boolean propertyDebugAABB = false;
|
|
||||||
boolean propertyDebugShape = false;
|
|
||||||
// Start engine with no gravity
|
|
||||||
private final Vector3f gravity = new Vector3f(0.0f, 0.0f, 0.0f);
|
|
||||||
private float accumulator = 0;
|
|
||||||
//private final EngineGravity gravity;
|
|
||||||
private final DynamicsWorld dynamicsWorld;
|
|
||||||
|
|
||||||
private final Vector<ComponentPhysics> components = new Vector<>();
|
|
||||||
|
|
||||||
private final ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create();
|
|
||||||
|
|
||||||
public EnginePhysics(final Environement env) {
|
|
||||||
super(env);
|
|
||||||
/*
|
|
||||||
this.gravity = (EngineGravity) env.getEngine("gravity");
|
|
||||||
if (this.gravity == null) {
|
|
||||||
Log.critical("Must initialyse Gravity before physics...");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
final Vector3f gravity = new Vector3f(0.0f, 0.0f, 0.0f);
|
|
||||||
this.dynamicsWorld = new DynamicsWorld(gravity);
|
|
||||||
// Set the number of iterations of the constraint solver
|
|
||||||
this.dynamicsWorld.setNbIterationsVelocitySolver(15);
|
|
||||||
this.dynamicsWorld.setEventListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyForces(final float timeStep) {
|
|
||||||
for (final ComponentPhysics it : this.components) {
|
|
||||||
//it.applyForces(TIME_STEP, gravity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beginContact(final ContactPointInfo contact) {
|
|
||||||
ComponentPhysics component1 = null;
|
|
||||||
ComponentPhysics component2 = null;
|
|
||||||
// Called when a new contact point is found between two bodies that were separated before.
|
|
||||||
Log.warning("collision detection [BEGIN] " + contact.localPoint1 + " depth=" + contact.penetrationDepth);
|
|
||||||
if (contact.shape1 != null && contact.shape1.getUserData() != null) {
|
|
||||||
component1 = (ComponentPhysics) contact.shape1.getUserData();
|
|
||||||
}
|
|
||||||
if (contact.shape2 != null && contact.shape2.getUserData() != null) {
|
|
||||||
component2 = (ComponentPhysics) contact.shape2.getUserData();
|
|
||||||
}
|
|
||||||
if (component1 != null) {
|
|
||||||
component1.beginContact(component2, contact.normal, contact.localPoint1, contact.localPoint2, contact.penetrationDepth);
|
|
||||||
}
|
|
||||||
if (component2 != null) {
|
|
||||||
component2.beginContact(component1, contact.normal.multiply(-1), contact.localPoint2, contact.localPoint1, contact.penetrationDepth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beginInternalTick() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentAdd(final Component ref) {
|
|
||||||
if (!(ref instanceof ComponentPhysics elem)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.components.add(elem);
|
|
||||||
elem.generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentRemove(final Component ref) {
|
|
||||||
this.components.remove(ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endInternalTick() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DynamicsWorld getDynamicsWorld() {
|
|
||||||
return this.dynamicsWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getType() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return ENGINE_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void newContact(final ContactPointInfo contact) {
|
|
||||||
|
|
||||||
ComponentPhysics component1 = null;
|
|
||||||
ComponentPhysics component2 = null;
|
|
||||||
//Called when a new contact point is found between two bodies.
|
|
||||||
Log.warning("collision detection [ NEW ] " + contact.localPoint1 + " depth=" + contact.penetrationDepth);
|
|
||||||
if (contact.shape1 != null && contact.shape1.getUserData() != null) {
|
|
||||||
component1 = (ComponentPhysics) contact.shape1.getUserData();
|
|
||||||
}
|
|
||||||
if (contact.shape2 != null && contact.shape2.getUserData() != null) {
|
|
||||||
component2 = (ComponentPhysics) contact.shape2.getUserData();
|
|
||||||
}
|
|
||||||
if (component1 != null) {
|
|
||||||
component1.newContact(component2, contact.normal, contact.localPoint1, contact.localPoint2, contact.penetrationDepth);
|
|
||||||
}
|
|
||||||
if (component2 != null) {
|
|
||||||
component2.newContact(component1, contact.normal.multiply(-1), contact.localPoint2, contact.localPoint1, contact.penetrationDepth);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(final long deltaMili, final Camera camera) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
for (final ComponentPhysics it : this.components) {
|
|
||||||
//Log.info("Render " + it);
|
|
||||||
it.renderDebug(this.debugDrawProperty, camera);
|
|
||||||
}
|
|
||||||
//debugDrawProperty.drawCone(2, 5, 9, 12, Matrix4f.identity(), new Color(1,1,0,1));
|
|
||||||
//debugDrawProperty.drawSquare(new Vector3f(1,1,1), Matrix4f.identity(), new Color(1,1,0,1));
|
|
||||||
//debugDrawProperty.drawCubeLine(new Vector3f(1,1,1), new Vector3f(5,5,5), new Color(1,0,1,1), Matrix4f.identity(), true, true);
|
|
||||||
//debugDrawProperty.drawCubeLine(new Vector3f(0,0,0), new Vector3f(32,32,32), new Color(1,0,1,1), Matrix4f.identity(), true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderDebug(final long deltaMili, final Camera camera) {
|
|
||||||
if (this.propertyDebugShape) {
|
|
||||||
for (final ComponentPhysics it : this.components) {
|
|
||||||
it.drawShape(this.debugDrawProperty, camera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.propertyDebugAABB) {
|
|
||||||
for (final ComponentPhysics it : this.components) {
|
|
||||||
it.renderDebug(this.debugDrawProperty, camera);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Matrix4f transformationMatrix = Matrix4f.IDENTITY;
|
|
||||||
final Color tmpColor = new Color(0.0f, 0.0f, 1.0f, 0.8f);
|
|
||||||
final List<Island> islands = this.dynamicsWorld.getIslands();
|
|
||||||
for (final Island it : islands) {
|
|
||||||
// TODO compute island AABB to display it ...
|
|
||||||
final AABB islandElements = new AABB();
|
|
||||||
for (final RigidBody elem : it.getBodies()) {
|
|
||||||
final AABB tmp = elem.getAABB();
|
|
||||||
islandElements.mergeWithAABB(tmp);
|
|
||||||
}
|
|
||||||
this.debugDrawProperty.drawCubeLine(islandElements.getMin(), islandElements.getMax(), tmpColor, transformationMatrix, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<ContactManifold> listContact = this.dynamicsWorld.getContactsList();
|
|
||||||
//Log.info("nb contact: " + listContact.size());
|
|
||||||
for (final ContactManifold it : listContact) {
|
|
||||||
for (int iii = 0; iii < it.getNbContactPoints(); iii++) {
|
|
||||||
final ContactPoint contact = it.getContactPoint(iii);
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(contact.getWorldPointOnBody1())), new Color(0, 1, 0, 1));
|
|
||||||
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.IDENTITY.multiply(Matrix4f.createMatrixTranslate(contact.getWorldPointOnBody2())), new Color(0, 1, 0, 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGravity(final Vector3f _axePower) {
|
|
||||||
if (this.dynamicsWorld != null) {
|
|
||||||
final Vector3f gravity = _axePower;
|
|
||||||
this.dynamicsWorld.setGravity(gravity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(long deltaMili) {
|
|
||||||
//Log.error("=================================================================" + deltaMili);
|
|
||||||
if (deltaMili > 1000) {
|
|
||||||
deltaMili = (long) (TIME_STEP * 1000.0f);
|
|
||||||
}
|
|
||||||
final float deltaTime = deltaMili * 0.0001f;
|
|
||||||
// Add the time difference in the accumulator
|
|
||||||
this.accumulator += deltaTime;
|
|
||||||
// While there is enough accumulated time to take one or several physics steps
|
|
||||||
while (this.accumulator >= TIME_STEP) {
|
|
||||||
//Log.error("---------------------------------------------------" + TIME_STEP);
|
|
||||||
if (this.dynamicsWorld != null) {
|
|
||||||
// call every object to usdate their constant forces applied
|
|
||||||
for (final ComponentPhysics it : this.components) {
|
|
||||||
if (it != null) {
|
|
||||||
it.update(TIME_STEP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Update the Dynamics world with a constant time step
|
|
||||||
Log.debug("Update the Physic engine ... " + TIME_STEP);
|
|
||||||
this.dynamicsWorld.update(TIME_STEP);
|
|
||||||
}
|
|
||||||
// Decrease the accumulated time
|
|
||||||
this.accumulator -= TIME_STEP;
|
|
||||||
}
|
|
||||||
for (final ComponentPhysics elem : this.components) {
|
|
||||||
elem.emitAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user