diff --git a/assets/Data/entity/objects/containers.json b/assets/Data/entity/objects/containers.json
index 736d8b6e..c2f3cfb1 100644
--- a/assets/Data/entity/objects/containers.json
+++ b/assets/Data/entity/objects/containers.json
@@ -12,6 +12,9 @@
],
"collidable": {
"type" : "CUBE",
+ "mass": 10.0,
+ "rollingFriction": 100.0,
+ "linearFriction": 100.0,
"dimension1" : 2.0,
"dimension2" : 2.0,
"dimension3" : 2.0,
diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md
index b2c39db9..b0cee678 100644
--- a/docs/src/progress/renderertodo.md
+++ b/docs/src/progress/renderertodo.md
@@ -744,6 +744,8 @@ Move AttachUtils package
Move Scene package
Crate object
Data cleanup
+Delete Structure entity type
+Physics work
# TODO
diff --git a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java
index 1e846e3e..e48f8403 100644
--- a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java
+++ b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java
@@ -64,9 +64,12 @@ public class ClientSceneWrapper {
/**
* Resolves a client ID to the equivalent ID on the server
* @param clientId The id provided by the client
- * @return The equivalent id on the server
+ * @return The equivalent id on the server, or -1 if no equivalent is found
*/
public int mapClientToServerId(int clientId){
+ if(clientToServerIdMap.get(clientId) == null){
+ return -1;
+ }
return clientToServerIdMap.get(clientId);
}
diff --git a/src/main/java/electrosphere/collision/CollisionBodyCreation.java b/src/main/java/electrosphere/collision/CollisionBodyCreation.java
index 6f8db4f4..da52eaaa 100644
--- a/src/main/java/electrosphere/collision/CollisionBodyCreation.java
+++ b/src/main/java/electrosphere/collision/CollisionBodyCreation.java
@@ -2,6 +2,7 @@ package electrosphere.collision;
import java.nio.IntBuffer;
+import org.joml.Quaterniond;
import org.joml.Vector3d;
import org.lwjgl.PointerBuffer;
import org.lwjgl.assimp.AIFace;
@@ -14,6 +15,7 @@ import org.ode4j.ode.DBox;
import org.ode4j.ode.DCapsule;
import org.ode4j.ode.DCylinder;
import org.ode4j.ode.DGeom;
+import org.ode4j.ode.DMass;
import org.ode4j.ode.DSphere;
import org.ode4j.ode.DTriMesh;
@@ -83,6 +85,18 @@ public class CollisionBodyCreation {
return collisionEngine.createDBody(geom);
}
+ /**
+ * Creates a capsule body in the collision engine
+ * @param collisionEngine The collision engine
+ * @param length The length of the capsule (not including round part at ends)
+ * @param radius The radius of the sphere
+ * @return The DBody
+ */
+ public static DBody createCapsuleBody(CollisionEngine collisionEngine, double length, double radius, long categoryBits){
+ DCapsule geom = collisionEngine.createCapsuleGeom(radius,length,categoryBits);
+ return collisionEngine.createDBody(geom);
+ }
+
/**
* Creates a dbody with existing shapes that are provided
* @param collisionEngine the collision engine to create it in
@@ -116,6 +130,42 @@ public class CollisionBodyCreation {
return collisionEngine.createCapsuleGeom(radius, length, categoryBits);
}
+ /**
+ * Sets the mass on the dbody
+ * @param collisionEngine The collision engine
+ * @param body The body
+ * @param mass The mass value
+ * @param radius The radius of the cylinder
+ * @param length The length of the cylinder
+ * @return The DMass object
+ */
+ public static DMass setCylinderMass(CollisionEngine collisionEngine, DBody body, double mass, double radius, double length, Vector3d offset, Quaterniond rotation){
+ return collisionEngine.createCylinderMass(mass, radius, length, body, offset, rotation);
+ }
+
+ /**
+ * Sets the mass on the dbody
+ * @param collisionEngine The collision engine
+ * @param body The body
+ * @param mass The mass value
+ * @param dims The dimensions of the box
+ * @return The DMass object
+ */
+ public static DMass setBoxMass(CollisionEngine collisionEngine, DBody body, double mass, Vector3d dims, Vector3d offset, Quaterniond rotation){
+ return collisionEngine.createBoxMass(mass, dims, body, offset, rotation);
+ }
+
+ /**
+ * Sets the damping for the body
+ * @param collisionEngine The collision engine
+ * @param body The body
+ * @param linearDamping The linear damping
+ * @param angularDamping The angular damping
+ */
+ public static void setDamping(CollisionEngine collisionEngine, DBody body, double linearDamping, double angularDamping){
+ collisionEngine.setDamping(body, linearDamping, angularDamping);
+ }
+
/**
* Sets the provided body to be a kinematic body (no gravity applied)
* @param collisionEngine The collision engine
diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java
index c1c40c4f..070cdfda 100644
--- a/src/main/java/electrosphere/collision/CollisionEngine.java
+++ b/src/main/java/electrosphere/collision/CollisionEngine.java
@@ -19,7 +19,6 @@ import org.joml.Matrix4d;
import org.joml.Quaterniond;
import org.joml.Vector3d;
import org.joml.Vector4d;
-import org.ode4j.math.DMatrix3;
import org.ode4j.math.DVector3;
import org.ode4j.ode.DBody;
import org.ode4j.ode.DBox;
@@ -40,11 +39,11 @@ import org.ode4j.ode.DSphere;
import org.ode4j.ode.DTriMesh;
import org.ode4j.ode.DTriMeshData;
import org.ode4j.ode.DWorld;
-import org.ode4j.ode.OdeConstants;
import org.ode4j.ode.OdeHelper;
import electrosphere.collision.RayCastCallback.RayCastCallbackData;
import electrosphere.collision.collidable.Collidable;
+import electrosphere.collision.collidable.SurfaceParams;
import electrosphere.engine.Globals;
import electrosphere.engine.time.Timekeeper;
import electrosphere.entity.Entity;
@@ -63,6 +62,21 @@ public class CollisionEngine {
//gravity constant
public static final float GRAVITY_MAGNITUDE = 9.8f * 2;
+
+ /**
+ * The damping applied to angular velocity
+ */
+ public static final double DEFAULT_ANGULAR_DAMPING = 0.01;
+
+ /**
+ * The damping applied to linear velocity
+ */
+ public static final double DEFAULT_LINEAR_DAMPING = 0.01;
+
+ /**
+ * Default max angular speed
+ */
+ public static final double DEFAULT_MAX_ANGULAR_SPEED = 100;
//world data that the collision engine leverages for position correction and the like
CollisionWorldData collisionWorldData;
@@ -103,6 +117,15 @@ public class CollisionEngine {
world = OdeHelper.createWorld();
space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT);
world.setGravity(0,-GRAVITY_MAGNITUDE,0);
+ world.setAutoDisableFlag(true);
+ // world.setContactMaxCorrectingVel(0.1);
+ world.setContactSurfaceLayer(0.001);
+ world.setCFM(0.00000001);
+
+ //base plane
+ OdeHelper.createPlane(space, 0, 1, 0, 0);
+
+
contactgroup = OdeHelper.createJointGroup();
this.nearCallback = new DNearCallback() {
@Override
@@ -296,33 +319,52 @@ public class CollisionEngine {
return;
}
- //creates a buffer to store potential collisions
- DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS); // up to MAX_CONTACTS contacts per box-box
- for (int i=0; i The mode flags for the surface This must always be set. This is a combination of one or more of the following flags.
+ * Possible values:
+ *
+ *
+ *
Coulomb friction coefficient
+ *Ranges [0,infinity)
+ *0 is a frictionless contact, dInfinity results in a contact that never slips.
+ *Note that frictionless contacts are less time consume to compute than ones with friction.
+ *This must always be set.
+ */ + Double mu; + + /** + *Rolling friction coefficient around direction 1.
+ */ + Double rho; + + /** + *Rolling friction coefficient around direction 2.
+ */ + Double rho2; + + /** + *Rolling friction coefficient around the normal direction.
+ */ + Double rhoN; + + /** + *Restitution parameter
+ *Ranges (0,1)
+ *0 means the surfaces are not bouncy at all. 1 is maximum bounciness.
+ *Note that mode must be set with dContactBounce.
+ */ + Double bounce; + + /** + *Minimum velocity to trigger a bounce
+ *All velocities below this threshold will effectively have bounce parameter of 0.
+ *Note that mode must be set with ??put flat here??.
+ */ + Double bounceVel; + + /** + * Constructor + */ + public SurfaceParams(){ + mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling & OdeConstants.dContactBounce; + mu = 10.0; + rho = 10.0; + rho2 = 10.0; + rhoN = 10.0; + bounce = 0.001; + bounceVel = 100.0; + } + + /** + * Gets the mode for the surface + * @return The mode + */ + public int getMode(){ + return mode; + } + + /** + * Gets the mu for the surface + * @return The mu + */ + public Double getMu(){ + return mu; + } + + /** + * Gets the rho for the surface; + * @return The rho + */ + public Double getRho(){ + return rho; + } + + /** + * Gets the rho2 for the surface; + * @return The rho2 + */ + public Double getRho2(){ + return rho2; + } + + /** + * Gets the rhoN for the surface; + * @return The rhoN + */ + public Double getRhoN(){ + return rhoN; + } + + /** + * Gets the bounce for the surface; + * @return The bounce + */ + public Double getBounce(){ + return bounce; + } + + /** + * Gets the bounce minimum velocity for the surface; + * @return The bounce minimum velocity + */ + public Double getBounceVel(){ + return bounceVel; + } + + /** + * Sets the rolling friction of the surface params + * @param friction The rolling friction + */ + public void setRollingFriction(double friction){ + this.rho = this.rho2 = this.rhoN = friction; + } + + /** + * Sets the lienar friction + * @param linearFriction The linear friction + */ + public void setLinearFriction(double linearFriction){ + this.mu = linearFriction; + } + +} diff --git a/src/main/java/electrosphere/engine/Main.java b/src/main/java/electrosphere/engine/Main.java index a8121446..9eca8430 100644 --- a/src/main/java/electrosphere/engine/Main.java +++ b/src/main/java/electrosphere/engine/Main.java @@ -5,7 +5,6 @@ import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose; import java.util.concurrent.TimeUnit; import org.graalvm.polyglot.HostAccess.Export; - import org.ode4j.ode.OdeHelper; import electrosphere.audio.AudioEngine; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index 004e011b..65ae8414 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -322,6 +322,7 @@ public class ClientGroundMovementTree implements BehaviorTree { } CreatureUtils.setVelocity(parent, velocity); //actually update + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -353,6 +354,7 @@ public class ClientGroundMovementTree implements BehaviorTree { this.updateVelocity(); float velocity = this.getModifiedVelocity(); + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -400,6 +402,7 @@ public class ClientGroundMovementTree implements BehaviorTree { } CreatureUtils.setVelocity(parent, velocity); } + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index b1b8a1ec..c0fbcacb 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -272,6 +272,7 @@ public class ServerGroundMovementTree implements BehaviorTree { state = MovementTreeState.MOVE; CreatureUtils.setVelocity(parent, velocity); } + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -317,6 +318,7 @@ public class ServerGroundMovementTree implements BehaviorTree { } this.updateVelocity(); float velocity = this.getModifiedVelocity(); + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -383,6 +385,7 @@ public class ServerGroundMovementTree implements BehaviorTree { // linearVelocity.get1(), // movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() // ); + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 79546ff6..135fa56a 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -332,6 +332,9 @@ public class CreatureUtils { } public static float getVelocity(Entity e){ + if(!e.containsKey(EntityDataStrings.DATA_STRING_VELOCITY)){ + return 0; + } return (float)e.getData(EntityDataStrings.DATA_STRING_VELOCITY); } diff --git a/src/main/java/electrosphere/game/data/Config.java b/src/main/java/electrosphere/game/data/Config.java index 67a3e56e..8f78188d 100644 --- a/src/main/java/electrosphere/game/data/Config.java +++ b/src/main/java/electrosphere/game/data/Config.java @@ -15,7 +15,6 @@ import electrosphere.game.data.foliage.type.model.FoliageTypeMap; import electrosphere.game.data.item.type.model.ItemTypeMap; import electrosphere.game.data.particle.ParticleDefinition; import electrosphere.game.data.projectile.ProjectileTypeHolder; -import electrosphere.game.data.structure.type.model.StructureTypeMap; import electrosphere.game.data.tutorial.HintDefinition; import electrosphere.game.data.units.UnitDefinitionFile; import electrosphere.game.data.units.UnitLoader; @@ -30,7 +29,6 @@ import electrosphere.util.FileUtils; public class Config { CreatureTypeLoader creatureTypeLoader; - StructureTypeMap structureTypeMap; ItemTypeMap itemMap; FoliageTypeMap foliageMap; CommonEntityMap objectTypeLoader; @@ -67,7 +65,6 @@ public class Config { Config config = new Config(); config.creatureTypeLoader = loadCreatureTypes("Data/entity/creatures.json"); config.itemMap = FileUtils.loadObjectFromAssetPath("Data/entity/items.json", ItemTypeMap.class); - config.structureTypeMap = FileUtils.loadObjectFromAssetPath("Data/entity/structures.json", StructureTypeMap.class); config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/entity/foliage.json", FoliageTypeMap.class); config.objectTypeLoader = loadCommonEntityTypes("Data/entity/objects.json"); config.symbolMap = FileUtils.loadObjectFromAssetPath("Data/game/symbolism.json", SymbolMap.class); @@ -176,14 +173,6 @@ public class Config { return creatureTypeLoader; } - /** - * Gets the data on all structure entities in memory - * @return The structure definitions - */ - public StructureTypeMap getStructureTypeMap() { - return structureTypeMap; - } - /** * Gets the data on all item types in memory * @return the data on all items diff --git a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java index 35324de5..325e39bb 100644 --- a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java +++ b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java @@ -5,6 +5,9 @@ package electrosphere.game.data.collidable; */ public class CollidableTemplate { + /** + * The primitive shape type + */ String type; float dimension1; @@ -20,11 +23,30 @@ public class CollidableTemplate { float offsetY; float offsetZ; + /** + * The mass of the body + */ + Double mass; + + /** + * The linear friction of the body + */ + Double linearFriction; + + /** + * The rolling friction of the body (ie if it's a sphere, what's the friction keeping it from spinning) + */ + Double rollingFriction; + /** * Controls whether the body can rotate or not */ boolean angularlyStatic; + /** + * The primitive shape type + * @return The primitive shape + */ public String getType() { return type; } @@ -69,6 +91,30 @@ public class CollidableTemplate { return offsetZ; } + /** + * Gets the mass of the body + * @return The mass + */ + public Double getMass(){ + return mass; + } + + /** + * Gets the linear friction + * @return The linear friction + */ + public Double getLinearFriction(){ + return linearFriction; + } + + /** + * Gets the rolling friction (ie if it's a sphere, what's the friction keeping it from spinning) + * @return The rolling friction + */ + public Double getRollingFriction(){ + return rollingFriction; + } + /** * Gets if the body should always be allowed to rotate or not * @return true if should always be allowed to rotate, false otherwise diff --git a/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java b/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java deleted file mode 100644 index cd219d72..00000000 --- a/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java +++ /dev/null @@ -1,73 +0,0 @@ -package electrosphere.game.data.structure.type.model; - -/** - * Collidable data - */ -public class CollisionObjectTemplate { - - String type; - public static final String TYPE_CUBE = "CUBE"; - public static final String TYPE_PLANE = "PLANE"; - - - float positionX; - float positionY; - float positionZ; - - float scaleX; - float scaleY; - float scaleZ; - - float rotationW; - float rotationX; - float rotationY; - float rotationZ; - - public String getType() { - return type; - } - - public float getPositionX() { - return positionX; - } - - public float getPositionY() { - return positionY; - } - - public float getPositionZ() { - return positionZ; - } - - public float getScaleX() { - return scaleX; - } - - public float getScaleY() { - return scaleY; - } - - public float getScaleZ() { - return scaleZ; - } - - public float getRotationW() { - return rotationW; - } - - public float getRotationX() { - return rotationX; - } - - public float getRotationY() { - return rotationY; - } - - public float getRotationZ() { - return rotationZ; - } - - - - -} diff --git a/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java b/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java deleted file mode 100644 index 0bcd81a2..00000000 --- a/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java +++ /dev/null @@ -1,34 +0,0 @@ -package electrosphere.game.data.structure.type.model; - -import java.util.List; - -/** - * Structure data - */ -public class StructureType { - - String modelPath; - String name; - float radius; - - List