closes #60
Adds in world item entities that can be placed on ground. Physics needs major tweaking before they're really test-able
This commit is contained in:
parent
64e6d60755
commit
caa1bcd5d5
@ -88,8 +88,8 @@
|
||||
"movementSystems" : [
|
||||
{
|
||||
"type" : "GROUND",
|
||||
"acceleration" : 0.015,
|
||||
"maxVelocity" : 0.15
|
||||
"acceleration" : 0.0015,
|
||||
"maxVelocity" : 0.015
|
||||
}
|
||||
],
|
||||
"collidable" : {
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -58,4 +58,8 @@ public class Entity {
|
||||
id = entity_id_iterator;
|
||||
entity_id_iterator++;
|
||||
}
|
||||
|
||||
public void removeData(String key){
|
||||
data.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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<HitboxData> hitboxes;
|
||||
List<String> tokens;
|
||||
CollidableTemplate collidable;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@ -25,5 +27,9 @@ public class Item {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public CollidableTemplate getCollidable(){
|
||||
return collidable;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user