diff --git a/assets/Data/creatures.json b/assets/Data/creatures.json index 34307ab1..4756f206 100644 --- a/assets/Data/creatures.json +++ b/assets/Data/creatures.json @@ -88,8 +88,8 @@ "movementSystems" : [ { "type" : "GROUND", - "acceleration" : 0.015, - "maxVelocity" : 0.15 + "acceleration" : 0.0015, + "maxVelocity" : 0.015 } ], "collidable" : { diff --git a/assets/Data/items.json b/assets/Data/items.json index 47a79801..5a4fd997 100644 --- a/assets/Data/items.json +++ b/assets/Data/items.json @@ -33,10 +33,19 @@ "name" : "Bow", "modelPath": "Models/bow1.fbx", "tokens" : [ - "BLENDER_TRANSFORM", + "GRAVITY", "WEAPON", "RANGED" - ] + ], + "collidable": { + "type" : "CUBE", + "dimension1" : 0.1, + "dimension2" : 0.1, + "dimension3" : 0.1, + "offsetX" : 0, + "offsetY" : 0.1, + "offsetZ" : 0 + } } diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index 9bd77dce..88eddd4b 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -586,7 +586,10 @@ public class LoadingThread extends Thread { // //attach ai to evil goblin // MindlessAttacker.attachToCreature(goblin); - StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf()); +// StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf()); + + Entity bow = ItemUtils.spawnBasicItem("Bow"); + EntityUtils.getPosition(bow).set(1, 1, 2); // Entity fallOak = FoliageUtils.spawnBasicFoliage("FallOak1"); // EntityUtils.getPosition(fallOak).set(1,0,3); diff --git a/src/main/java/electrosphere/entity/Entity.java b/src/main/java/electrosphere/entity/Entity.java index 2c3a07e8..e7e9d4d9 100644 --- a/src/main/java/electrosphere/entity/Entity.java +++ b/src/main/java/electrosphere/entity/Entity.java @@ -58,4 +58,8 @@ public class Entity { id = entity_id_iterator; entity_id_iterator++; } + + public void removeData(String key){ + data.remove(key); + } } diff --git a/src/main/java/electrosphere/entity/state/GravityTree.java b/src/main/java/electrosphere/entity/state/GravityTree.java index 42b1fa52..64aa3334 100644 --- a/src/main/java/electrosphere/entity/state/GravityTree.java +++ b/src/main/java/electrosphere/entity/state/GravityTree.java @@ -73,12 +73,12 @@ public class GravityTree { static final float linearDamping = 0.1f; public void simulate(float deltaTime){ - float velocity = CreatureUtils.getVelocity(parent); - float acceleration = CreatureUtils.getAcceleration(parent); - float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent); - Actor entityActor = EntityUtils.getActor(parent); +// float velocity = CreatureUtils.getVelocity(parent); +// float acceleration = CreatureUtils.getAcceleration(parent); +// float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent); +// Actor entityActor = EntityUtils.getActor(parent); Vector3d position = EntityUtils.getPosition(parent); - Vector3f movementVector = CreatureUtils.getMovementVector(parent); +// Vector3f movementVector = CreatureUtils.getMovementVector(parent); Quaternionf rotation = EntityUtils.getRotation(parent); Vector3f newPosition; javax.vecmath.Matrix4f bodyTransformMatrix; diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index ba9497a9..05b006a0 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -1,12 +1,18 @@ package electrosphere.entity.types.item; +import electrosphere.collision.dispatch.CollisionObject; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; +import electrosphere.entity.state.GravityTree; +import electrosphere.entity.state.collidable.CollidableTree; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; +import electrosphere.game.collision.PhysicsUtils; +import electrosphere.game.collision.collidable.Collidable; +import electrosphere.game.config.creature.type.CollidableTemplate; import electrosphere.game.config.creature.type.CreatureType; import electrosphere.game.config.item.type.Item; import electrosphere.main.Globals; @@ -28,14 +34,58 @@ public class ItemUtils { public static Entity spawnBasicItem(String name){ Item item = Globals.gameConfigCurrent.getItemMap().getItem(name); Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath()); - for(HitboxData hitboxdata : item.getHitboxes()){ - Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); + if(item.getHitboxes() != null){ + for(HitboxData hitboxdata : item.getHitboxes()){ + Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); + } + } + if(item.getCollidable() != null){ + CollidableTemplate physicsTemplate = item.getCollidable(); + CollisionObject rigidBody; + Collidable collidable; + switch(physicsTemplate.getType()){ + case "CYLINDER": + rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3())); + collidable = new Collidable(rVal, Collidable.TYPE_ITEM); + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); + rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); + rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); + rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody)); + Globals.collisionEngine.registerPhysicsEntity(rVal); + Globals.collisionEngine.registerDynamicPhysicsEntity(rVal); + Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); + Globals.entityManager.registerCollidableEntity(rVal); + break; + case "CUBE": + rigidBody = PhysicsUtils.getCubeObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3())); + collidable = new Collidable(rVal, Collidable.TYPE_ITEM); + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); + rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); + rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); + rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody)); + Globals.collisionEngine.registerPhysicsEntity(rVal); + Globals.collisionEngine.registerDynamicPhysicsEntity(rVal); + Globals.collisionEngine.registerCollisionObject(rigidBody, collidable); + Globals.entityManager.registerCollidableEntity(rVal); + break; + } } for(String token : item.getTokens()){ switch(token){ case "BLENDER_TRANSFORM": ActorUtils.applyBlenderTransformer(rVal); break; + case "GRAVITY": + Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); + CollisionObject collisionObject = (CollisionObject)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); + GravityTree gravityTree = new GravityTree(rVal,collidable,collisionObject); +// gravityTree.setCollisionObject(collisionObject, collidable); + rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); + rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree); + Globals.entityManager.registerGravityEntity(rVal); + break; } } rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true); @@ -46,6 +96,31 @@ public class ItemUtils { return rVal; } + public static void removePhysics(Entity item){ + /* + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); + rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); + rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); + rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE,collidable); + rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody)); + */ + if(item.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY)){ + item.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY); + } + if(item.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET)){ + item.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET); + } + if(item.getDataKeys().contains(EntityDataStrings.PHYSICS_MODEL_TEMPLATE)){ + item.removeData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); + } + if(item.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + item.removeData(EntityDataStrings.PHYSICS_COLLIDABLE); + } + if(item.getDataKeys().contains(EntityDataStrings.COLLIDABLE_TREE)){ + item.removeData(EntityDataStrings.COLLIDABLE_TREE); + } + } + public static void updateItemActorAnimation(Entity item){ Actor actor = EntityUtils.getActor(item); if(actor.getCurrentAnimation() == null){ diff --git a/src/main/java/electrosphere/game/collision/collidable/Collidable.java b/src/main/java/electrosphere/game/collision/collidable/Collidable.java index 8622c453..252f1e8d 100644 --- a/src/main/java/electrosphere/game/collision/collidable/Collidable.java +++ b/src/main/java/electrosphere/game/collision/collidable/Collidable.java @@ -24,6 +24,7 @@ public class Collidable { public static final String TYPE_TERRAIN = "terrain"; public static final String TYPE_CREATURE = "creature"; public static final String TYPE_STRUCTURE = "structure"; + public static final String TYPE_ITEM = "item"; public Collidable(Entity parent, String type){ diff --git a/src/main/java/electrosphere/game/config/item/type/Item.java b/src/main/java/electrosphere/game/config/item/type/Item.java index f9c2169a..f5658a7f 100644 --- a/src/main/java/electrosphere/game/config/item/type/Item.java +++ b/src/main/java/electrosphere/game/config/item/type/Item.java @@ -1,6 +1,7 @@ package electrosphere.game.config.item.type; import electrosphere.entity.types.hitbox.HitboxData; +import electrosphere.game.config.creature.type.CollidableTemplate; import java.util.List; public class Item { @@ -8,6 +9,7 @@ public class Item { String modelPath; List hitboxes; List tokens; + CollidableTemplate collidable; public String getName() { return name; @@ -25,5 +27,9 @@ public class Item { return tokens; } + public CollidableTemplate getCollidable(){ + return collidable; + } + } diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index 9146bcd4..1d008e3b 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -489,6 +489,22 @@ public class RenderingEngine { physicsGraphicsModel.draw(true, true, false, true, true, true, true); } break; + case "CUBE": + if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){ + Vector3d position = EntityUtils.getPosition(physicsEntity); + Vector3f scale = EntityUtils.getScale(physicsEntity); + Quaternionf rotation = EntityUtils.getRotation(physicsEntity); + //calculate camera-modified vector3f + Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + modelTransformMatrix.identity(); + modelTransformMatrix.translate(cameraModifiedPosition); + modelTransformMatrix.rotate(rotation); + // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere + modelTransformMatrix.scale(scale); + physicsGraphicsModel.modelMatrix = modelTransformMatrix; + physicsGraphicsModel.draw(true, true, false, true, true, true, true); + } + break; } } }