[DEV] update new physics
This commit is contained in:
parent
711ef047fc
commit
c6a1a0b615
@ -22,7 +22,7 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-gale">
|
<classpathentry combineaccessrules="false" kind="src" path="/scenarium-logger">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
@ -32,7 +32,12 @@
|
|||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/scenarium-logger">
|
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-gale">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/jReactPhysics3D">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -9,9 +9,10 @@ open module org.atriasoft.gameengine {
|
|||||||
exports org.atriasoft.gameengine.engines;
|
exports org.atriasoft.gameengine.engines;
|
||||||
exports org.atriasoft.gameengine.geometry;
|
exports org.atriasoft.gameengine.geometry;
|
||||||
exports org.atriasoft.gameengine.map;
|
exports org.atriasoft.gameengine.map;
|
||||||
exports org.atriasoft.gameengine.physics;
|
exports org.atriasoft.gameengine.physics.shape;
|
||||||
exports org.atriasoft.gameengine.resource;
|
exports org.atriasoft.gameengine.resource;
|
||||||
|
|
||||||
requires transitive org.atriasoft.gale;
|
requires transitive org.atriasoft.gale;
|
||||||
requires transitive org.atriasoft.etk;
|
requires transitive org.atriasoft.etk;
|
||||||
|
requires transitive net.jreactphysics3d;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,7 @@
|
|||||||
|
package org.atriasoft.gameengine.components;
|
||||||
|
|
||||||
|
public enum PhysicBodyType {
|
||||||
|
BODY_DYNAMIC,
|
||||||
|
BODY_STATIC,
|
||||||
|
BODY_KINEMATIC,
|
||||||
|
}
|
@ -2,150 +2,192 @@ package org.atriasoft.gameengine.engines;
|
|||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
||||||
import org.atriasoft.gameengine.internal.Log;
|
|
||||||
import org.atriasoft.gameengine.Component;
|
import org.atriasoft.gameengine.Component;
|
||||||
import org.atriasoft.gameengine.Engine;
|
import org.atriasoft.gameengine.Engine;
|
||||||
import org.atriasoft.gameengine.Environement;
|
import org.atriasoft.gameengine.Environement;
|
||||||
import org.atriasoft.gameengine.camera.Camera;
|
import org.atriasoft.gameengine.camera.Camera;
|
||||||
import org.atriasoft.gameengine.components.ComponentPhysics;
|
import org.atriasoft.gameengine.components.ComponentPhysics;
|
||||||
import org.atriasoft.gameengine.physics.PhysicCollisionAABB;
|
import org.atriasoft.gameengine.internal.Log;
|
||||||
|
|
||||||
public class EnginePhysics extends Engine {
|
import net.jreactphysics3d.constraint.ContactPointInfo;
|
||||||
|
import net.jreactphysics3d.engine.DynamicsWorld;
|
||||||
|
import net.jreactphysics3d.engine.EventListener;
|
||||||
|
|
||||||
|
public class EnginePhysics extends Engine implements EventListener {
|
||||||
public static final String ENGINE_NAME = "physics";
|
public static final String ENGINE_NAME = "physics";
|
||||||
|
// Constant physics time step
|
||||||
|
private static final float TIME_STEP = 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 float accumulator = 0;
|
||||||
private static final float TIME_STEP = 0.005f;
|
//private final EngineGravity gravity;
|
||||||
private EngineGravity gravity;
|
private final DynamicsWorld dynamicsWorld;
|
||||||
private Vector<ComponentPhysics> components = new Vector<ComponentPhysics>();
|
|
||||||
private ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create();
|
|
||||||
|
|
||||||
public EnginePhysics(Environement env) {
|
private final Vector<ComponentPhysics> components = new Vector<ComponentPhysics>();
|
||||||
|
|
||||||
|
private final ResourceColored3DObject debugDrawProperty = ResourceColored3DObject.create();
|
||||||
|
|
||||||
|
public EnginePhysics(final Environement env) {
|
||||||
super(env);
|
super(env);
|
||||||
this.gravity = (EngineGravity)env.getEngine("gravity");
|
/*
|
||||||
|
this.gravity = (EngineGravity) env.getEngine("gravity");
|
||||||
if (this.gravity == null) {
|
if (this.gravity == null) {
|
||||||
Log.critical("Must initialyse Gravity before physics...");
|
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
|
@Override
|
||||||
public void componentRemove(Component ref) {
|
public void beginContact(final ContactPointInfo contact) {
|
||||||
components.remove(ref);
|
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.multiplyNew(-1), contact.localPoint2, contact.localPoint1, contact.penetrationDepth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void componentAdd(Component ref) {
|
public void beginInternalTick() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentAdd(final Component ref) {
|
||||||
if (ref instanceof ComponentPhysics == false) {
|
if (ref instanceof ComponentPhysics == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
components.add((ComponentPhysics)ref);
|
final ComponentPhysics elem = (ComponentPhysics) ref;
|
||||||
|
this.components.add(elem);
|
||||||
|
elem.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(long deltaMili) {
|
public void componentRemove(final Component ref) {
|
||||||
// Add the time difference in the accumulator
|
this.components.remove(ref);
|
||||||
accumulator += (float)deltaMili*0.0001f;
|
|
||||||
// While there is enough accumulated time to take one or several physics steps
|
|
||||||
while (accumulator >= TIME_STEP) {
|
|
||||||
Log.info("update physic ... " + accumulator);
|
|
||||||
//applyForces(TIME_STEP);
|
|
||||||
updateAABB(TIME_STEP);
|
|
||||||
updateCollisionsAABB(TIME_STEP);
|
|
||||||
updateCollisionsNarrowPhase(TIME_STEP);
|
|
||||||
generateResultCollisionsForces(TIME_STEP);
|
|
||||||
// Decrease the accumulated time
|
|
||||||
accumulator -= TIME_STEP;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyForces(float timeStep) {
|
|
||||||
for (ComponentPhysics it: components) {
|
|
||||||
it.applyForces(TIME_STEP, gravity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Collision detection STEP 1: Upadte the AABB positioning of each elements
|
|
||||||
* @param timeStep Delta time since the last check
|
|
||||||
*/
|
|
||||||
private void updateAABB(float timeStep) {
|
|
||||||
for (ComponentPhysics it: components) {
|
|
||||||
it.updateAABB();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Collision Detection STEP 2: update the list of each element that collide together in the AABB Boxs (update is done between each boxes)
|
|
||||||
* @param timeStep Delta time since the last check
|
|
||||||
*/
|
|
||||||
private void updateCollisionsAABB(float timeStep) {
|
|
||||||
// clear all object intersection
|
|
||||||
for (ComponentPhysics it: components) {
|
|
||||||
it.clearAABBIntersection();
|
|
||||||
}
|
|
||||||
// update the current object intersection...
|
|
||||||
for (int iii=0; iii< components.size(); iii++) {
|
|
||||||
ComponentPhysics current = components.get(iii);
|
|
||||||
PhysicCollisionAABB currentAABB = current.getAABB();
|
|
||||||
for (int jjj=iii+1; jjj< components.size(); jjj++) {
|
|
||||||
ComponentPhysics remote = components.get(jjj);
|
|
||||||
if (currentAABB.intersect(components.get(jjj).getAABB()) == true) {
|
|
||||||
current.addIntersection(remote);
|
|
||||||
remote.addIntersection(current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Collision Detection STEP 3: Narrow phase: process the collision between every OBB boxes (or other..)
|
|
||||||
* @param timeStep Delta time since the last check
|
|
||||||
*/
|
|
||||||
private void updateCollisionsNarrowPhase(float timeStep) {
|
|
||||||
// clear all object intersection
|
|
||||||
for (ComponentPhysics it: components) {
|
|
||||||
it.updateForNarrowCollision();
|
|
||||||
}
|
|
||||||
// check for every component if the narrow collision is available.
|
|
||||||
for (int iii=0; iii< components.size(); iii++) {
|
|
||||||
ComponentPhysics current = components.get(iii);
|
|
||||||
boolean collide = current.checkNarrowCollision();
|
|
||||||
|
|
||||||
}
|
|
||||||
// update the force of collision available.
|
|
||||||
for (int iii=0; iii< components.size(); iii++) {
|
|
||||||
ComponentPhysics current = components.get(iii);
|
|
||||||
current.narrowCollisionCreateContactAndForce();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Collision Detection STEP 4: apply all calculated forces (with containts)
|
|
||||||
* @param timeStep
|
|
||||||
*/
|
|
||||||
private void generateResultCollisionsForces(float timeStep) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(long deltaMili, Camera camera) {
|
public void endInternalTick() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
for (ComponentPhysics it: this.components) {
|
|
||||||
//Log.info("Render " + it);
|
|
||||||
it.renderDebug(debugDrawProperty);
|
|
||||||
}
|
|
||||||
//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(long deltaMili, Camera camera) {
|
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DynamicsWorld getDynamicsWorld() {
|
||||||
|
return this.dynamicsWorld;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return ENGINE_NAME;
|
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.multiplyNew(-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 == true) {
|
||||||
|
for (final ComponentPhysics it : this.components) {
|
||||||
|
it.drawShape(this.debugDrawProperty, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.propertyDebugAABB == true) {
|
||||||
|
for (final ComponentPhysics it : this.components) {
|
||||||
|
it.renderDebug(this.debugDrawProperty, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setGravity(final Vector3f _axePower) {
|
||||||
|
if (this.dynamicsWorld != null) {
|
||||||
|
final Vector3f gravity = _axePower.clone();
|
||||||
|
this.dynamicsWorld.setGravity(gravity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(final long deltaMili) {
|
||||||
|
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) {
|
||||||
|
if (this.dynamicsWorld != null) {
|
||||||
|
// call every object to usdate their constant forces applyed
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,46 +15,54 @@ public class Log {
|
|||||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||||
|
|
||||||
private Log() {}
|
public static void critical(final String data) {
|
||||||
|
if (PRINT_CRITICAL) {
|
||||||
public static void print(String data) {
|
|
||||||
if (PRINT_PRINT)
|
|
||||||
Logger.print(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void todo(String data) {
|
|
||||||
if (PRINT_TODO)
|
|
||||||
Logger.todo(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void critical(String data) {
|
|
||||||
if (PRINT_CRITICAL)
|
|
||||||
Logger.critical(LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(String data) {
|
|
||||||
if (PRINT_ERROR)
|
|
||||||
Logger.error(LIB_NAME_DRAW, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(String data) {
|
public static void debug(final String data) {
|
||||||
if (PRINT_WARNING)
|
if (PRINT_DEBUG) {
|
||||||
Logger.warning(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(String data) {
|
|
||||||
if (PRINT_INFO)
|
|
||||||
Logger.info(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void debug(String data) {
|
|
||||||
if (PRINT_DEBUG)
|
|
||||||
Logger.debug(LIB_NAME_DRAW, data);
|
Logger.debug(LIB_NAME_DRAW, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(String data) {
|
|
||||||
if (PRINT_VERBOSE)
|
|
||||||
Logger.verbose(LIB_NAME_DRAW, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void error(final String data) {
|
||||||
|
if (PRINT_ERROR) {
|
||||||
|
Logger.error(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(final String data) {
|
||||||
|
if (PRINT_INFO) {
|
||||||
|
Logger.info(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void print(final String data) {
|
||||||
|
if (PRINT_PRINT) {
|
||||||
|
Logger.print(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void todo(final String data) {
|
||||||
|
if (PRINT_TODO) {
|
||||||
|
Logger.todo(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void verbose(final String data) {
|
||||||
|
if (PRINT_VERBOSE) {
|
||||||
|
Logger.verbose(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(final String data) {
|
||||||
|
if (PRINT_WARNING) {
|
||||||
|
Logger.warning(LIB_NAME_DRAW, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Log() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,6 @@ import org.atriasoft.gameengine.components.ComponentTexture;
|
|||||||
import org.atriasoft.gameengine.components.ComponentTextures;
|
import org.atriasoft.gameengine.components.ComponentTextures;
|
||||||
import org.atriasoft.gameengine.engines.EngineLight;
|
import org.atriasoft.gameengine.engines.EngineLight;
|
||||||
import org.atriasoft.gameengine.engines.EngineMap;
|
import org.atriasoft.gameengine.engines.EngineMap;
|
||||||
import org.atriasoft.gameengine.physics.PhysicBox;
|
|
||||||
import org.atriasoft.gameengine.physics.PhysicMapVoxel;
|
|
||||||
|
|
||||||
public class MapVoxel extends EngineMap {
|
public class MapVoxel extends EngineMap {
|
||||||
//List<VoxelChunk> listOfChunks = new ArrayList<VoxelChunk>();
|
//List<VoxelChunk> listOfChunks = new ArrayList<VoxelChunk>();
|
||||||
@ -75,9 +73,9 @@ public class MapVoxel extends EngineMap {
|
|||||||
new Uri("DATA", "basicMaterial.frag"),
|
new Uri("DATA", "basicMaterial.frag"),
|
||||||
(EngineLight)env.getEngine(EngineLight.ENGINE_NAME)));
|
(EngineLight)env.getEngine(EngineLight.ENGINE_NAME)));
|
||||||
ComponentPhysics physics = new ComponentPhysics(false);
|
ComponentPhysics physics = new ComponentPhysics(false);
|
||||||
PhysicMapVoxel box = new PhysicMapVoxel(tmpVoxelChunk);
|
//PhysicMapVoxel box = new PhysicMapVoxel(tmpVoxelChunk);
|
||||||
physics.addShape(box);
|
//physics.addShape(box);
|
||||||
physics.setStaticObject(true);
|
//physics.setStaticObject(true);
|
||||||
tmpEntity.addComponent(physics);
|
tmpEntity.addComponent(physics);
|
||||||
this.env.addEntity(tmpEntity);
|
this.env.addEntity(tmpEntity);
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
|
|
||||||
public class ColisionPoints {
|
|
||||||
public Vector3f position;
|
|
||||||
public Vector3f force;
|
|
||||||
|
|
||||||
public ColisionPoints(Vector3f position, Vector3f force) {
|
|
||||||
this.position = position;
|
|
||||||
this.force = force;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
public class Collision {
|
|
||||||
public final ColisionPoints[] colisionPointLocal;
|
|
||||||
public final PhysicShape shapeRemote;
|
|
||||||
public final ColisionPoints[] colisionPointRemote;
|
|
||||||
public final boolean staticRemote;
|
|
||||||
public Collision(ColisionPoints[] colisionPointLocal, PhysicShape shapeRemote,
|
|
||||||
ColisionPoints[] colisionPointRemote, boolean staticRemote) {
|
|
||||||
super();
|
|
||||||
this.colisionPointLocal = colisionPointLocal;
|
|
||||||
this.shapeRemote = shapeRemote;
|
|
||||||
this.colisionPointRemote = colisionPointRemote;
|
|
||||||
this.staticRemote = staticRemote;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
|
|
||||||
public abstract class GravityMap {
|
|
||||||
public abstract Vector3f getGravityAtPosition(Vector3f position);
|
|
||||||
}
|
|
@ -1,112 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.Color;
|
|
||||||
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.gameengine.internal.Log;
|
|
||||||
|
|
||||||
public class PhysicBox extends PhysicShape {
|
|
||||||
// Box size property in X, Y and Z
|
|
||||||
private Vector3f size = new Vector3f(1, 1, 1);
|
|
||||||
|
|
||||||
public PhysicBox() {
|
|
||||||
super(PhysicShapeType.BOX);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3f getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(Vector3f size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateAABB(Transform3D transformGlobal, PhysicCollisionAABB aabb) {
|
|
||||||
// store it, many time usefull...
|
|
||||||
this.transformGlobal = transformGlobal;
|
|
||||||
this.colisionPoints.clear();
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x * 0.5f, this.size.y * 0.5f, this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x * 0.5f, this.size.y * 0.5f, this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x * 0.5f, -this.size.y * 0.5f, this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x * 0.5f, -this.size.y * 0.5f, this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x * 0.5f, this.size.y * 0.5f, -this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x * 0.5f, this.size.y * 0.5f, -this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(-this.size.x * 0.5f, -this.size.y * 0.5f, -this.size.z * 0.5f))));
|
|
||||||
aabb.update(transformGlobal.multiply(this.transform.multiply(new Vector3f(this.size.x * 0.5f, -this.size.y * 0.5f, -this.size.z * 0.5f))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// only needed for the narrow phase calculation ...
|
|
||||||
public Vector3f narrowPhaseGlobalPos;
|
|
||||||
public Vector3f narrowPhaseAxisX = new Vector3f(1, 0, 0);
|
|
||||||
public Vector3f narrowPhaseAxisY = new Vector3f(1, 0, 0);
|
|
||||||
public Vector3f narrowPhaseAxisZ = new Vector3f(1, 0, 0);
|
|
||||||
public Vector3f narrowPhaseHalfSize;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateForNarrowCollision(Transform3D transformGlobal) {
|
|
||||||
this.narrowPhaseGlobalPos = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 0, 0)));
|
|
||||||
this.narrowPhaseAxisX = transformGlobal.multiply(this.transform.multiply(new Vector3f(1, 0, 0))).less(this.narrowPhaseGlobalPos);
|
|
||||||
this.narrowPhaseAxisY = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 1, 0))).less(this.narrowPhaseGlobalPos);
|
|
||||||
this.narrowPhaseAxisZ = transformGlobal.multiply(this.transform.multiply(new Vector3f(0, 0, 1))).less(this.narrowPhaseGlobalPos);
|
|
||||||
this.narrowPhaseHalfSize = this.size.multiplyNew(0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderPoint(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiplyNew(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
|
||||||
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.08f, 0.08f, 0.08f), transformation, new Color(0, 0, 1, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderPoint2(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiplyNew(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), transformation, new Color(0, 1, 0, 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderPoint3(Vector3f subPosition, Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
Matrix4f transformation = transformGlobal.getOpenGLMatrix().multiplyNew(this.transform.getOpenGLMatrix()).multiply(Matrix4f.createMatrixTranslate(subPosition));
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), transformation, new Color(1, 1, 0, 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderPoint4(Vector3f subPosition, Vector3f force, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.identity().multiply(Matrix4f.createMatrixTranslate(subPosition)), new Color(1, 0, 0, 1));
|
|
||||||
List<Vector3f> tmp = new ArrayList<>();
|
|
||||||
tmp.add(new Vector3f(0,0,0));
|
|
||||||
tmp.add(force);
|
|
||||||
debugDrawProperty.drawLine(tmp, new Color(1, 0, 0, 1), Matrix4f.identity().multiply(Matrix4f.createMatrixTranslate(subPosition)), true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renderDebug(Transform3D transformGlobal, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
debugDrawProperty.drawSquare(this.size.multiplyNew(0.5f), this.transform.getOpenGLMatrix().multiplyNew(transformGlobal.getOpenGLMatrix()), new Color(0, 1, 0, 0.25f));
|
|
||||||
Vector3f dimention = this.size.multiplyNew(0.5f);
|
|
||||||
renderPoint2(new Vector3f(+dimention.x, +dimention.y, +dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(-dimention.x, +dimention.y, +dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(+dimention.x, -dimention.y, +dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(-dimention.x, -dimention.y, +dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(+dimention.x, +dimention.y, -dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(-dimention.x, +dimention.y, -dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint(new Vector3f(+dimention.x, -dimention.y, -dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
renderPoint3(new Vector3f(-dimention.x, -dimention.y, -dimention.z), transformGlobal, debugDrawProperty);
|
|
||||||
for (Collision elem: this.colisionPoints) {
|
|
||||||
if (elem != null) {
|
|
||||||
if (elem.colisionPointLocal == null) {
|
|
||||||
Log.error("colision point must be set !!!");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (int iii = 0; iii < elem.colisionPointLocal.length; iii++) {
|
|
||||||
renderPoint4(elem.colisionPointLocal[iii].position, elem.colisionPointLocal[iii].force, debugDrawProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
|
|
||||||
public class PhysicCollisionAABB {
|
|
||||||
public float minX;
|
|
||||||
public float minY;
|
|
||||||
public float minZ;
|
|
||||||
public float maxX;
|
|
||||||
public float maxY;
|
|
||||||
public float maxZ;
|
|
||||||
public PhysicCollisionAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
|
|
||||||
super();
|
|
||||||
this.minX = minX;
|
|
||||||
this.minY = minY;
|
|
||||||
this.minZ = minZ;
|
|
||||||
this.maxX = maxX;
|
|
||||||
this.maxY = maxY;
|
|
||||||
this.maxZ = maxZ;
|
|
||||||
}
|
|
||||||
public boolean intersect(PhysicCollisionAABB other) {
|
|
||||||
if (this == other) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (minX > other.maxX) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (maxX < other.minX) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (minY > other.maxY) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (maxY < other.minY) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (minZ > other.maxZ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (maxZ < other.minZ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public void update(Vector3f point) {
|
|
||||||
if (minX > point.x) {
|
|
||||||
minX = point.x;
|
|
||||||
}
|
|
||||||
if (maxX < point.x) {
|
|
||||||
maxX = point.x;
|
|
||||||
}
|
|
||||||
if (minY > point.y) {
|
|
||||||
minY = point.y;
|
|
||||||
}
|
|
||||||
if (maxY < point.y) {
|
|
||||||
maxY = point.y;
|
|
||||||
}
|
|
||||||
if (minZ > point.z) {
|
|
||||||
minZ = point.z;
|
|
||||||
}
|
|
||||||
if (maxZ < point.z) {
|
|
||||||
maxZ = point.z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Vector3f getMin() {
|
|
||||||
return new Vector3f(minX, minY, minZ);
|
|
||||||
}
|
|
||||||
public Vector3f getMax() {
|
|
||||||
return new Vector3f(maxX, maxY, maxZ);
|
|
||||||
}
|
|
||||||
public static PhysicCollisionAABB beforeCalculated() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return new PhysicCollisionAABB(999999,999999,999999,-999999,-999999,-999999);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Transform3D;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
|
||||||
import org.atriasoft.gameengine.map.VoxelChunk;
|
|
||||||
|
|
||||||
public class PhysicMapVoxel extends PhysicShape {
|
|
||||||
// Box size property in X, Y and Z
|
|
||||||
private VoxelChunk chunk;
|
|
||||||
public PhysicMapVoxel(VoxelChunk chunk) {
|
|
||||||
super(PhysicShapeType.MAP_VOXEL);
|
|
||||||
this.chunk = chunk;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateAABB(Transform3D transform, PhysicCollisionAABB aabb) {
|
|
||||||
if (this.chunk == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.colisionPoints.clear();
|
|
||||||
aabb.update(new Vector3f(this.chunk.getPosition().x,this.chunk.getPosition().y,this.chunk.getPosition().z));
|
|
||||||
aabb.update(new Vector3f(
|
|
||||||
this.chunk.getPosition().x + VoxelChunk.VOXEL_CHUNK_SIZE,
|
|
||||||
this.chunk.getPosition().y + VoxelChunk.VOXEL_CHUNK_SIZE,
|
|
||||||
this.chunk.getPosition().z + VoxelChunk.VOXEL_CHUNK_SIZE));
|
|
||||||
}
|
|
||||||
// only needed for the narrow phase calculation ...
|
|
||||||
private Vector3f narrowPhaseGlobalPos;
|
|
||||||
private Vector3f narrowPhaseAxisX = new Vector3f(1,0,0);
|
|
||||||
private Vector3f narrowPhaseAxisY = new Vector3f(1,0,0);
|
|
||||||
private Vector3f narrowPhaseAxisZ = new Vector3f(1,0,0);
|
|
||||||
private Vector3f narrowPhaseHalfSize = new Vector3f(0.5f,0.5f,0.5f);
|
|
||||||
@Override
|
|
||||||
public void updateForNarrowCollision(Transform3D transform) {
|
|
||||||
this.narrowPhaseGlobalPos = transform.multiply(this.transform.multiply(new Vector3f(0,0,0)));
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void renderDebug(Transform3D transform, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,101 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Quaternion;
|
|
||||||
import org.atriasoft.etk.math.Transform3D;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class PhysicShape {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected List<Collision> colisionPoints = new ArrayList<>();
|
|
||||||
// protected Quaternion quaternion;
|
|
||||||
// protected Vector3f origin;
|
|
||||||
protected Transform3D transform;
|
|
||||||
protected Transform3D transformGlobal;
|
|
||||||
protected float mass = 0;
|
|
||||||
protected final PhysicShapeType type;
|
|
||||||
|
|
||||||
public PhysicShape(PhysicShapeType type) {
|
|
||||||
this.type = type;
|
|
||||||
this.transform = new Transform3D();
|
|
||||||
// this.quaternion = Quaternion.identity();
|
|
||||||
// this.origin = Vector3f.zero();
|
|
||||||
this.mass = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PhysicShape(PhysicShapeType type, Quaternion quaternion, Vector3f origin, float mass) {
|
|
||||||
this.type = type;
|
|
||||||
this.transform = new Transform3D(origin, quaternion);
|
|
||||||
// this.quaternion = quaternion;
|
|
||||||
// this.origin = origin;
|
|
||||||
this.mass = mass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Quaternion getQuaternionFull() {
|
|
||||||
return transformGlobal.getOrientation().multiplyNew(transform.getOrientation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Quaternion getQuaternion() {
|
|
||||||
return transform.getOrientation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuaternion(Quaternion quaternion) {
|
|
||||||
this.transform.setOrientation(quaternion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vector3f getOrigin() {
|
|
||||||
return this.transform.getPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrigin(Vector3f origin) {
|
|
||||||
this.transform.setPosition(origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Transform3D getTransform() {
|
|
||||||
return transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransform(Transform3D transform) {
|
|
||||||
this.transform = transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Transform3D getTransformGlobal() {
|
|
||||||
return transformGlobal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransformGlobal(Transform3D transform) {
|
|
||||||
this.transformGlobal = transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMass() {
|
|
||||||
return mass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMass(float mass) {
|
|
||||||
this.mass = mass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PhysicShapeType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addColision(Collision colision) {
|
|
||||||
colisionPoints.add(colision);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract void updateAABB(Transform3D transform, PhysicCollisionAABB aabb);
|
|
||||||
|
|
||||||
public abstract void updateForNarrowCollision(Transform3D transform);
|
|
||||||
|
|
||||||
public abstract void renderDebug(Transform3D transform, ResourceColored3DObject debugDrawProperty);
|
|
||||||
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
public enum PhysicShapeType {
|
|
||||||
UNKNOWN,
|
|
||||||
BOX,
|
|
||||||
CAPSULE,
|
|
||||||
CONE,
|
|
||||||
CONVEXHULL,
|
|
||||||
CYLINDER,
|
|
||||||
SPHERE,
|
|
||||||
CONCAVE,
|
|
||||||
MAP_VOXEL
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.Color;
|
|
||||||
import org.atriasoft.etk.math.Transform3D;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gale.resource.ResourceColored3DObject;
|
|
||||||
|
|
||||||
public class PhysicSphere extends PhysicShape {
|
|
||||||
// Box size property in X, Y and Z
|
|
||||||
private float size;
|
|
||||||
public PhysicSphere() {
|
|
||||||
super(PhysicShapeType.SPHERE);
|
|
||||||
}
|
|
||||||
public float getSize() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
public void setSize(float size) {
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateAABB(Transform3D transform, PhysicCollisionAABB aabb) {
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(this.size,0,0)));
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(-this.size,0,0)));
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(0,this.size,0)));
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(0,-this.size,0)));
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(0,0,this.size)));
|
|
||||||
aabb.update(transform.multiply(this.transform.getPosition()).addNew(new Vector3f(0,0,-this.size)));
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void updateForNarrowCollision(Transform3D transform) {
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void renderDebug(Transform3D transform, ResourceColored3DObject debugDrawProperty) {
|
|
||||||
debugDrawProperty.drawSphere(this.size, 9, 9, this.transform.getOpenGLMatrix().multiplyNew(transform.getOpenGLMatrix()), new Color(0,1,0,1));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,377 +0,0 @@
|
|||||||
package org.atriasoft.gameengine.physics;
|
|
||||||
|
|
||||||
import org.atriasoft.etk.math.Quaternion;
|
|
||||||
import org.atriasoft.etk.math.Vector3f;
|
|
||||||
import org.atriasoft.gameengine.internal.Log;
|
|
||||||
import org.atriasoft.gameengine.samples.LoxelEngine.LoxelApplication;
|
|
||||||
|
|
||||||
// set the relevant elements of our oriented bounding box
|
|
||||||
class OBB {
|
|
||||||
public Vector3f position;
|
|
||||||
public Vector3f axisX;
|
|
||||||
public Vector3f axisY;
|
|
||||||
public Vector3f axisZ;
|
|
||||||
public Vector3f halfSize;
|
|
||||||
|
|
||||||
public OBB() {
|
|
||||||
position = new Vector3f();
|
|
||||||
axisX = new Vector3f();
|
|
||||||
axisY = new Vector3f();
|
|
||||||
axisZ = new Vector3f();
|
|
||||||
halfSize = new Vector3f();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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.multiplyNew(box1.halfSize.x).dot(plane)) + Math.abs(box1.axisY.multiplyNew(box1.halfSize.y).dot(plane))
|
|
||||||
+ Math.abs(box1.axisZ.multiplyNew(box1.halfSize.z).dot(plane)) + Math.abs(box2.axisX.multiplyNew(box2.halfSize.x).dot(plane))
|
|
||||||
+ Math.abs(box2.axisY.multiplyNew(box2.halfSize.y).dot(plane)) + Math.abs(box2.axisZ.multiplyNew(box2.halfSize.z).dot(plane))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// test for separating planes in all 15 axes
|
|
||||||
private static boolean getCollision(OBB box1, OBB box2) {
|
|
||||||
Vector3f rPos = box2.position.lessNew(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.multiplyNew(box1.narrowPhaseHalfSize.x).dot(plane))
|
|
||||||
+ Math.abs(box1.narrowPhaseAxisY.multiplyNew(box1.narrowPhaseHalfSize.y).dot(plane)) + Math.abs(box1.narrowPhaseAxisZ.multiplyNew(box1.narrowPhaseHalfSize.z).dot(plane))
|
|
||||||
+ Math.abs(box2.narrowPhaseAxisX.multiplyNew(box2.narrowPhaseHalfSize.x).dot(plane)) + Math.abs(box2.narrowPhaseAxisY.multiplyNew(box2.narrowPhaseHalfSize.y).dot(plane))
|
|
||||||
+ Math.abs(box2.narrowPhaseAxisZ.multiplyNew(box2.narrowPhaseHalfSize.z).dot(plane))));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean testCollide(PhysicBox box1, PhysicBox box2) {
|
|
||||||
|
|
||||||
Vector3f rPos = box2.narrowPhaseGlobalPos.lessNew(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.lessNew(box2.narrowPhaseGlobalPos);
|
|
||||||
Vector3f rPos2 = box2.narrowPhaseGlobalPos.lessNew(box1.narrowPhaseGlobalPos);
|
|
||||||
Quaternion quat1 = box1.getQuaternionFull();
|
|
||||||
Quaternion quat2 = box2.getQuaternionFull();
|
|
||||||
// Step 1: set the Box 2 in the repere of the Box 1:
|
|
||||||
Quaternion quatTransfer1 = Quaternion.diff(quat1, quat2);
|
|
||||||
Quaternion quatTransfer2 = Quaternion.diff(quat2, quat1);
|
|
||||||
// quatTransfer.normalize();
|
|
||||||
|
|
||||||
// LoxelApplication.relativeTest = quatTransfer;
|
|
||||||
// Vector3f tmp = rPos.addNew(new Vector3f(0,0,14));
|
|
||||||
// LoxelApplication.relativeTestPos.getTransform().setPosition(tmp);
|
|
||||||
// LoxelApplication.relativeTestPos.getTransform().setOrientation(quatTransfer);
|
|
||||||
// LoxelApplication.boxTest.setSize(box1.getSize());
|
|
||||||
// Log.info("" + rPos + quatTransfer1);
|
|
||||||
// /*res = */getCollidePointsAABBCenteredWithOBB(box1.narrowPhaseHalfSize, box2.narrowPhaseHalfSize, quatTransfer, rPos);
|
|
||||||
/* res = transfert in generic plan the new res ... */
|
|
||||||
// test origin AABB with OBB collision
|
|
||||||
// Step 2: set the Box 1 in the repere of the Box 2:
|
|
||||||
// test origin AABB with OBB collision
|
|
||||||
// tmp = rPos.addNew(new Vector3f(0,0,14));
|
|
||||||
LoxelApplication.testRpos = quat2.inverseNew().getMatrix4().multiply(rPos1);
|
|
||||||
LoxelApplication.testQTransfert = quatTransfer2;
|
|
||||||
LoxelApplication.box1HalfSize = box2.narrowPhaseHalfSize;
|
|
||||||
LoxelApplication.box2HalfSize = box1.narrowPhaseHalfSize;
|
|
||||||
|
|
||||||
// LoxelApplication.relativeTestPos.getTransform().setPosition(tmp);
|
|
||||||
// LoxelApplication.relativeTestPos.getTransform().setOrientation(quatTransfer);
|
|
||||||
// LoxelApplication.boxTest.setSize(box1.getSize());
|
|
||||||
// foinctionne avec la box qui n'est pas orienter...
|
|
||||||
// getCollidePointsAABBCenteredWithOBB(box2.narrowPhaseHalfSize, box1.narrowPhaseHalfSize, quatTransfer2, rPos1);
|
|
||||||
// fonctionne quand le block est trourner de 90% petit pb de positionnement en hauteur....
|
|
||||||
// getCollidePointsAABBCenteredWithOBB(box2.narrowPhaseHalfSize, box1.narrowPhaseHalfSize, quatTransfer2, quat2.multiply(rPos2));
|
|
||||||
ColisionPoints[] collide1 = getCollidePointsAABBCenteredWithOBB(box2.narrowPhaseHalfSize, box1.narrowPhaseHalfSize, quatTransfer2, quat2.inverseNew().getMatrix4().multiply(rPos1));
|
|
||||||
// transfer detection point collision in global environement:
|
|
||||||
if (collide1 != null) {
|
|
||||||
for (int iii = 0; iii < collide1.length; iii++) {
|
|
||||||
collide1[iii].position = quat1.multiply(collide1[iii].position).add(box1.narrowPhaseGlobalPos);
|
|
||||||
collide1[iii].force = quat2.multiply(collide1[iii].force);//.add(box1.narrowPhaseGlobalPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* res = trensfert in generic plan the new res ... */
|
|
||||||
|
|
||||||
LoxelApplication.testRpos = quat1.inverseNew().getMatrix4().multiply(rPos2);
|
|
||||||
LoxelApplication.testQTransfert = quatTransfer1;
|
|
||||||
LoxelApplication.box1HalfSize = box1.narrowPhaseHalfSize;
|
|
||||||
LoxelApplication.box2HalfSize = box2.narrowPhaseHalfSize;
|
|
||||||
ColisionPoints[] collide2 = getCollidePointsAABBCenteredWithOBB(box1.narrowPhaseHalfSize, box2.narrowPhaseHalfSize, quatTransfer1, quat1.inverseNew().getMatrix4().multiply(rPos2));
|
|
||||||
if (collide2 != null) {
|
|
||||||
for (int iii = 0; iii < collide2.length; iii++) {
|
|
||||||
collide2[iii].position = quat2.multiply(collide2[iii].position).add(box2.narrowPhaseGlobalPos);
|
|
||||||
collide2[iii].force = quat1.multiply(collide2[iii].force);//.add(box2.narrowPhaseGlobalPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add only if NOT static, when static no colision is performed
|
|
||||||
if (true) { //!isStatic1) {
|
|
||||||
Collision colision = new Collision(collide1, box2, collide2, isStatic2);
|
|
||||||
box1.addColision(colision);
|
|
||||||
}
|
|
||||||
if (true) { //!isStatic1) {
|
|
||||||
Collision colision = new Collision(collide2, box1, collide1, isStatic1);
|
|
||||||
box2.addColision(colision);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ColisionPoints[] 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);
|
|
||||||
Vector3f topFrontRight = box2Orientation.multiply(new Vector3f(+box2HalfSize.x, -box2HalfSize.y, +box2HalfSize.z)).add(box2Position);
|
|
||||||
Vector3f topFrontLeft = box2Orientation.multiply(new Vector3f(-box2HalfSize.x, -box2HalfSize.y, +box2HalfSize.z)).add(box2Position);
|
|
||||||
Vector3f bottomBackRight = box2Orientation.multiply(new Vector3f(+box2HalfSize.x, +box2HalfSize.y, -box2HalfSize.z)).add(box2Position);
|
|
||||||
Vector3f bottomBackLeft = box2Orientation.multiply(new Vector3f(-box2HalfSize.x, +box2HalfSize.y, -box2HalfSize.z)).add(box2Position);
|
|
||||||
Vector3f bottomFrontRight = box2Orientation.multiply(new Vector3f(+box2HalfSize.x, -box2HalfSize.y, -box2HalfSize.z)).add(box2Position);
|
|
||||||
Vector3f bottomFrontLeft = box2Orientation.multiply(new Vector3f(-box2HalfSize.x, -box2HalfSize.y, -box2HalfSize.z)).add(box2Position);
|
|
||||||
LoxelApplication.testPoints.clear();
|
|
||||||
LoxelApplication.testPoints.add(topBackRight);
|
|
||||||
LoxelApplication.testPoints.add(topBackLeft);
|
|
||||||
LoxelApplication.testPoints.add(topFrontRight);
|
|
||||||
LoxelApplication.testPoints.add(topFrontLeft);
|
|
||||||
LoxelApplication.testPoints.add(bottomBackRight);
|
|
||||||
LoxelApplication.testPoints.add(bottomBackLeft);
|
|
||||||
LoxelApplication.testPoints.add(bottomFrontRight);
|
|
||||||
LoxelApplication.testPoints.add(bottomFrontLeft);
|
|
||||||
LoxelApplication.testPointsBox.clear();
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(+box1HalfSize.x, +box1HalfSize.y, +box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(-box1HalfSize.x, +box1HalfSize.y, +box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(+box1HalfSize.x, -box1HalfSize.y, +box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(-box1HalfSize.x, -box1HalfSize.y, +box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(+box1HalfSize.x, +box1HalfSize.y, -box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(-box1HalfSize.x, +box1HalfSize.y, -box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(+box1HalfSize.x, -box1HalfSize.y, -box1HalfSize.z));
|
|
||||||
LoxelApplication.testPointsBox.add(new Vector3f(-box1HalfSize.x, -box1HalfSize.y, -box1HalfSize.z));
|
|
||||||
Vector3f insideTopBackRight = pointDistanceInAABB(box1HalfSize, topBackRight);
|
|
||||||
Vector3f insideTopBackLeft = pointDistanceInAABB(box1HalfSize, topBackLeft);
|
|
||||||
Vector3f insideTopFrontRight = pointDistanceInAABB(box1HalfSize, topFrontRight);
|
|
||||||
Vector3f insideTopFrontLeft = pointDistanceInAABB(box1HalfSize, topFrontLeft);
|
|
||||||
Vector3f insideBottomBackRight = pointDistanceInAABB(box1HalfSize, bottomBackRight);
|
|
||||||
Vector3f insideBottomBackLeft = pointDistanceInAABB(box1HalfSize, bottomBackLeft);
|
|
||||||
Vector3f insideBottomFrontRight = pointDistanceInAABB(box1HalfSize, bottomFrontRight);
|
|
||||||
Vector3f insideBottomFrontLeft = pointDistanceInAABB(box1HalfSize, bottomFrontLeft);
|
|
||||||
LoxelApplication.testPointsCollide.clear();
|
|
||||||
LoxelApplication.testPointsCollide.add(insideTopBackRight == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideTopBackLeft == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideTopFrontRight == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideTopFrontLeft == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideBottomBackRight == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideBottomBackLeft == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideBottomFrontRight == null ? false : true);
|
|
||||||
LoxelApplication.testPointsCollide.add(insideBottomFrontLeft == null ? false : true);
|
|
||||||
int count = 0;
|
|
||||||
if (insideTopBackRight != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopBackLeft != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopFrontRight != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopFrontLeft != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomBackRight != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomBackLeft != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomFrontRight != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomFrontLeft != null) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
ColisionPoints[] out = new ColisionPoints[count];
|
|
||||||
count = 0;
|
|
||||||
if (insideTopBackRight != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(+box2HalfSize.x, +box2HalfSize.y, +box2HalfSize.z), insideTopBackRight);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopBackLeft != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(-box2HalfSize.x, +box2HalfSize.y, +box2HalfSize.z), insideTopBackLeft);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopFrontRight != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(+box2HalfSize.x, -box2HalfSize.y, +box2HalfSize.z), insideTopFrontRight);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideTopFrontLeft != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(-box2HalfSize.x, -box2HalfSize.y, +box2HalfSize.z), insideTopFrontLeft);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomBackRight != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(+box2HalfSize.x, +box2HalfSize.y, -box2HalfSize.z), insideBottomBackRight);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomBackLeft != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(-box2HalfSize.x, +box2HalfSize.y, -box2HalfSize.z), insideBottomBackLeft);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomFrontRight != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(+box2HalfSize.x, -box2HalfSize.y, -box2HalfSize.z), insideBottomFrontRight);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (insideBottomFrontLeft != null) {
|
|
||||||
out[count] = new ColisionPoints(new Vector3f(-box2HalfSize.x, -box2HalfSize.y, -box2HalfSize.z), insideBottomFrontLeft);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (count != 0) {
|
|
||||||
// Find a point inside the BOX ...
|
|
||||||
/*
|
|
||||||
Log.info("Detect point inside ... " + insideTopBackRight + " " + insideTopBackLeft + " " + insideTopFrontRight + " " + insideTopFrontLeft + " " + insideBottomBackRight + " "
|
|
||||||
+ insideBottomBackLeft + " " + insideBottomFrontRight + " " + insideBottomFrontLeft);
|
|
||||||
*/
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
// line in AABB
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3f pointDistanceInAABB(Vector3f halfSize, Vector3f point) {
|
|
||||||
Vector3f out = new Vector3f();
|
|
||||||
if (point.x < 0) {
|
|
||||||
if (point.x > -halfSize.x) {
|
|
||||||
|
|
||||||
out.x = -(halfSize.x + point.x);
|
|
||||||
|
|
||||||
//out.x = -halfSize.x - point.x;
|
|
||||||
//out.x = -halfSize.x + point.x;
|
|
||||||
//out.x = + point.x;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (point.x < halfSize.x) {
|
|
||||||
//out.x = halfSize.x + point.x;
|
|
||||||
out.x = halfSize.x - point.x;
|
|
||||||
//out.x = - point.x;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (point.y < 0) {
|
|
||||||
if (point.y > -halfSize.y) {
|
|
||||||
out.y = -halfSize.y - point.y;
|
|
||||||
//out.y = -halfSize.y + point.y;
|
|
||||||
//out.y = point.y;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (point.y < halfSize.y) {
|
|
||||||
//out.y = halfSize.y + point.y;
|
|
||||||
out.y = halfSize.y - point.y;
|
|
||||||
//out.y = - point.y;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (point.z < 0) {
|
|
||||||
if (point.z > -halfSize.z) {
|
|
||||||
out.z = -halfSize.z - point.z;
|
|
||||||
//out.z = -halfSize.z + point.z;
|
|
||||||
//out.z = + point.z;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (point.z < halfSize.z) {
|
|
||||||
//out.z = halfSize.z + point.z;
|
|
||||||
out.z = halfSize.z - point.z;
|
|
||||||
//out.z = - point.z;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Math.abs(out.x) < Math.abs(out.y)) {
|
|
||||||
out.y = 0;
|
|
||||||
if (Math.abs(out.x) < Math.abs(out.z)) {
|
|
||||||
out.z = 0;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
out.x = 0;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
out.x = 0;
|
|
||||||
if (Math.abs(out.y) < Math.abs(out.z)) {
|
|
||||||
out.z = 0;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
out.y = 0;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
36
src/org/atriasoft/gameengine/physics/shape/Box.java
Normal file
36
src/org/atriasoft/gameengine/physics/shape/Box.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class Box extends Shape {
|
||||||
|
private Vector3f size; // Box size property in X, Y and Z
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "half-extents:", 13) == 0) {
|
||||||
|
sscanf(&_line[13], "%f %f %f", &size.m_floats[0], &size.m_floats[1], &size.m_floats[2] );
|
||||||
|
EGE_VERBOSE(" halfSize=" << size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(Vector3f size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
46
src/org/atriasoft/gameengine/physics/shape/Capsule.java
Normal file
46
src/org/atriasoft/gameengine/physics/shape/Capsule.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class Capsule extends Shape {
|
||||||
|
private float radius = 1;
|
||||||
|
private float size = 1;
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "radius:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f", &m_radius );
|
||||||
|
EGE_VERBOSE(" radius=" << m_radius);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "size:", 5) == 0) {
|
||||||
|
sscanf(&_line[5], "%f", &m_size );
|
||||||
|
EGE_VERBOSE(" height=" << m_size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public float getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
public void setSize(float size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
62
src/org/atriasoft/gameengine/physics/shape/Concave.java
Normal file
62
src/org/atriasoft/gameengine/physics/shape/Concave.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
import org.atriasoft.gameengine.internal.Log;
|
||||||
|
|
||||||
|
public class Concave extends Shape {
|
||||||
|
private List<Vector3f> vertexes = new ArrayList<>();
|
||||||
|
|
||||||
|
private final List<Integer> indices = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addTriangle(final List<Integer> index) {
|
||||||
|
/*
|
||||||
|
if (m_indices.size() == 0) {
|
||||||
|
m_indices = _index;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if (index.size() % 3 != 0) {
|
||||||
|
Log.error("wrong number of faces : " + index.size() + " ==> not a multiple of 3");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (final Integer it : index) {
|
||||||
|
this.indices.add(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
this.vertexes.clear();
|
||||||
|
this.indices.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getIndices() {
|
||||||
|
return this.indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Vector3f> getVertex() {
|
||||||
|
return this.vertexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean parse(final String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// TODO ...
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListOfVertex(final List<Vector3f> vertexes) {
|
||||||
|
this.vertexes = vertexes;
|
||||||
|
}
|
||||||
|
}
|
46
src/org/atriasoft/gameengine/physics/shape/Cone.java
Normal file
46
src/org/atriasoft/gameengine/physics/shape/Cone.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class Cone extends Shape {
|
||||||
|
private float radius = 1;
|
||||||
|
private float size = 1;
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "radius:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f", &m_radius );
|
||||||
|
EGE_VERBOSE(" radius=" << m_radius);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "size:", 5) == 0) {
|
||||||
|
sscanf(&_line[5], "%f", &m_size );
|
||||||
|
EGE_VERBOSE(" size=" << m_size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public float getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
public float getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
public void setSize(float size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
65
src/org/atriasoft/gameengine/physics/shape/ConvexHull.java
Normal file
65
src/org/atriasoft/gameengine/physics/shape/ConvexHull.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class ConvexHull extends Shape {
|
||||||
|
private Vector3f scale = new Vector3f(1, 1, 1);
|
||||||
|
private List<Vector3f> points = new ArrayList<>();
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "points:", 6) == 0) {
|
||||||
|
//EGE_DEBUG("convex hull point parsing " << _line);
|
||||||
|
char* base = (char*)(&_line[6]);
|
||||||
|
char* tmp= strchr(base, '|');
|
||||||
|
vec3 pos(0,0,0);
|
||||||
|
while (tmp != null) {
|
||||||
|
*tmp = '\0';
|
||||||
|
sscanf(base, "%f %f %f", &pos.m_floats[0], &pos.m_floats[1], &pos.m_floats[2] );
|
||||||
|
m_points.pushBack(pos);
|
||||||
|
base = tmp+1;
|
||||||
|
tmp= strchr(base, '|');
|
||||||
|
}
|
||||||
|
sscanf(base, "%f %f %f", &pos.m_floats[0], &pos.m_floats[1], &pos.m_floats[2] );
|
||||||
|
m_points.pushBack(pos);
|
||||||
|
/ *
|
||||||
|
for (int32_t iii=0; iii<m_points.size(); iii++) {
|
||||||
|
EGE_VERBOSE(" parsed " << m_points[iii]);
|
||||||
|
}
|
||||||
|
* /
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "scale:", 6) == 0) {
|
||||||
|
sscanf(&_line[6], "%f %f %f", &m_scale.m_floats[0], &m_scale.m_floats[1], &m_scale.m_floats[2] );
|
||||||
|
EGE_VERBOSE(" scale=" << m_scale);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public Vector3f getScale() {
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
public void setScale(Vector3f scale) {
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
public List<Vector3f> getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
public void setPoints(List<Vector3f> points) {
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
41
src/org/atriasoft/gameengine/physics/shape/Cylinder.java
Normal file
41
src/org/atriasoft/gameengine/physics/shape/Cylinder.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class Cylinder extends Shape {
|
||||||
|
private float radius = 1;
|
||||||
|
private float size = 1;
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "radius:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f", &m_radius );
|
||||||
|
EGE_VERBOSE(" radius=" << m_radius);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public float getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
public void setSize(float size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
49
src/org/atriasoft/gameengine/physics/shape/ProxyShape.java
Normal file
49
src/org/atriasoft/gameengine/physics/shape/ProxyShape.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Matrix3f;
|
||||||
|
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 net.jreactphysics3d.body.RigidBody;
|
||||||
|
import net.jreactphysics3d.collision.shapes.CollisionShape;
|
||||||
|
import net.jreactphysics3d.engine.DynamicsWorld;
|
||||||
|
|
||||||
|
public class ProxyShape {
|
||||||
|
|
||||||
|
private CollisionShape collisionShape;
|
||||||
|
private RigidBody rigidBody;
|
||||||
|
|
||||||
|
protected void createRigidBody(CollisionShape collisionShape, Transform3D transform, float mass, DynamicsWorld dynamicsWorld) {
|
||||||
|
|
||||||
|
this.collisionShape = collisionShape;
|
||||||
|
|
||||||
|
Matrix3f inertiaTensor = new Matrix3f();
|
||||||
|
collisionShape.computeLocalInertiaTensor(inertiaTensor, mass);
|
||||||
|
|
||||||
|
rigidBody = dynamicsWorld.createRigidBody(transform, mass, inertiaTensor, collisionShape);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollisionShape getCollisionShape() {
|
||||||
|
return collisionShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RigidBody getRigidBody() {
|
||||||
|
return rigidBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTransform() {
|
||||||
|
|
||||||
|
// Get the interpolated transform of the rigid body
|
||||||
|
Transform3D transform = rigidBody.getInterpolatedTransform();
|
||||||
|
|
||||||
|
// Compute the transform used for rendering the box
|
||||||
|
Matrix4f glMatrix = transform.getOpenGLMatrix();
|
||||||
|
|
||||||
|
// Apply the scaling matrix to have the correct box dimensions
|
||||||
|
//getWorldTransform().fromOpenGLArray(glMatrix);
|
||||||
|
//getWorldTransform().multiply(getScalingTransform());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
106
src/org/atriasoft/gameengine/physics/shape/Shape.java
Normal file
106
src/org/atriasoft/gameengine/physics/shape/Shape.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Quaternion;
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
|
||||||
|
public class Shape {
|
||||||
|
private Quaternion orientation = new Quaternion();
|
||||||
|
private float mass = 1; //!< element mass in "g" then 1000 for 1kg
|
||||||
|
private Vector3f origin = new Vector3f(0,0,0);
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if(strncmp(_line, "origin:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f %f %f", &m_origin.m_floats[0], &m_origin.m_floats[1], &m_origin.m_floats[2] );
|
||||||
|
EGE_VERBOSE(" Origin=" << m_origin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "rotate:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f %f %f %f", &m_quaternion.m_floats[0], &m_quaternion.m_floats[1], &m_quaternion.m_floats[2], &m_quaternion.m_floats[3] );
|
||||||
|
EGE_VERBOSE(" rotate=" << m_quaternion);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "mass:", 5) == 0) {
|
||||||
|
sscanf(&_line[5], "%f", &m_mass );
|
||||||
|
EGE_VERBOSE(" mass=" << m_mass);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void display() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public Quaternion getOrientation() {
|
||||||
|
return this.orientation.clone();
|
||||||
|
}
|
||||||
|
public void setOrientation(Quaternion orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
public Vector3f getOrigin() {
|
||||||
|
return this.origin;
|
||||||
|
};
|
||||||
|
public void setOrigin(Vector3f origin) {
|
||||||
|
this.origin = origin;
|
||||||
|
}
|
||||||
|
public float getMass() {
|
||||||
|
return this.mass;
|
||||||
|
}
|
||||||
|
public void setMass(float mass) {
|
||||||
|
this.mass = mass;
|
||||||
|
}
|
||||||
|
public boolean isBox() {
|
||||||
|
return this instanceof Box;
|
||||||
|
};
|
||||||
|
public boolean isCylinder() {
|
||||||
|
return this instanceof Cylinder;
|
||||||
|
};
|
||||||
|
public boolean isCapsule() {
|
||||||
|
return this instanceof Capsule;
|
||||||
|
};
|
||||||
|
public boolean isCone() {
|
||||||
|
return this instanceof Cone;
|
||||||
|
};
|
||||||
|
public boolean isConvexHull() {
|
||||||
|
return this instanceof ConvexHull;
|
||||||
|
};
|
||||||
|
public boolean isSphere() {
|
||||||
|
return this instanceof Sphere;
|
||||||
|
};
|
||||||
|
public boolean isConcave() {
|
||||||
|
return this instanceof Concave;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
ememory::SharedPtr<ege::physics::Shape> ege::physics::Shape::create(const etk::String& _name) {
|
||||||
|
ememory::SharedPtr<ege::physics::Shape> tmpp = null;
|
||||||
|
etk::String name = etk::toLower(_name);
|
||||||
|
if (name == "box") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Box>();
|
||||||
|
} else if (name == "sphere") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Sphere>();
|
||||||
|
} else if (name == "cone") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Cone>();
|
||||||
|
} else if (name == "cylinder") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Cylinder>();
|
||||||
|
} else if (name == "capsule") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Capsule>();
|
||||||
|
} else if (name == "convexhull") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::ConvexHull>();
|
||||||
|
} else if (name == "autoconcave") {
|
||||||
|
tmpp = ememory::makeShared<ege::physics::shape::Concave>();
|
||||||
|
} else {
|
||||||
|
EGE_ERROR("Create an unknow element : '" << _name << "' availlable : [BOX,SPHERE,CONE,CYLINDER,CAPSULE,CONVEXHULL,autoConcave]");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (tmpp == null) {
|
||||||
|
EGE_ERROR("Allocation error for physical element : '" << _name << "'");
|
||||||
|
}
|
||||||
|
return tmpp;
|
||||||
|
}
|
||||||
|
*/
|
34
src/org/atriasoft/gameengine/physics/shape/Sphere.java
Normal file
34
src/org/atriasoft/gameengine/physics/shape/Sphere.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
package org.atriasoft.gameengine.physics.shape;
|
||||||
|
|
||||||
|
import org.atriasoft.etk.math.Vector3f;
|
||||||
|
|
||||||
|
public class Sphere extends Shape {
|
||||||
|
private float radius = 1;
|
||||||
|
@Override
|
||||||
|
public boolean parse(String _line) {
|
||||||
|
/*
|
||||||
|
if (super.parse(_line) == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(strncmp(_line, "radius:", 7) == 0) {
|
||||||
|
sscanf(&_line[7], "%f", &m_radius );
|
||||||
|
EGE_VERBOSE(" radius=" << m_radius);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public float getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
public void setRadius(float radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,11 @@ import org.atriasoft.gale.Gale;
|
|||||||
import org.atriasoft.gale.backend3d.OpenGL;
|
import org.atriasoft.gale.backend3d.OpenGL;
|
||||||
import org.atriasoft.gale.backend3d.OpenGL.Flag;
|
import org.atriasoft.gale.backend3d.OpenGL.Flag;
|
||||||
import org.atriasoft.gale.context.Context;
|
import org.atriasoft.gale.context.Context;
|
||||||
|
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.gameengine.ControlCameraPlayer;
|
import org.atriasoft.gameengine.ControlCameraPlayer;
|
||||||
import org.atriasoft.gameengine.Entity;
|
import org.atriasoft.gameengine.Entity;
|
||||||
import org.atriasoft.gameengine.Environement;
|
import org.atriasoft.gameengine.Environement;
|
||||||
@ -37,27 +42,12 @@ import org.atriasoft.gameengine.components.ComponentStaticMesh;
|
|||||||
import org.atriasoft.gameengine.components.ComponentTexture;
|
import org.atriasoft.gameengine.components.ComponentTexture;
|
||||||
import org.atriasoft.gameengine.engines.EngineLight;
|
import org.atriasoft.gameengine.engines.EngineLight;
|
||||||
import org.atriasoft.gameengine.map.MapVoxel;
|
import org.atriasoft.gameengine.map.MapVoxel;
|
||||||
import org.atriasoft.gameengine.physics.PhysicBox;
|
import org.atriasoft.gameengine.physics.shape.Box;
|
||||||
import org.atriasoft.gameengine.tools.MeshGenerator;
|
import org.atriasoft.gameengine.tools.MeshGenerator;
|
||||||
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;
|
|
||||||
|
|
||||||
public class LoxelApplication extends Application {
|
public class LoxelApplication extends Application {
|
||||||
private Environement env;
|
// public static ComponentPosition relativeTestPos;
|
||||||
private ComponentPosition objectPosition;
|
// public static Box boxTest;
|
||||||
private Quaternion basicRotation = Quaternion.identity();
|
|
||||||
private Quaternion basicRotation2 = Quaternion.identity();
|
|
||||||
private boolean creationDone;
|
|
||||||
private ControlCameraPlayer simpleControl;
|
|
||||||
private ComponentPosition lightPosition;
|
|
||||||
private float angleLight = 0;
|
|
||||||
private MapVoxel map;
|
|
||||||
private ComponentPlayer objectPlayer;
|
|
||||||
// public static ComponentPosition relativeTestPos;
|
|
||||||
// public static PhysicBox boxTest;
|
|
||||||
public static List<Vector3f> testPoints = new ArrayList<Vector3f>();
|
public static List<Vector3f> testPoints = new ArrayList<Vector3f>();
|
||||||
public static List<Vector3f> testPointsBox = new ArrayList<Vector3f>();
|
public static List<Vector3f> testPointsBox = new ArrayList<Vector3f>();
|
||||||
public static List<Boolean> testPointsCollide = new ArrayList<Boolean>();
|
public static List<Boolean> testPointsCollide = new ArrayList<Boolean>();
|
||||||
@ -65,280 +55,260 @@ public class LoxelApplication extends Application {
|
|||||||
public static Quaternion testQTransfert;
|
public static Quaternion testQTransfert;
|
||||||
public static Vector3f box1HalfSize;
|
public static Vector3f box1HalfSize;
|
||||||
public static Vector3f box2HalfSize;
|
public static Vector3f box2HalfSize;
|
||||||
|
private Environement env;
|
||||||
|
private ComponentPosition objectPosition;
|
||||||
|
private final Quaternion basicRotation = Quaternion.identity();
|
||||||
|
private final Quaternion basicRotation2 = Quaternion.identity();
|
||||||
|
private boolean creationDone;
|
||||||
|
private ControlCameraPlayer simpleControl;
|
||||||
|
private ComponentPosition lightPosition;
|
||||||
|
private float angleLight = 0;
|
||||||
|
private MapVoxel map;
|
||||||
|
private ComponentPlayer objectPlayer;
|
||||||
private ResourceColored3DObject debugDrawProperty;
|
private ResourceColored3DObject debugDrawProperty;
|
||||||
public LoxelApplication(){
|
|
||||||
creationDone = false;
|
public LoxelApplication() {
|
||||||
|
this.creationDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Context context) {
|
public void onCreate(final Context context) {
|
||||||
// set the system global max speed
|
// set the system global max speed
|
||||||
ComponentPhysics.globalMaxSpeed = 3;
|
//ComponentPhysics.globalMaxSpeed = 3;
|
||||||
Gale.getContext().grabPointerEvents(true, new Vector2f(0,0));
|
Gale.getContext().grabPointerEvents(true, new Vector2f(0, 0));
|
||||||
env = new Environement();
|
this.env = new Environement();
|
||||||
this.canDraw = true;
|
this.canDraw = true;
|
||||||
setSize(new Vector2f(1500, 1500));
|
setSize(new Vector2f(1500, 1500));
|
||||||
setTitle("Loxel sample");
|
setTitle("Loxel sample");
|
||||||
map = new MapVoxel(this.env);
|
this.map = new MapVoxel(this.env);
|
||||||
// this.env.addEngine(map);
|
// this.env.addEngine(map);
|
||||||
// map.init();
|
// map.init();
|
||||||
|
|
||||||
// simple sun to have a global light ...
|
// simple sun to have a global light ...
|
||||||
Entity globalGravity = new Entity(this.env);
|
final Entity globalGravity = new Entity(this.env);
|
||||||
globalGravity.addComponent(new ComponentGravityStatic(new Vector3f(0,0,-1)));
|
globalGravity.addComponent(new ComponentGravityStatic(new Vector3f(0, 0, -1)));
|
||||||
env.addEntity(globalGravity);
|
this.env.addEntity(globalGravity);
|
||||||
|
|
||||||
// simple sun to have a global light ...
|
// simple sun to have a global light ...
|
||||||
Entity sun = new Entity(this.env);
|
final Entity sun = new Entity(this.env);
|
||||||
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000,1000,1000))));
|
sun.addComponent(new ComponentPosition(new Transform3D(new Vector3f(1000, 1000, 1000))));
|
||||||
sun.addComponent(new ComponentLightSun(new Light(new Vector3f(0.4f,0.4f,0.4f), new Vector3f(0,0,0), new Vector3f(0.8f,0,0))));
|
sun.addComponent(new ComponentLightSun(new Light(new Vector3f(0.4f, 0.4f, 0.4f), new Vector3f(0, 0, 0), new Vector3f(0.8f, 0, 0))));
|
||||||
env.addEntity(sun);
|
this.env.addEntity(sun);
|
||||||
|
|
||||||
// add a cube to show where in the light ...
|
// add a cube to show where in the light ...
|
||||||
Entity localLight = new Entity(this.env);
|
final Entity localLight = new Entity(this.env);
|
||||||
lightPosition = new ComponentPosition(new Transform3D(new Vector3f(-10,-10,17)));
|
this.lightPosition = new ComponentPosition(new Transform3D(new Vector3f(-10, -10, 17)));
|
||||||
// localLight.addComponent(lightPosition);
|
// localLight.addComponent(lightPosition);
|
||||||
// localLight.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
// localLight.addComponent(new ComponentStaticMesh(new Uri("RES", "cube.obj")));
|
||||||
// localLight.addComponent(new ComponentTexture(new Uri("RES", "grass.png")));
|
// 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 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(
|
// localLight.addComponent(new ComponentRenderTexturedStaticMesh(
|
||||||
// new Uri("DATA", "basic.vert"),
|
// new Uri("DATA", "basic.vert"),
|
||||||
// new Uri("DATA", "basic.frag")));
|
// new Uri("DATA", "basic.frag")));
|
||||||
// env.addEntity(localLight);
|
// env.addEntity(localLight);
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2,-2,14))));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2, -2, 14))));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
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 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(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(1, 1, 1));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(1,1,1));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,4,12.5f))));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 4, 12.5f))));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
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 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(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(1, 1, 1));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(1,1,1));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2,2,14.5f))));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-2, 2, 14.5f))));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(1, 1, 1));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(1,1,1));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-5,-5,14))));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(-5, -5, 14))));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(4, 4, 4));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(4,4,4));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
Quaternion transform = new Quaternion(0.5f,0.2f,0.4f,1);
|
final Quaternion transform = new Quaternion(0.5f, 0.2f, 0.4f, 1);
|
||||||
transform.normalize();
|
transform.normalize();
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(15,15,14), transform)));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(15, 15, 14), transform)));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(8, 8, 8));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(8,8,8));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
Quaternion transform = new Quaternion(0.3f,0.3f,0.4f,1);
|
final Quaternion transform = new Quaternion(0.3f, 0.3f, 0.4f, 1);
|
||||||
transform.normalize();
|
transform.normalize();
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2,-2,14.2f),transform)));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2, -2, 14.2f), transform)));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(1, 1, 1));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(1,1,1));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// add a cube to test collision ...
|
// add a cube to test collision ...
|
||||||
Entity localBox = new Entity(this.env);
|
final Entity localBox = new Entity(this.env);
|
||||||
Quaternion transform = new Quaternion(0,0,1,1);
|
final Quaternion transform = new Quaternion(0, 0, 1, 1);
|
||||||
transform.normalize();
|
transform.normalize();
|
||||||
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2,2,14.2f),transform)));
|
localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(2, 2, 14.2f), transform)));
|
||||||
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
localBox.addComponent(new ComponentRenderTexturedStaticMesh(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag")));
|
||||||
new Uri("DATA", "basic.vert"),
|
final ComponentPhysics physics2 = new ComponentPhysics(this.env);
|
||||||
new Uri("DATA", "basic.frag")));
|
final Box box2 = new Box();
|
||||||
ComponentPhysics physics2 = new ComponentPhysics(true);
|
box2.setSize(new Vector3f(1, 1, 1));
|
||||||
PhysicBox box2 = new PhysicBox();
|
box2.setOrigin(new Vector3f(0, 0, 0));
|
||||||
box2.setSize(new Vector3f(1,1,1));
|
|
||||||
box2.setOrigin(new Vector3f(0,0,0));
|
|
||||||
box2.setMass(1);
|
box2.setMass(1);
|
||||||
physics2.addShape(box2);
|
physics2.addShape(box2);
|
||||||
localBox.addComponent(physics2);
|
localBox.addComponent(physics2);
|
||||||
env.addEntity(localBox);
|
this.env.addEntity(localBox);
|
||||||
}
|
}
|
||||||
// {
|
// {
|
||||||
// // add a cube to test collision ...
|
// // add a cube to test collision ...
|
||||||
// Entity localBox = new Entity(this.env);
|
// 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)));
|
// relativeTestPos = new ComponentPosition(new Transform3D(new Vector3f(0,0,14),new Quaternion(0.5f,0.2f,0.4f,1)));
|
||||||
// localBox.addComponent(relativeTestPos);
|
// localBox.addComponent(relativeTestPos);
|
||||||
//// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
//// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
//// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
//// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
//// 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 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(
|
//// localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
||||||
//// new Uri("DATA", "basic.vert"),
|
//// new Uri("DATA", "basic.vert"),
|
||||||
//// new Uri("DATA", "basic.frag")));
|
//// new Uri("DATA", "basic.frag")));
|
||||||
// ComponentPhysics physics2 = new ComponentPhysics(true);
|
// ComponentPhysics physics2 = new ComponentPhysics(true);
|
||||||
// boxTest = new PhysicBox();
|
// boxTest = new Box();
|
||||||
// boxTest.setSize(new Vector3f(1,1,1));
|
// boxTest.setSize(new Vector3f(1,1,1));
|
||||||
// boxTest.setOrigin(new Vector3f(0,0,0));
|
// boxTest.setOrigin(new Vector3f(0,0,0));
|
||||||
// boxTest.setMass(1);
|
// boxTest.setMass(1);
|
||||||
// physics2.addShape(boxTest);
|
// physics2.addShape(boxTest);
|
||||||
// localBox.addComponent(physics2);
|
// localBox.addComponent(physics2);
|
||||||
// env.addEntity(localBox);
|
// env.addEntity(localBox);
|
||||||
// }
|
// }
|
||||||
// {
|
// {
|
||||||
// Entity localBox = new Entity(this.env);
|
// Entity localBox = new Entity(this.env);
|
||||||
// localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,14))));
|
// localBox.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,14))));
|
||||||
// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
// localBox.addComponent(new ComponentStaticMesh(new Uri("RES", "cube-one.obj")));
|
||||||
// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
// localBox.addComponent(new ComponentTexture(new Uri("DATA", "blocks/clay.png")));
|
||||||
// localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
// localBox.addComponent(new ComponentRenderTexturedStaticMesh(
|
||||||
// new Uri("DATA", "basic.vert"),
|
// new Uri("DATA", "basic.vert"),
|
||||||
// new Uri("DATA", "basic.frag")));
|
// new Uri("DATA", "basic.frag")));
|
||||||
// env.addEntity(localBox);
|
// env.addEntity(localBox);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Entity gird = new Entity(this.env);
|
final Entity gird = new Entity(this.env);
|
||||||
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0,0,13))));
|
gird.addComponent(new ComponentPosition(new Transform3D(new Vector3f(0, 0, 13))));
|
||||||
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
gird.addComponent(new ComponentStaticMesh(MeshGenerator.createGrid(5)));
|
||||||
gird.addComponent(new ComponentRenderColoredStaticMesh(
|
gird.addComponent(new ComponentRenderColoredStaticMesh(new Uri("DATA_EGE", "wireColor.vert"), new Uri("DATA_EGE", "wireColor.frag")));
|
||||||
new Uri("DATA_EGE", "wireColor.vert"),
|
this.env.addEntity(gird);
|
||||||
new Uri("DATA_EGE", "wireColor.frag")));
|
|
||||||
env.addEntity(gird);
|
|
||||||
|
|
||||||
Entity player = new Entity(this.env);
|
final Entity player = new Entity(this.env);
|
||||||
objectPosition = new ComponentPositionPlayer(new Transform3D(new Vector3f(5,5,13)));
|
this.objectPosition = new ComponentPositionPlayer(new Transform3D(new Vector3f(5, 5, 13)));
|
||||||
player.addComponent(objectPosition);
|
player.addComponent(this.objectPosition);
|
||||||
objectPlayer = new ComponentPlayer();
|
this.objectPlayer = new ComponentPlayer();
|
||||||
player.addComponent(objectPlayer);
|
player.addComponent(this.objectPlayer);
|
||||||
player.addComponent(new ComponentMaterial(new Material()));
|
player.addComponent(new ComponentMaterial(new Material()));
|
||||||
//player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj")));
|
//player.addComponent(new ComponentStaticMesh(new Uri("RES", "person.obj")));
|
||||||
player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj")));
|
player.addComponent(new ComponentStaticMesh(new Uri("RES", "person_-yfw_zup.obj")));
|
||||||
player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png")));
|
player.addComponent(new ComponentTexture(new Uri("RES", "playerTexture.png")));
|
||||||
player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(
|
player.addComponent(new ComponentRenderTexturedMaterialsStaticMesh(new Uri("DATA", "basicMaterial.vert"), new Uri("DATA", "basicMaterial.frag"),
|
||||||
new Uri("DATA", "basicMaterial.vert"),
|
(EngineLight) this.env.getEngine(EngineLight.ENGINE_NAME)));
|
||||||
new Uri("DATA", "basicMaterial.frag"),
|
final ComponentPhysics physics = new ComponentPhysics(this.env);
|
||||||
(EngineLight)env.getEngine(EngineLight.ENGINE_NAME)));
|
final Box box = new Box();
|
||||||
ComponentPhysics physics = new ComponentPhysics(true);
|
box.setSize(new Vector3f(0.6f, 0.6f, 1.8f));
|
||||||
PhysicBox box = new PhysicBox();
|
box.setOrigin(new Vector3f(0, 0, 0.9f));
|
||||||
box.setSize(new Vector3f(0.6f,0.6f,1.8f));
|
|
||||||
box.setOrigin(new Vector3f(0,0,0.9f));
|
|
||||||
box.setMass(1);
|
box.setMass(1);
|
||||||
physics.addShape(box);
|
physics.addShape(box);
|
||||||
player.addComponent(physics);
|
player.addComponent(physics);
|
||||||
env.addEntity(player);
|
this.env.addEntity(player);
|
||||||
|
|
||||||
|
final Camera mainView = new Camera();
|
||||||
Camera mainView = new Camera();
|
this.env.addCamera("default", mainView);
|
||||||
env.addCamera("default", mainView);
|
mainView.setPitch((float) Math.PI * -0.25f);
|
||||||
mainView.setPitch((float)Math.PI*-0.25f);
|
mainView.setPosition(new Vector3f(0, -5, 5));
|
||||||
mainView.setPosition(new Vector3f(0,-5,5));
|
|
||||||
|
|
||||||
this.simpleControl = new ControlCameraPlayer(mainView, player);
|
this.simpleControl = new ControlCameraPlayer(mainView, player);
|
||||||
env.addControlInterface(simpleControl);
|
this.env.addControlInterface(this.simpleControl);
|
||||||
|
|
||||||
// start the engine.
|
// start the engine.
|
||||||
env.setPropertyStatus(GameStatus.gameStart);
|
this.env.setPropertyStatus(GameStatus.gameStart);
|
||||||
|
|
||||||
basicRotation.setEulerAngles(new Vector3f(0.005f,0.005f,0.01f));
|
this.basicRotation.setEulerAngles(new Vector3f(0.005f, 0.005f, 0.01f));
|
||||||
basicRotation2.setEulerAngles(new Vector3f(0.003f,0.01f,0.001f));
|
this.basicRotation2.setEulerAngles(new Vector3f(0.003f, 0.01f, 0.001f));
|
||||||
// ready to let Gale & Ege manage the display
|
// ready to let Gale & Ege manage the display
|
||||||
Log.info("==> Init APPL (END)");
|
Log.info("==> Init APPL (END)");
|
||||||
creationDone = true;
|
this.creationDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRegenerateDisplay(Context context) {
|
public void onDraw(final Context context) {
|
||||||
//Log.verbose("Regenerate Gale Application");
|
|
||||||
if (!this.creationDone) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
angleLight += 0.01;
|
|
||||||
lightPosition.getTransform().getPosition().x = 5 + (float)Math.cos(angleLight) * 7.0f;
|
|
||||||
lightPosition.getTransform().getPosition().y = 5 + (float)Math.sin(angleLight) * 7.0f;
|
|
||||||
env.periodicCall();
|
|
||||||
markDrawingIsNeeded();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDraw(Context context) {
|
|
||||||
//Log.info("==> appl Draw ...");
|
//Log.info("==> appl Draw ...");
|
||||||
Vector2f size = getSize();
|
final Vector2f size = getSize();
|
||||||
if (!this.creationDone) {
|
if (!this.creationDone) {
|
||||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
OpenGL.setViewPort(new Vector2f(0, 0), size);
|
||||||
Color bgColor = new Color(0.8f, 0.5f, 0.5f, 1.0f);
|
final Color bgColor = new Color(0.8f, 0.5f, 0.5f, 1.0f);
|
||||||
OpenGL.clearColor(bgColor);
|
OpenGL.clearColor(bgColor);
|
||||||
Log.info("==> appl clear ==> not created ...");
|
Log.info("==> appl clear ==> not created ...");
|
||||||
return;
|
return;
|
||||||
@ -346,14 +316,14 @@ public class LoxelApplication extends Application {
|
|||||||
// Store openGl context.
|
// Store openGl context.
|
||||||
OpenGL.push();
|
OpenGL.push();
|
||||||
// set projection matrix:
|
// set projection matrix:
|
||||||
Matrix4f tmpProjection = Matrix4f.createMatrixPerspective(3.14f*0.5f, getAspectRatio(), 0.1f, 50000);
|
final Matrix4f tmpProjection = Matrix4f.createMatrixPerspective(3.14f * 0.5f, getAspectRatio(), 0.1f, 50000);
|
||||||
OpenGL.setMatrix(tmpProjection);
|
OpenGL.setMatrix(tmpProjection);
|
||||||
|
|
||||||
// set the basic openGL view port: (Draw in all the windows...)
|
// set the basic openGL view port: (Draw in all the windows...)
|
||||||
OpenGL.setViewPort(new Vector2f(0,0), size);
|
OpenGL.setViewPort(new Vector2f(0, 0), size);
|
||||||
|
|
||||||
// clear background
|
// clear background
|
||||||
Color bgColor = new Color(0.18f, 0.43f, 0.95f, 1.0f);
|
final Color bgColor = new Color(0.18f, 0.43f, 0.95f, 1.0f);
|
||||||
OpenGL.clearColor(bgColor);
|
OpenGL.clearColor(bgColor);
|
||||||
// real clear request:
|
// real clear request:
|
||||||
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
|
||||||
@ -361,34 +331,39 @@ public class LoxelApplication extends Application {
|
|||||||
OpenGL.enable(Flag.flag_depthTest);
|
OpenGL.enable(Flag.flag_depthTest);
|
||||||
|
|
||||||
//Log.info("==> appl Draw ...");
|
//Log.info("==> appl Draw ...");
|
||||||
env.render(20, "default");
|
this.env.render(20, "default");
|
||||||
if (this.debugDrawProperty == null) {
|
if (this.debugDrawProperty == null) {
|
||||||
debugDrawProperty = ResourceColored3DObject.create();
|
this.debugDrawProperty = ResourceColored3DObject.create();
|
||||||
}
|
}
|
||||||
// now render the point test collision ...
|
// now render the point test collision ...
|
||||||
for (int iii=0; iii<LoxelApplication.testPoints.size(); iii++) {
|
for (int iii = 0; iii < LoxelApplication.testPoints.size(); iii++) {
|
||||||
Vector3f elem = LoxelApplication.testPoints.get(iii);
|
final Vector3f elem = LoxelApplication.testPoints.get(iii);
|
||||||
boolean collide = LoxelApplication.testPointsCollide.get(iii);
|
final boolean collide = LoxelApplication.testPointsCollide.get(iii);
|
||||||
if (collide) {
|
if (collide) {
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.1f,0.1f,0.1f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(1,0,0,1));
|
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.identity().multiplyNew(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().multiplyNew(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().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x, elem.y, elem.z + 14))),
|
||||||
|
new Color(1, 1, 0, 1));
|
||||||
} else {
|
} else {
|
||||||
if (iii==0) {
|
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x, elem.y, elem.z + 14))),
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f,0.05f,0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(0,1,0,1));
|
new Color(1, 1, 1, 1));
|
||||||
} else if (iii==7) {
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f,0.05f,0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(1,1,0,1));
|
|
||||||
} else {
|
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.1f,0.1f,0.1f), Matrix4f.identity().multiplyNew(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++) {
|
||||||
for (int iii=0; iii<LoxelApplication.testPointsBox.size(); iii++) {
|
final Vector3f elem = LoxelApplication.testPointsBox.get(iii);
|
||||||
Vector3f elem = LoxelApplication.testPointsBox.get(iii);
|
if (iii == 0) {
|
||||||
if (iii==0) {
|
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x, elem.y, elem.z + 14))),
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f,0.05f,0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(0,1,0,1));
|
new Color(0, 1, 0, 1));
|
||||||
} else if (iii==7) {
|
} else if (iii == 7) {
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.05f,0.05f,0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(1,1,0,1));
|
this.debugDrawProperty.drawSquare(new Vector3f(0.05f, 0.05f, 0.05f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x, elem.y, elem.z + 14))),
|
||||||
|
new Color(1, 1, 0, 1));
|
||||||
} else {
|
} else {
|
||||||
debugDrawProperty.drawSquare(new Vector3f(0.1f,0.1f,0.1f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x,elem.y,elem.z+14))), new Color(0,0,1,1));
|
this.debugDrawProperty.drawSquare(new Vector3f(0.1f, 0.1f, 0.1f), Matrix4f.identity().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(elem.x, elem.y, elem.z + 14))),
|
||||||
|
new Color(0, 0, 1, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,39 +372,48 @@ public class LoxelApplication extends Application {
|
|||||||
//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)));
|
||||||
//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)));
|
||||||
//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)));
|
||||||
Matrix4f trensformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x,testRpos.y,testRpos.z)).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,14))).multiply(testQTransfert.getMatrix4());
|
final Matrix4f trensformation = Matrix4f.createMatrixTranslate(new Vector3f(testRpos.x, testRpos.y, testRpos.z)).multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)))
|
||||||
|
.multiply(testQTransfert.getMatrix4());
|
||||||
// OK sans la box1 orientation ...
|
// 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)));
|
||||||
//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)));
|
||||||
debugDrawProperty.drawSquare(box2HalfSize, trensformation, new Color(0,1,0,0.5f));
|
this.debugDrawProperty.drawSquare(box2HalfSize, trensformation, new Color(0, 1, 0, 0.5f));
|
||||||
debugDrawProperty.drawSquare(box1HalfSize, Matrix4f.createMatrixTranslate(new Vector3f(0,0,14)), new Color(0,0,1,0.5f));
|
this.debugDrawProperty.drawSquare(box1HalfSize, Matrix4f.createMatrixTranslate(new Vector3f(0, 0, 14)), new Color(0, 0, 1, 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore context of matrix
|
// Restore context of matrix
|
||||||
OpenGL.pop();
|
OpenGL.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPointer(KeySpecial special,
|
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
|
||||||
KeyType type,
|
if (type == KeyKeyboard.f1) {
|
||||||
int pointerID,
|
Gale.getContext().grabPointerEvents(false, new Vector2f(0, 0));
|
||||||
Vector2f pos,
|
|
||||||
KeyStatus state) {
|
|
||||||
env.onPointer(special, type, pointerID, pos, state);
|
|
||||||
}
|
}
|
||||||
@Override
|
if (type == KeyKeyboard.f2) {
|
||||||
public void onKeyboard(KeySpecial special,
|
Gale.getContext().grabPointerEvents(true, new Vector2f(0, 0));
|
||||||
KeyKeyboard type,
|
|
||||||
Character value,
|
|
||||||
KeyStatus state) {
|
|
||||||
if (type == KeyKeyboard.f1 ) {
|
|
||||||
Gale.getContext().grabPointerEvents(false, new Vector2f(0,0));
|
|
||||||
}
|
}
|
||||||
if (type == KeyKeyboard.f2 ) {
|
if (type == KeyKeyboard.f12) {
|
||||||
Gale.getContext().grabPointerEvents(true, new Vector2f(0,0));
|
|
||||||
}
|
|
||||||
if (type == KeyKeyboard.f12 ) {
|
|
||||||
Gale.getContext().setFullScreen(!Gale.getContext().getFullScreen());
|
Gale.getContext().setFullScreen(!Gale.getContext().getFullScreen());
|
||||||
}
|
}
|
||||||
env.onKeyboard(special, type, value, state);
|
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 Context context) {
|
||||||
|
//Log.verbose("Regenerate Gale Application");
|
||||||
|
if (!this.creationDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.angleLight += 0.01;
|
||||||
|
this.lightPosition.getTransform().getPosition().x = 5 + (float) Math.cos(this.angleLight) * 7.0f;
|
||||||
|
this.lightPosition.getTransform().getPosition().y = 5 + (float) Math.sin(this.angleLight) * 7.0f;
|
||||||
|
this.env.periodicCall();
|
||||||
|
markDrawingIsNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package org.atriasoft.gameengine.samples.LoxelEngine;
|
|||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.gale.Gale;
|
import org.atriasoft.gale.Gale;
|
||||||
|
|
||||||
public class Main {
|
public class MainLoxelEngine {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Uri.setGroup("DATA", "src/org/atriasoft/gameengine/samples/LoxelEngine/res/");
|
Uri.setGroup("DATA", "src/org/atriasoft/gameengine/samples/LoxelEngine/res/");
|
||||||
Uri.setGroup("DATA_EGE", "src/org/atriasoft/gameengine/data/");
|
Uri.setGroup("DATA_EGE", "src/org/atriasoft/gameengine/data/");
|
@ -3,7 +3,7 @@ package org.atriasoft.gameengine.samples.lowPoly;
|
|||||||
import org.atriasoft.etk.Uri;
|
import org.atriasoft.etk.Uri;
|
||||||
import org.atriasoft.gale.Gale;
|
import org.atriasoft.gale.Gale;
|
||||||
|
|
||||||
public class Main {
|
public class MainMowPoly {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Uri.setGroup("DATA", "src/org/atriasoft/gameengine/samples/lowPoly/");
|
Uri.setGroup("DATA", "src/org/atriasoft/gameengine/samples/lowPoly/");
|
||||||
Uri.setGroup("DATA_EGE", "src/org/atriasoft/gameengine/data/");
|
Uri.setGroup("DATA_EGE", "src/org/atriasoft/gameengine/data/");
|
Loading…
x
Reference in New Issue
Block a user