diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index a46324d5..36df5f82 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -267,7 +267,7 @@ "collidable" : { "type" : "CYLINDER", "dimension1" : 0.1, - "dimension2" : 0.9, + "dimension2" : 0.8, "dimension3" : 0.1, "rotX": 0, "rotY": 0, diff --git a/docs/src/physics/collision.md b/docs/src/physics/collision.md index 4782c660..c2543374 100644 --- a/docs/src/physics/collision.md +++ b/docs/src/physics/collision.md @@ -26,6 +26,7 @@ The big case for this engine is the main physics system. The goal is to provide - All geometries are aligned along z by default in the library (ie your cylinders will be on their sides) - All functions that transform the scale of a DBody only transform the first shape within the rigid body. This should likely eventually be updated to support multiple shapes in a body. + - Furthermore, these transform functions require the CollidableTemplate to modify scale. Ode4J doesn't provide a "scale" function, instead it lets you change the core params. To scale, must know the original size. diff --git a/docs/src/resources/modelLoading.md b/docs/src/resources/modelLoading.md index 979a7eed..473806ee 100644 --- a/docs/src/resources/modelLoading.md +++ b/docs/src/resources/modelLoading.md @@ -10,7 +10,7 @@ TODO ## Major Usage Notes - + - Global pretransforms are applied to the global inverse bind pose matrix diff --git a/src/main/java/electrosphere/collision/CollisionBodyCreation.java b/src/main/java/electrosphere/collision/CollisionBodyCreation.java index 02f42bf0..d2319dfd 100644 --- a/src/main/java/electrosphere/collision/CollisionBodyCreation.java +++ b/src/main/java/electrosphere/collision/CollisionBodyCreation.java @@ -65,7 +65,7 @@ public class CollisionBodyCreation { public static DBody createCylinderBody(CollisionEngine collisionEngine, double radius, double length){ DCylinder geom = collisionEngine.createCylinderGeom(radius,length); DBody returnBody = collisionEngine.createDBody(geom); - geom.setOffsetRotation(AXIS_CORRECTION_MATRIX); + geom.setOffsetRotation(AXIS_CORRECTION_MATRIX); //ode4j required geom to already be on body before rotating for some reason return returnBody; } diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index b13b5daf..60bf98c3 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -52,6 +52,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.collidable.Impulse; import electrosphere.entity.types.hitbox.HitboxData; +import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.logger.LoggerInterface; /** @@ -647,17 +648,17 @@ public class CollisionEngine { * @param rotation The rotation * @param scale The scale */ - protected void setBodyTransform(DBody body, Vector3d position, Quaterniond rotation, Vector3d scale){ + protected void setBodyTransform(DBody body, CollidableTemplate template, Vector3d position, Quaterniond rotation, Vector3d scale){ spaceLock.acquireUninterruptibly(); body.setPosition(position.x, position.y, position.z); body.setQuaternion(PhysicsUtils.jomlQuatToOdeQuat(rotation)); DGeom firstGeom = body.getFirstGeom(); if(firstGeom instanceof DCylinder){ - ((DCylinder)firstGeom).setParams(scale.x,scale.y); + ((DCylinder)firstGeom).setParams(template.getDimension1() * scale.x,template.getDimension2() * scale.y); } else if(firstGeom instanceof DBox){ - ((DBox)firstGeom).setLengths(scale.x,scale.y,scale.z); + ((DBox)firstGeom).setLengths(template.getDimension1() * scale.x,template.getDimension2() * scale.y,template.getDimension3() * scale.z); } else if(firstGeom instanceof DCapsule){ - ((DCapsule)firstGeom).setParams(scale.x,scale.y); + ((DCapsule)firstGeom).setParams(template.getDimension1() * scale.x,template.getDimension2() * scale.y); } spaceLock.release(); } diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 8d8c8c85..33fff991 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -46,10 +46,9 @@ public class PhysicsEntityUtils { collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); ClientCollidableTree tree = new ClientCollidableTree(rVal,collidable,rigidBody); rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); - Matrix4d offsetTransform = new Matrix4d().translationRotateScale( + Matrix4d offsetTransform = new Matrix4d().translationRotate( physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ(), //translate - physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW(), //rotate - 1, 1, 1 //scale + physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW() //rotate ); rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); diff --git a/src/main/java/electrosphere/collision/PhysicsUtils.java b/src/main/java/electrosphere/collision/PhysicsUtils.java index 133745b5..9b7165bb 100644 --- a/src/main/java/electrosphere/collision/PhysicsUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsUtils.java @@ -7,6 +7,8 @@ import org.ode4j.math.DQuaternionC; import org.ode4j.ode.DBody; import org.ode4j.ode.DMass; +import electrosphere.game.data.collidable.CollidableTemplate; + /** * Utilities for leveraging the collision system to perform physics */ @@ -76,8 +78,8 @@ public class PhysicsUtils { * @param scale The scale * @param body The body */ - public static void setRigidBodyTransform(CollisionEngine collisionEngine, Vector3d position, Quaterniond rotation, Vector3d scale, DBody body){ - collisionEngine.setBodyTransform(body, position, rotation, scale); + public static void setRigidBodyTransform(CollisionEngine collisionEngine, CollidableTemplate template, Vector3d position, Quaterniond rotation, Vector3d scale, DBody body){ + collisionEngine.setBodyTransform(body, template, position, rotation, scale); } /** diff --git a/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java b/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java index 6313563d..d90b4bdc 100644 --- a/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java +++ b/src/main/java/electrosphere/entity/state/collidable/ClientCollidableTree.java @@ -217,10 +217,10 @@ public class ClientCollidableTree implements BehaviorTree { Vector4d rigidBodyPositionRaw = parentTransform.transform(new Vector4d(0,0,0,1)); Vector3d rigidBodyPosition = new Vector3d(rigidBodyPositionRaw.x,rigidBodyPositionRaw.y,rigidBodyPositionRaw.z); Quaterniond rigidBodyRotation = parentTransform.getUnnormalizedRotation(new Quaterniond()).normalize(); - Vector3d rigidBodyScaleRaw = parentTransform.getScale(new Vector3d()); - Vector3d rigidBodyScale = new Vector3d(rigidBodyScaleRaw.x,rigidBodyScaleRaw.y,rigidBodyScaleRaw.z); + Vector3d rigidBodyScale = new Vector3d(parentScale); PhysicsUtils.setRigidBodyTransform( Globals.clientSceneWrapper.getCollisionEngine(), + template, rigidBodyPosition, rigidBodyRotation, rigidBodyScale,