simplify physics cases
This commit is contained in:
parent
36d2271b35
commit
524f328fae
@ -1168,6 +1168,7 @@ Fix particles not spawning in correct positions
|
||||
Fix block not firing
|
||||
Fix reentrant locking bug
|
||||
Convert server physics cell generation to executor service
|
||||
Simplifying physics cases
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
@ -133,6 +133,11 @@ public class CollisionEngine {
|
||||
//buffer for collisions
|
||||
DContactBuffer contacts = null;
|
||||
|
||||
/**
|
||||
* The body that contains all static shapes
|
||||
*/
|
||||
DBody staticBody;
|
||||
|
||||
// Callback for any near collisions in the broadphase of the collision check
|
||||
private DNearCallback nearCallback;
|
||||
|
||||
@ -150,6 +155,10 @@ public class CollisionEngine {
|
||||
//base plane
|
||||
OdeHelper.createPlane(space, 0, 1, 0, 0);
|
||||
|
||||
//static body
|
||||
staticBody = this.createDBody();
|
||||
staticBody.setKinematic();
|
||||
|
||||
|
||||
contactgroup = OdeHelper.createJointGroup();
|
||||
this.nearCallback = new DNearCallback() {
|
||||
@ -184,7 +193,7 @@ public class CollisionEngine {
|
||||
switch(receiver.getType()){
|
||||
case Collidable.TYPE_CREATURE:
|
||||
switch(impactor.getType()){
|
||||
case Collidable.TYPE_TERRAIN:
|
||||
case Collidable.TYPE_STATIC:
|
||||
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
||||
// System.out.println();
|
||||
// System.out.println("Terrain-creature collision: " + normal + " mag:" + magnitude);
|
||||
@ -192,52 +201,11 @@ public class CollisionEngine {
|
||||
// normal.x = 0;
|
||||
// normal.z = 0;
|
||||
// }
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude * 2, Collidable.TYPE_TERRAIN));
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude * 2, Collidable.TYPE_STATIC));
|
||||
break;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
// float realMag = 1f/(float)Math.pow(0.1, magnitude);
|
||||
// System.out.println(normal + " - " + realMag);
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_ITEM));
|
||||
break;
|
||||
case Collidable.TYPE_OBJECT:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_OBJECT));
|
||||
break;
|
||||
case Collidable.TYPE_FOLIAGE_STATIC:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_OBJECT));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
switch(impactor.getType()){
|
||||
case Collidable.TYPE_TERRAIN:
|
||||
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
||||
// System.out.println();
|
||||
// System.out.println("Terrain-item collision: " + normal + " mag:" + magnitude);
|
||||
// if(normal.y > normal.x + normal.z){
|
||||
// normal.x = 0;
|
||||
// normal.z = 0;
|
||||
// }
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude * 2, Collidable.TYPE_TERRAIN));
|
||||
break;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
// float realMag = 1f/(float)Math.pow(0.1, magnitude);
|
||||
// System.out.println(normal + " - " + realMag);
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_ITEM));
|
||||
break;
|
||||
case Collidable.TYPE_OBJECT:
|
||||
receiver.addImpulse(new Impulse(normal, localPosition, worldPos, magnitude, Collidable.TYPE_OBJECT));
|
||||
break;
|
||||
@ -363,20 +331,19 @@ public class CollisionEngine {
|
||||
|
||||
if(
|
||||
!(
|
||||
bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN &&
|
||||
bodyPointerMap.get(b1).getType() == Collidable.TYPE_STATIC &&
|
||||
(
|
||||
bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN ||
|
||||
bodyPointerMap.get(b2).getType() == Collidable.TYPE_STATIC ||
|
||||
!b2.isEnabled()
|
||||
)
|
||||
) &&
|
||||
!(
|
||||
bodyPointerMap.get(b2).getType() == Collidable.TYPE_TERRAIN &&
|
||||
bodyPointerMap.get(b2).getType() == Collidable.TYPE_STATIC &&
|
||||
(
|
||||
bodyPointerMap.get(b1).getType() == Collidable.TYPE_TERRAIN ||
|
||||
bodyPointerMap.get(b1).getType() == Collidable.TYPE_STATIC ||
|
||||
!b1.isEnabled()
|
||||
)
|
||||
) &&
|
||||
!(bodyPointerMap.get(b1).getType() == Collidable.TYPE_FOLIAGE_STATIC && bodyPointerMap.get(b2).getType() == Collidable.TYPE_FOLIAGE_STATIC)
|
||||
)
|
||||
){
|
||||
try {
|
||||
//creates a buffer to store potential collisions
|
||||
|
||||
@ -489,7 +489,7 @@ public class PhysicsEntityUtils {
|
||||
*/
|
||||
public static void clientAttachTriGeomRigidBody(Entity terrain, TriGeomData data){
|
||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data, Collidable.TYPE_STATIC_BIT);
|
||||
Collidable collidable = new Collidable(terrain,Collidable.TYPE_TERRAIN, false);
|
||||
Collidable collidable = new Collidable(terrain,Collidable.TYPE_STATIC, false);
|
||||
Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, collidable);
|
||||
PhysicsEntityUtils.setDBody(terrain,terrainBody);
|
||||
terrain.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable);
|
||||
@ -506,7 +506,7 @@ public class PhysicsEntityUtils {
|
||||
Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain);
|
||||
DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(terrainRealm.getCollisionEngine(),data,Collidable.TYPE_STATIC_BIT);
|
||||
|
||||
terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false));
|
||||
terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_STATIC, false));
|
||||
PhysicsEntityUtils.setDBody(terrain,terrainBody);
|
||||
|
||||
return terrainBody;
|
||||
|
||||
@ -33,27 +33,12 @@ public class Collidable {
|
||||
public static final String TYPE_STATIC = "static";
|
||||
public static final long TYPE_STATIC_BIT = 0x1;
|
||||
|
||||
public static final String TYPE_TERRAIN = "terrain";
|
||||
public static final long TYPE_TERRAIN_BIT = 0x2;
|
||||
|
||||
public static final String TYPE_CREATURE = "creature";
|
||||
public static final long TYPE_CREATURE_BIT = 0x4;
|
||||
|
||||
public static final String TYPE_STRUCTURE = "structure";
|
||||
public static final long TYPE_STRUCTURE_BIT = 0x8;
|
||||
|
||||
public static final String TYPE_ITEM = "item";
|
||||
public static final long TYPE_ITEM_BIT = 0x10;
|
||||
|
||||
public static final String TYPE_FORCE = "force";
|
||||
public static final long TYPE_FORCE_BIT = 0x20;
|
||||
|
||||
public static final String TYPE_OBJECT = "object";
|
||||
public static final long TYPE_OBJECT_BIT = 0x40;
|
||||
|
||||
public static final String TYPE_FOLIAGE_STATIC = "foliageStatic";
|
||||
public static final long TYPE_FOLIAGE_BIT = 0x80;
|
||||
|
||||
public static final String TYPE_WORLD_BOUND = "worldBound";
|
||||
public static final long TYPE_WORLD_BOUND_BIT = 0x100;
|
||||
|
||||
@ -63,11 +48,7 @@ public class Collidable {
|
||||
public static final List<String> MASK_NO_TERRAIN = Arrays.asList(new String[]{
|
||||
TYPE_STATIC,
|
||||
TYPE_CREATURE,
|
||||
TYPE_STRUCTURE,
|
||||
TYPE_ITEM,
|
||||
TYPE_FORCE,
|
||||
TYPE_OBJECT,
|
||||
TYPE_FOLIAGE_STATIC,
|
||||
TYPE_WORLD_BOUND,
|
||||
});
|
||||
|
||||
|
||||
@ -48,11 +48,6 @@ public class ServerCollidableTree implements BehaviorTree {
|
||||
//have we hit a terrain impulse?
|
||||
//handle impulses
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.type.matches(Collidable.TYPE_ITEM)){
|
||||
if(ServerGravityTree.getServerGravityTree(parent)!=null){
|
||||
ServerGravityTree.getServerGravityTree(parent).start();
|
||||
}
|
||||
}
|
||||
if(impulse.type.matches(Collidable.TYPE_CREATURE)){
|
||||
if(ServerGravityTree.getServerGravityTree(parent)!=null){
|
||||
ServerGravityTree.getServerGravityTree(parent).start();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package electrosphere.entity.state.gravity;
|
||||
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.ode4j.ode.DBody;
|
||||
|
||||
import electrosphere.collision.collidable.Collidable;
|
||||
@ -95,8 +94,6 @@ public class ClientGravityTree implements BehaviorTree {
|
||||
switch(state){
|
||||
case ACTIVE:
|
||||
if(hadGroundCollision()){
|
||||
if(!hadStructureCollision()){
|
||||
}
|
||||
ClientJumpTree jumpTree;
|
||||
if((jumpTree = ClientJumpTree.getClientJumpTree(parent))!=null){
|
||||
jumpTree.land();
|
||||
@ -124,29 +121,13 @@ public class ClientGravityTree implements BehaviorTree {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hadStructureCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_STRUCTURE)){
|
||||
rVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public boolean hadGroundCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_TERRAIN)){
|
||||
if(impulse.getType().equals(Collidable.TYPE_STATIC)){
|
||||
rVal = true;
|
||||
break;
|
||||
} else if(
|
||||
impulse.getType().equals(Collidable.TYPE_STRUCTURE) &&
|
||||
new Vector3d(impulse.getDirection()).normalize().y > 0.7
|
||||
){
|
||||
rVal = true;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
|
||||
@ -6,7 +6,6 @@ import electrosphere.net.parser.net.message.SynchronizationMessage;
|
||||
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
||||
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.ode4j.ode.DBody;
|
||||
|
||||
import electrosphere.collision.collidable.Collidable;
|
||||
@ -129,21 +128,6 @@ public class ServerGravityTree implements BehaviorTree {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the gravity tree had a collision with a structure
|
||||
* @return true if collided on the most recent frame, false otherwise
|
||||
*/
|
||||
public boolean hadStructureCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_STRUCTURE)){
|
||||
rVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the gravity tree had a collision with terrain
|
||||
@ -152,14 +136,9 @@ public class ServerGravityTree implements BehaviorTree {
|
||||
public boolean hadGroundCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_TERRAIN)){
|
||||
if(impulse.getType().equals(Collidable.TYPE_STATIC)){
|
||||
rVal = true;
|
||||
break;
|
||||
} else if(
|
||||
impulse.getType().equals(Collidable.TYPE_STRUCTURE) &&
|
||||
new Vector3d(impulse.getDirection()).normalize().y > 0.7
|
||||
){
|
||||
rVal = true;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
|
||||
@ -133,7 +133,7 @@ public class CommonEntityUtils {
|
||||
DBody collisionObject = Globals.assetManager.fetchCollisionObject(Globals.clientSceneWrapper.getCollisionEngine(),rawType.getGraphicsTemplate().getModel().getPath());
|
||||
if(collisionObject != null){
|
||||
Globals.clientSceneWrapper.getScene().deregisterBehaviorTree(this);
|
||||
CollisionObjUtils.clientAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_TERRAIN);
|
||||
CollisionObjUtils.clientAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_STATIC);
|
||||
}
|
||||
}});
|
||||
} break;
|
||||
@ -352,9 +352,6 @@ public class CommonEntityUtils {
|
||||
ClientAlwaysUprightTree.attachTree(entity);
|
||||
CreatureUtils.setFacingVector(entity, SpatialMathUtils.getOriginVector());
|
||||
} break;
|
||||
case "TERRAIN_COLLISION": {
|
||||
CollisionObjUtils.getCollidable(entity).overrideType(Collidable.TYPE_TERRAIN);
|
||||
} break;
|
||||
case "BLENDER_ROTATION": {
|
||||
ActorUtils.applyBlenderRotation(entity);
|
||||
} break;
|
||||
@ -441,7 +438,7 @@ public class CommonEntityUtils {
|
||||
DBody collisionObject = Globals.assetManager.fetchCollisionObject(realm.getCollisionEngine(),rawType.getGraphicsTemplate().getModel().getPath());
|
||||
if(collisionObject != null){
|
||||
ServerBehaviorTreeUtils.detatchBTreeFromEntity(entity, this);
|
||||
CollisionObjUtils.serverAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_TERRAIN);
|
||||
CollisionObjUtils.serverAttachCollisionObjectToEntity(entity, collisionObject, 0, Collidable.TYPE_STATIC);
|
||||
}
|
||||
}});
|
||||
} break;
|
||||
@ -656,9 +653,6 @@ public class CommonEntityUtils {
|
||||
ServerAlwaysUprightTree.attachTree(entity);
|
||||
CreatureUtils.setFacingVector(entity, SpatialMathUtils.getOriginVector());
|
||||
} break;
|
||||
case "TERRAIN_COLLISION": {
|
||||
CollisionObjUtils.getCollidable(entity).overrideType(Collidable.TYPE_TERRAIN);
|
||||
} break;
|
||||
case "BLENDER_ROTATION": {
|
||||
ActorUtils.applyBlenderRotation(entity);
|
||||
} break;
|
||||
|
||||
@ -134,7 +134,7 @@ public class ProceduralTree {
|
||||
);
|
||||
CollisionBodyCreation.setOffsetPosition(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody, new Vector3d(0,treeModel.getPhysicsBody().getOffsetY(),0));
|
||||
CollisionBodyCreation.setKinematic(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody);
|
||||
Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_FOLIAGE_STATIC, true);
|
||||
Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_STATIC, true);
|
||||
PhysicsEntityUtils.setDBody(trunkChild, rigidBody);
|
||||
Matrix4d offsetTransform = new Matrix4d().translationRotateScale(
|
||||
0,treeModel.getPhysicsBody().getOffsetY(),0, //translate
|
||||
@ -539,7 +539,7 @@ public class ProceduralTree {
|
||||
);
|
||||
CollisionBodyCreation.setOffsetPosition(realm.getCollisionEngine(), rigidBody, new Vector3d(0,treeModel.getPhysicsBody().getOffsetY(),0));
|
||||
CollisionBodyCreation.setKinematic(realm.getCollisionEngine(), rigidBody);
|
||||
Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_FOLIAGE_STATIC, true);
|
||||
Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_STATIC, true);
|
||||
PhysicsEntityUtils.setDBody(trunkChild, rigidBody);
|
||||
Matrix4d offsetTransform = new Matrix4d().translationRotateScale(
|
||||
0,treeModel.getPhysicsBody().getOffsetY(),0, //translate
|
||||
|
||||
@ -85,6 +85,11 @@ public class CollidableTemplate {
|
||||
*/
|
||||
boolean kinematic;
|
||||
|
||||
/**
|
||||
* The type of body (ie creature, static, foliage, etc)
|
||||
*/
|
||||
String collisionType;
|
||||
|
||||
/**
|
||||
* The primitive shape type
|
||||
* @return The primitive shape
|
||||
@ -269,6 +274,22 @@ public class CollidableTemplate {
|
||||
this.kinematic = kinematic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of body (ie creature, static, foliage, etc)
|
||||
* @return The type of body (ie creature, static, foliage, etc)
|
||||
*/
|
||||
public String getCollisionType() {
|
||||
return collisionType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of body (ie creature, static, foliage, etc)
|
||||
* @param collisionType The type of body (ie creature, static, foliage, etc)
|
||||
*/
|
||||
public void setCollisionType(String collisionType) {
|
||||
this.collisionType = collisionType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user