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" : [
|
"movementSystems" : [
|
||||||
{
|
{
|
||||||
"type" : "GROUND",
|
"type" : "GROUND",
|
||||||
"acceleration" : 0.015,
|
"acceleration" : 0.0015,
|
||||||
"maxVelocity" : 0.15
|
"maxVelocity" : 0.015
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"collidable" : {
|
"collidable" : {
|
||||||
|
|||||||
@ -33,10 +33,19 @@
|
|||||||
"name" : "Bow",
|
"name" : "Bow",
|
||||||
"modelPath": "Models/bow1.fbx",
|
"modelPath": "Models/bow1.fbx",
|
||||||
"tokens" : [
|
"tokens" : [
|
||||||
"BLENDER_TRANSFORM",
|
"GRAVITY",
|
||||||
"WEAPON",
|
"WEAPON",
|
||||||
"RANGED"
|
"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
|
// //attach ai to evil goblin
|
||||||
// MindlessAttacker.attachToCreature(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");
|
// Entity fallOak = FoliageUtils.spawnBasicFoliage("FallOak1");
|
||||||
// EntityUtils.getPosition(fallOak).set(1,0,3);
|
// EntityUtils.getPosition(fallOak).set(1,0,3);
|
||||||
|
|||||||
@ -58,4 +58,8 @@ public class Entity {
|
|||||||
id = entity_id_iterator;
|
id = entity_id_iterator;
|
||||||
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;
|
static final float linearDamping = 0.1f;
|
||||||
|
|
||||||
public void simulate(float deltaTime){
|
public void simulate(float deltaTime){
|
||||||
float velocity = CreatureUtils.getVelocity(parent);
|
// float velocity = CreatureUtils.getVelocity(parent);
|
||||||
float acceleration = CreatureUtils.getAcceleration(parent);
|
// float acceleration = CreatureUtils.getAcceleration(parent);
|
||||||
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
// float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
||||||
Actor entityActor = EntityUtils.getActor(parent);
|
// Actor entityActor = EntityUtils.getActor(parent);
|
||||||
Vector3d position = EntityUtils.getPosition(parent);
|
Vector3d position = EntityUtils.getPosition(parent);
|
||||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
// Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
Vector3f newPosition;
|
Vector3f newPosition;
|
||||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
package electrosphere.entity.types.item;
|
package electrosphere.entity.types.item;
|
||||||
|
|
||||||
|
import electrosphere.collision.dispatch.CollisionObject;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.entity.state.GravityTree;
|
||||||
|
import electrosphere.entity.state.collidable.CollidableTree;
|
||||||
import electrosphere.entity.state.movement.GroundMovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.types.attach.AttachUtils;
|
import electrosphere.entity.types.attach.AttachUtils;
|
||||||
import electrosphere.entity.types.hitbox.HitboxData;
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
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.creature.type.CreatureType;
|
||||||
import electrosphere.game.config.item.type.Item;
|
import electrosphere.game.config.item.type.Item;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
@ -28,14 +34,58 @@ public class ItemUtils {
|
|||||||
public static Entity spawnBasicItem(String name){
|
public static Entity spawnBasicItem(String name){
|
||||||
Item item = Globals.gameConfigCurrent.getItemMap().getItem(name);
|
Item item = Globals.gameConfigCurrent.getItemMap().getItem(name);
|
||||||
Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath());
|
Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath());
|
||||||
for(HitboxData hitboxdata : item.getHitboxes()){
|
if(item.getHitboxes() != null){
|
||||||
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
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()){
|
for(String token : item.getTokens()){
|
||||||
switch(token){
|
switch(token){
|
||||||
case "BLENDER_TRANSFORM":
|
case "BLENDER_TRANSFORM":
|
||||||
ActorUtils.applyBlenderTransformer(rVal);
|
ActorUtils.applyBlenderTransformer(rVal);
|
||||||
break;
|
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);
|
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
||||||
@ -46,6 +96,31 @@ public class ItemUtils {
|
|||||||
return rVal;
|
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){
|
public static void updateItemActorAnimation(Entity item){
|
||||||
Actor actor = EntityUtils.getActor(item);
|
Actor actor = EntityUtils.getActor(item);
|
||||||
if(actor.getCurrentAnimation() == null){
|
if(actor.getCurrentAnimation() == null){
|
||||||
|
|||||||
@ -24,6 +24,7 @@ public class Collidable {
|
|||||||
public static final String TYPE_TERRAIN = "terrain";
|
public static final String TYPE_TERRAIN = "terrain";
|
||||||
public static final String TYPE_CREATURE = "creature";
|
public static final String TYPE_CREATURE = "creature";
|
||||||
public static final String TYPE_STRUCTURE = "structure";
|
public static final String TYPE_STRUCTURE = "structure";
|
||||||
|
public static final String TYPE_ITEM = "item";
|
||||||
|
|
||||||
|
|
||||||
public Collidable(Entity parent, String type){
|
public Collidable(Entity parent, String type){
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package electrosphere.game.config.item.type;
|
package electrosphere.game.config.item.type;
|
||||||
|
|
||||||
import electrosphere.entity.types.hitbox.HitboxData;
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
|
import electrosphere.game.config.creature.type.CollidableTemplate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
@ -8,6 +9,7 @@ public class Item {
|
|||||||
String modelPath;
|
String modelPath;
|
||||||
List<HitboxData> hitboxes;
|
List<HitboxData> hitboxes;
|
||||||
List<String> tokens;
|
List<String> tokens;
|
||||||
|
CollidableTemplate collidable;
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@ -25,5 +27,9 @@ public class Item {
|
|||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollidableTemplate getCollidable(){
|
||||||
|
return collidable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -489,6 +489,22 @@ public class RenderingEngine {
|
|||||||
physicsGraphicsModel.draw(true, true, false, true, true, true, true);
|
physicsGraphicsModel.draw(true, true, false, true, true, true, true);
|
||||||
}
|
}
|
||||||
break;
|
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