closes #25
Unifies gravity and movement trees under common "collidabletree" that parses impulses from collidable objects
This commit is contained in:
parent
766093d843
commit
64e6d60755
@ -88,11 +88,11 @@
|
|||||||
"movementSystems" : [
|
"movementSystems" : [
|
||||||
{
|
{
|
||||||
"type" : "GROUND",
|
"type" : "GROUND",
|
||||||
"acceleration" : 0.15,
|
"acceleration" : 0.015,
|
||||||
"maxVelocity" : 1.5
|
"maxVelocity" : 0.15
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"physicsObject" : {
|
"collidable" : {
|
||||||
"type" : "CYLINDER",
|
"type" : "CYLINDER",
|
||||||
"dimension1" : 0.1,
|
"dimension1" : 0.1,
|
||||||
"dimension2" : 0.45,
|
"dimension2" : 0.45,
|
||||||
@ -216,7 +216,7 @@
|
|||||||
"maxVelocity" : 0.025
|
"maxVelocity" : 0.025
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"physicsObject" : {
|
"collidable" : {
|
||||||
"type" : "CYLINDER",
|
"type" : "CYLINDER",
|
||||||
"dimension1" : 0.1,
|
"dimension1" : 0.1,
|
||||||
"dimension2" : 0.2,
|
"dimension2" : 0.2,
|
||||||
@ -271,7 +271,7 @@
|
|||||||
"maxVelocity" : 1
|
"maxVelocity" : 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"physicsObject" : {
|
"collidable" : {
|
||||||
"type" : "CYLINDER",
|
"type" : "CYLINDER",
|
||||||
"dimension1" : 0.1,
|
"dimension1" : 0.1,
|
||||||
"dimension2" : 0.45,
|
"dimension2" : 0.45,
|
||||||
@ -330,7 +330,7 @@
|
|||||||
"maxVelocity" : 0.025
|
"maxVelocity" : 0.025
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"physicsObject" : {
|
"collidable" : {
|
||||||
"type" : "CYLINDER",
|
"type" : "CYLINDER",
|
||||||
"dimension1" : 0.1,
|
"dimension1" : 0.1,
|
||||||
"dimension2" : 0.2,
|
"dimension2" : 0.2,
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import electrosphere.entity.EntityDataStrings;
|
|||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.AttackTree;
|
import electrosphere.entity.state.AttackTree;
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.state.movement.MovementTree.MovementTreeState;
|
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.menu.MenuTransition;
|
import electrosphere.menu.MenuTransition;
|
||||||
import electrosphere.net.parser.net.message.EntityMessage;
|
import electrosphere.net.parser.net.message.EntityMessage;
|
||||||
@ -213,7 +213,7 @@ public class ControlHandler {
|
|||||||
|
|
||||||
public void pollMainGameControls(){
|
public void pollMainGameControls(){
|
||||||
if(Globals.playerCharacter != null){
|
if(Globals.playerCharacter != null){
|
||||||
MovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
|
||||||
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerCharacter);
|
AttackTree attackTree = CreatureUtils.getAttackTree(Globals.playerCharacter);
|
||||||
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -114,7 +114,7 @@ public class EntityDataStrings {
|
|||||||
|
|
||||||
public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent";
|
public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent";
|
||||||
|
|
||||||
public static final String COLLISION_ENTITY_BEHAVIOR_TREE = "collisionEntityBehaviorTree";
|
public static final String COLLIDABLE_TREE = "collidableTree";
|
||||||
|
|
||||||
public static final String HITBOX_DATA = "hitboxData";
|
public static final String HITBOX_DATA = "hitboxData";
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ public class EntityManager {
|
|||||||
static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList();
|
static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList();
|
||||||
static CopyOnWriteArrayList<Entity> particleList = new CopyOnWriteArrayList();
|
static CopyOnWriteArrayList<Entity> particleList = new CopyOnWriteArrayList();
|
||||||
static CopyOnWriteArrayList<Entity> gravityList = new CopyOnWriteArrayList();
|
static CopyOnWriteArrayList<Entity> gravityList = new CopyOnWriteArrayList();
|
||||||
|
static CopyOnWriteArrayList<Entity> collidableList = new CopyOnWriteArrayList();
|
||||||
|
|
||||||
public EntityManager(){
|
public EntityManager(){
|
||||||
|
|
||||||
@ -128,6 +129,14 @@ public class EntityManager {
|
|||||||
return gravityList;
|
return gravityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerCollidableEntity(Entity e){
|
||||||
|
collidableList.add(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CopyOnWriteArrayList<Entity> getCollidables(){
|
||||||
|
return collidableList;
|
||||||
|
}
|
||||||
|
|
||||||
public void deregisterEntity(Entity e){
|
public void deregisterEntity(Entity e){
|
||||||
if(lightList.contains(e)){
|
if(lightList.contains(e)){
|
||||||
lightList.remove(e);
|
lightList.remove(e);
|
||||||
@ -163,6 +172,9 @@ public class EntityManager {
|
|||||||
if(gravityList.contains(e)){
|
if(gravityList.contains(e)){
|
||||||
gravityList.remove(e);
|
gravityList.remove(e);
|
||||||
}
|
}
|
||||||
|
if(collidableList.contains(e)){
|
||||||
|
collidableList.remove(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recursiveDeregister(Entity target){
|
public void recursiveDeregister(Entity target){
|
||||||
|
|||||||
@ -5,7 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package electrosphere.entity;
|
package electrosphere.entity;
|
||||||
|
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.collidable.CollidableTree;
|
||||||
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.entity.types.item.ItemUtils;
|
import electrosphere.entity.types.item.ItemUtils;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
@ -90,4 +91,8 @@ public class EntityUtils {
|
|||||||
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
|
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CollidableTree getCollidableTree(Entity e){
|
||||||
|
return (CollidableTree)e.getData(EntityDataStrings.COLLIDABLE_TREE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package electrosphere.entity.state;
|
|||||||
import electrosphere.collision.dispatch.CollisionObject;
|
import electrosphere.collision.dispatch.CollisionObject;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.movement.Impulse;
|
import electrosphere.entity.state.collidable.Impulse;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.game.collision.PhysicsUtils;
|
import electrosphere.game.collision.PhysicsUtils;
|
||||||
import electrosphere.game.collision.collidable.Collidable;
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
@ -39,16 +39,18 @@ public class GravityTree {
|
|||||||
|
|
||||||
int maxFrame = 60;
|
int maxFrame = 60;
|
||||||
|
|
||||||
public GravityTree(Entity e){
|
public GravityTree(Entity e, Collidable collidable, CollisionObject body){
|
||||||
state = GravityTreeState.ACTIVE;
|
state = GravityTreeState.ACTIVE;
|
||||||
parent = e;
|
parent = e;
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollisionObject(CollisionObject body, Collidable collidable){
|
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.collidable = collidable;
|
this.collidable = collidable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void setCollisionObject(CollisionObject body, Collidable collidable){
|
||||||
|
// this.body = body;
|
||||||
|
// this.collidable = collidable;
|
||||||
|
// }
|
||||||
|
|
||||||
public GravityTreeState getState(){
|
public GravityTreeState getState(){
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -115,14 +117,19 @@ public class GravityTree {
|
|||||||
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||||
Vector3d newGravityPos = new Vector3d(position.x,position.y - gravityDif,position.z);
|
Vector3d newGravityPos = new Vector3d(position.x,position.y - gravityDif,position.z);
|
||||||
float hitFraction = Globals.collisionEngine.sweepTest(body, new Vector3f((float)position.x,(float)position.y,(float)position.z), new Vector3f((float)newGravityPos.x,(float)newGravityPos.y,(float)newGravityPos.z));
|
float hitFraction = Globals.collisionEngine.sweepTest(body, new Vector3f((float)position.x,(float)position.y,(float)position.z), new Vector3f((float)newGravityPos.x,(float)newGravityPos.y,(float)newGravityPos.z));
|
||||||
if(hitFraction >= 0){
|
// if(hitFraction >= 0){
|
||||||
position.set(new Vector3d(position.x,position.y - gravityDif * hitFraction,position.z));
|
// collidable.addImpulse(new Impulse(new Vector3d(0,-1,0),gravityDif * hitFraction,"gravity"));
|
||||||
} else {
|
// position.set(new Vector3d(position.x,position.y - gravityDif * hitFraction,position.z));
|
||||||
position.set(new Vector3d(position.x,position.y - gravityDif,position.z));
|
// } else {
|
||||||
|
// position.set(new Vector3d(position.x,position.y - gravityDif,position.z));
|
||||||
|
// }
|
||||||
|
if(hitFraction < 0){
|
||||||
|
hitFraction = 1;
|
||||||
}
|
}
|
||||||
|
collidable.addImpulse(new Impulse(new Vector3d(0,-1,0),gravityDif * hitFraction,"gravity"));
|
||||||
// System.out.println(hitFraction);
|
// System.out.println(hitFraction);
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
// bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
// body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NOT_ACTIVE:
|
case NOT_ACTIVE:
|
||||||
@ -158,7 +165,7 @@ public class GravityTree {
|
|||||||
break;
|
break;
|
||||||
} else if(
|
} else if(
|
||||||
impulse.getType().equals(Collidable.TYPE_STRUCTURE) &&
|
impulse.getType().equals(Collidable.TYPE_STRUCTURE) &&
|
||||||
new Vector3f(impulse.getDirection()).normalize().y > 0.7
|
new Vector3d(impulse.getDirection()).normalize().y > 0.7
|
||||||
){
|
){
|
||||||
rVal = true;
|
rVal = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
package electrosphere.entity.state;
|
package electrosphere.entity.state;
|
||||||
|
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
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.AttackTree.AttackTreeState;
|
import electrosphere.entity.state.AttackTree.AttackTreeState;
|
||||||
import electrosphere.entity.state.movement.MovementTree.MovementTreeState;
|
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.net.parser.net.message.EntityMessage;
|
import electrosphere.net.parser.net.message.EntityMessage;
|
||||||
import electrosphere.renderer.Actor;
|
import electrosphere.renderer.Actor;
|
||||||
@ -57,7 +57,7 @@ public class IdleTree {
|
|||||||
Actor entityActor = EntityUtils.getActor(parent);
|
Actor entityActor = EntityUtils.getActor(parent);
|
||||||
|
|
||||||
boolean hasMovementTree = parent.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
boolean hasMovementTree = parent.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
||||||
MovementTree movementTree = null;
|
GroundMovementTree movementTree = null;
|
||||||
if(hasMovementTree){
|
if(hasMovementTree){
|
||||||
movementTree = CreatureUtils.getEntityMovementTree(parent);
|
movementTree = CreatureUtils.getEntityMovementTree(parent);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,72 @@
|
|||||||
|
package electrosphere.entity.state.collidable;
|
||||||
|
|
||||||
|
import electrosphere.collision.dispatch.CollisionObject;
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.game.collision.PhysicsUtils;
|
||||||
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author amaterasu
|
||||||
|
*/
|
||||||
|
public class CollidableTree {
|
||||||
|
|
||||||
|
Entity parent;
|
||||||
|
CollisionObject body;
|
||||||
|
Collidable collidable;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public CollidableTree(Entity e, Collidable collidable, CollisionObject body){
|
||||||
|
parent = e;
|
||||||
|
this.collidable = collidable;
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void simulate(){
|
||||||
|
Vector3d position = EntityUtils.getPosition(parent);
|
||||||
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
|
Vector3d offsetVector = new Vector3d();
|
||||||
|
Vector3d newPosition = new Vector3d(position);
|
||||||
|
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||||
|
//handle impulses
|
||||||
|
for(Impulse impulse : collidable.getImpulses()){
|
||||||
|
// collidable.getImpulses().remove(impulse);
|
||||||
|
Vector3d impulseForce = new Vector3d(impulse.getDirection()).mul(impulse.getForce());
|
||||||
|
// if(impulse.type.matches("movement")){
|
||||||
|
// System.out.println("Impulse force: " + impulseForce);
|
||||||
|
// }
|
||||||
|
offsetVector.add(impulseForce);
|
||||||
|
}
|
||||||
|
//make sure we're in a valid (World bounds) position
|
||||||
|
newPosition.add(offsetVector);
|
||||||
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
|
}
|
||||||
|
position.set(newPosition);
|
||||||
|
|
||||||
|
//update collision engine of this thing's position
|
||||||
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
||||||
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
|
// bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
||||||
|
// body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setCollisionObject(CollisionObject body, Collidable collidable){
|
||||||
|
this.body = body;
|
||||||
|
this.collidable = collidable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.entity.state.movement;
|
package electrosphere.entity.state.collidable;
|
||||||
|
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,21 +9,21 @@ import org.joml.Vector3f;
|
|||||||
*/
|
*/
|
||||||
public class Impulse {
|
public class Impulse {
|
||||||
|
|
||||||
Vector3f direction;
|
Vector3d direction;
|
||||||
float force;
|
double force;
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
public Impulse(Vector3f dir, float force, String type){
|
public Impulse(Vector3d dir, double force, String type){
|
||||||
this.force = force;
|
this.force = force;
|
||||||
this.direction = dir;
|
this.direction = dir;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3f getDirection() {
|
public Vector3d getDirection() {
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getForce() {
|
public double getForce() {
|
||||||
return force;
|
return force;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.entity.state.movement;
|
package electrosphere.entity.state.movement;
|
||||||
|
|
||||||
|
import electrosphere.entity.state.collidable.Impulse;
|
||||||
import electrosphere.collision.dispatch.CollisionObject;
|
import electrosphere.collision.dispatch.CollisionObject;
|
||||||
import electrosphere.dynamics.RigidBody;
|
import electrosphere.dynamics.RigidBody;
|
||||||
import electrosphere.entity.CameraEntityUtils;
|
import electrosphere.entity.CameraEntityUtils;
|
||||||
@ -8,6 +9,7 @@ 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.GravityTree;
|
||||||
|
import electrosphere.entity.state.GravityTree;
|
||||||
import electrosphere.game.collision.CollisionEngine;
|
import electrosphere.game.collision.CollisionEngine;
|
||||||
import electrosphere.game.collision.PhysicsUtils;
|
import electrosphere.game.collision.PhysicsUtils;
|
||||||
import electrosphere.game.collision.collidable.Collidable;
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
@ -28,7 +30,7 @@ import org.joml.Vector3f;
|
|||||||
/*
|
/*
|
||||||
Behavior tree for movement in an entity
|
Behavior tree for movement in an entity
|
||||||
*/
|
*/
|
||||||
public class MovementTree {
|
public class GroundMovementTree {
|
||||||
|
|
||||||
public static enum MovementTreeState {
|
public static enum MovementTreeState {
|
||||||
STARTUP,
|
STARTUP,
|
||||||
@ -43,7 +45,6 @@ public class MovementTree {
|
|||||||
|
|
||||||
Entity parent;
|
Entity parent;
|
||||||
|
|
||||||
CollisionObject body;
|
|
||||||
Collidable collidable;
|
Collidable collidable;
|
||||||
|
|
||||||
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
|
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
|
||||||
@ -51,20 +52,16 @@ public class MovementTree {
|
|||||||
long lastUpdateTime = 0;
|
long lastUpdateTime = 0;
|
||||||
|
|
||||||
|
|
||||||
public MovementTree(Entity e){
|
public GroundMovementTree(Entity e, Collidable collidable){
|
||||||
state = MovementTreeState.IDLE;
|
state = MovementTreeState.IDLE;
|
||||||
parent = e;
|
parent = e;
|
||||||
|
this.collidable = collidable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementTreeState getState(){
|
public MovementTreeState getState(){
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCollisionObject(CollisionObject body, Collidable collidable){
|
|
||||||
this.body = body;
|
|
||||||
this.collidable = collidable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start(){
|
public void start(){
|
||||||
//TODO: check if can start moving
|
//TODO: check if can start moving
|
||||||
state = MovementTreeState.STARTUP;
|
state = MovementTreeState.STARTUP;
|
||||||
@ -90,7 +87,6 @@ public class MovementTree {
|
|||||||
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
|
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
|
||||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
Vector3d newPosition;
|
Vector3d newPosition;
|
||||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
|
||||||
|
|
||||||
//parse attached network messages
|
//parse attached network messages
|
||||||
for(EntityMessage message : networkMessageQueue){
|
for(EntityMessage message : networkMessageQueue){
|
||||||
@ -148,19 +144,7 @@ public class MovementTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//handle impulses
|
|
||||||
if(collidable != null){
|
|
||||||
for(Impulse impulse : collidable.getImpulses()){
|
|
||||||
// collidable.getImpulses().remove(impulse);
|
|
||||||
Vector3f impulseForce = new Vector3f(impulse.direction).mul(impulse.force).mul(Main.deltaTime);
|
|
||||||
// System.out.println("Impulse force: " + impulseForce);
|
|
||||||
position.add(impulseForce);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(body != null){
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
//state machine
|
//state machine
|
||||||
switch(state){
|
switch(state){
|
||||||
@ -181,19 +165,17 @@ public class MovementTree {
|
|||||||
}
|
}
|
||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).set(movementQuaternion);
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//move the entity
|
// //move the entity
|
||||||
newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
// newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
||||||
//check/update if collision
|
// //check/update if collision
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
// }
|
||||||
// //actually update
|
// //actually update
|
||||||
position.set(newPosition);
|
collidable.addImpulse(new Impulse(new Vector3d(movementVector), velocity, "movement"));
|
||||||
|
// position.set(newPosition);
|
||||||
rotation.set(movementQuaternion);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
|
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
@ -211,37 +193,37 @@ public class MovementTree {
|
|||||||
// 0
|
// 0
|
||||||
// )
|
// )
|
||||||
// );
|
// );
|
||||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
// Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
0
|
// 0
|
||||||
),
|
// ),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||||
);
|
// );
|
||||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
Globals.clientConnection.queueOutgoingMessage(
|
// Globals.clientConnection.queueOutgoingMessage(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
0
|
// 0
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MOVE:
|
case MOVE:
|
||||||
@ -257,16 +239,14 @@ public class MovementTree {
|
|||||||
EntityUtils.getRotation(parent).set(movementQuaternion);
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//check if can move forward (collision engine)
|
//check if can move forward (collision engine)
|
||||||
//if can, move forward by entity movement stats
|
//if can, move forward by entity movement stats
|
||||||
newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
// newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
// }
|
||||||
position.set(newPosition);
|
collidable.addImpulse(new Impulse(new Vector3d(movementVector), velocity, "movement"));
|
||||||
|
// position.set(newPosition);
|
||||||
rotation.set(movementQuaternion);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
|
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
@ -284,37 +264,37 @@ public class MovementTree {
|
|||||||
// 1
|
// 1
|
||||||
// )
|
// )
|
||||||
// );
|
// );
|
||||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
// Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
1
|
// 1
|
||||||
),
|
// ),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||||
);
|
// );
|
||||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
Globals.clientConnection.queueOutgoingMessage(
|
// Globals.clientConnection.queueOutgoingMessage(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
1
|
// 1
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SLOWDOWN:
|
case SLOWDOWN:
|
||||||
@ -335,16 +315,14 @@ public class MovementTree {
|
|||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
//move the entity
|
//move the entity
|
||||||
newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
// newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
// }
|
||||||
position.set(newPosition);
|
collidable.addImpulse(new Impulse(new Vector3d(movementVector), velocity, "movement"));
|
||||||
|
// position.set(newPosition);
|
||||||
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
|
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
@ -362,37 +340,37 @@ public class MovementTree {
|
|||||||
// 2
|
// 2
|
||||||
// )
|
// )
|
||||||
// );
|
// );
|
||||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
// Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
2
|
// 2
|
||||||
),
|
// ),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.x),
|
||||||
Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
// Globals.serverWorldData.convertRealToChunkSpace(newPosition.z)
|
||||||
);
|
// );
|
||||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
Globals.clientConnection.queueOutgoingMessage(
|
// Globals.clientConnection.queueOutgoingMessage(
|
||||||
EntityMessage.constructmoveUpdateMessage(
|
// EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
(float)newPosition.x,
|
// (float)newPosition.x,
|
||||||
(float)newPosition.y,
|
// (float)newPosition.y,
|
||||||
(float)newPosition.z,
|
// (float)newPosition.z,
|
||||||
movementVector.x,
|
// movementVector.x,
|
||||||
movementVector.y,
|
// movementVector.y,
|
||||||
movementVector.z,
|
// movementVector.z,
|
||||||
velocity,
|
// velocity,
|
||||||
2
|
// 2
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IDLE:
|
case IDLE:
|
||||||
@ -131,4 +131,8 @@ public class CollisionObjUtils {
|
|||||||
PhysicsUtils.setRigidBodyTransform(position, rotation, body);
|
PhysicsUtils.setRigidBodyTransform(position, rotation, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Collidable getCollidable(Entity e){
|
||||||
|
return (Collidable)e.getData(EntityDataStrings.PHYSICS_COLLIDABLE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import electrosphere.dynamics.RigidBody;
|
|||||||
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.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
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.config.creature.type.CreatureType;
|
import electrosphere.game.config.creature.type.CreatureType;
|
||||||
@ -13,11 +13,13 @@ import electrosphere.game.config.creature.type.MovementSystem;
|
|||||||
import electrosphere.entity.state.AttackTree;
|
import electrosphere.entity.state.AttackTree;
|
||||||
import electrosphere.entity.state.GravityTree;
|
import electrosphere.entity.state.GravityTree;
|
||||||
import electrosphere.entity.state.IdleTree;
|
import electrosphere.entity.state.IdleTree;
|
||||||
|
import electrosphere.entity.state.collidable.CollidableTree;
|
||||||
|
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||||
import electrosphere.entity.types.life.LifeState;
|
import electrosphere.entity.types.life.LifeState;
|
||||||
import electrosphere.game.collision.PhysicsUtils;
|
import electrosphere.game.collision.PhysicsUtils;
|
||||||
import electrosphere.game.collision.collidable.Collidable;
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
import electrosphere.game.config.creature.type.AttackMove;
|
import electrosphere.game.config.creature.type.AttackMove;
|
||||||
import electrosphere.game.config.creature.type.PhysicsObject;
|
import electrosphere.game.config.creature.type.CollidableTemplate;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
@ -68,20 +70,8 @@ public class CreatureUtils {
|
|||||||
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(MovementSystem movementSystem : rawType.getMovementSystems()){
|
if(rawType.getCollidable() != null){
|
||||||
switch(movementSystem.getType()){
|
CollidableTemplate physicsTemplate = rawType.getCollidable();
|
||||||
case "GROUND":
|
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));
|
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
|
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, movementSystem.getMaxVelocity());
|
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, movementSystem.getAcceleration());
|
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
|
||||||
Globals.entityManager.registerMoveableEntity(rVal);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(rawType.getPhysicsObject() != null){
|
|
||||||
PhysicsObject physicsTemplate = rawType.getPhysicsObject();
|
|
||||||
switch(physicsTemplate.getType()){
|
switch(physicsTemplate.getType()){
|
||||||
case "CYLINDER":
|
case "CYLINDER":
|
||||||
CollisionObject rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
|
CollisionObject rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
|
||||||
@ -90,12 +80,26 @@ public class CreatureUtils {
|
|||||||
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
|
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_MODEL_TEMPLATE, physicsTemplate);
|
||||||
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE,collidable);
|
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE,collidable);
|
||||||
|
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody));
|
||||||
Globals.collisionEngine.registerPhysicsEntity(rVal);
|
Globals.collisionEngine.registerPhysicsEntity(rVal);
|
||||||
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
|
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
|
||||||
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
|
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
|
||||||
if(rVal.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT)){
|
Globals.entityManager.registerCollidableEntity(rVal);
|
||||||
CreatureUtils.getEntityMovementTree(rVal).setCollisionObject(rigidBody, collidable);
|
// if(rVal.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT)){
|
||||||
}
|
// CreatureUtils.getEntityMovementTree(rVal).setCollisionObject(rigidBody, collidable);
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(MovementSystem movementSystem : rawType.getMovementSystems()){
|
||||||
|
switch(movementSystem.getType()){
|
||||||
|
case "GROUND":
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new GroundMovementTree(rVal,CollisionObjUtils.getCollidable(rVal)));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, movementSystem.getMaxVelocity());
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, movementSystem.getAcceleration());
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
||||||
|
Globals.entityManager.registerMoveableEntity(rVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,10 +115,10 @@ public class CreatureUtils {
|
|||||||
Globals.entityManager.registerAttackerEntity(rVal);
|
Globals.entityManager.registerAttackerEntity(rVal);
|
||||||
break;
|
break;
|
||||||
case "GRAVITY":
|
case "GRAVITY":
|
||||||
GravityTree gravityTree = new GravityTree(rVal);
|
|
||||||
Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE);
|
Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE);
|
||||||
CollisionObject collisionObject = (CollisionObject)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
CollisionObject collisionObject = (CollisionObject)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||||
gravityTree.setCollisionObject(collisionObject, collidable);
|
GravityTree gravityTree = new GravityTree(rVal,collidable,collisionObject);
|
||||||
|
// gravityTree.setCollisionObject(collisionObject, collidable);
|
||||||
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
|
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
|
||||||
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
|
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
|
||||||
Globals.entityManager.registerGravityEntity(rVal);
|
Globals.entityManager.registerGravityEntity(rVal);
|
||||||
@ -187,8 +191,8 @@ public class CreatureUtils {
|
|||||||
e.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, scalar);
|
e.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, scalar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MovementTree getEntityMovementTree(Entity e){
|
public static GroundMovementTree getEntityMovementTree(Entity e){
|
||||||
return (MovementTree)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
return (GroundMovementTree)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void attachEntityMessageToMovementTree(Entity e, EntityMessage em){
|
public static void attachEntityMessageToMovementTree(Entity e, EntityMessage em){
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package electrosphere.entity.types.item;
|
|||||||
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.movement.MovementTree;
|
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;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import electrosphere.util.ObjectArrayList;
|
|||||||
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.movement.Impulse;
|
import electrosphere.entity.state.collidable.Impulse;
|
||||||
import electrosphere.entity.types.hitbox.HitboxData;
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
import electrosphere.game.collision.collidable.Collidable;
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
import static electrosphere.main.Main.deltaTime;
|
import static electrosphere.main.Main.deltaTime;
|
||||||
@ -84,7 +84,7 @@ public class CollisionEngine {
|
|||||||
Collidable physicsObject1 = (Collidable)object1.getUserPointer();
|
Collidable physicsObject1 = (Collidable)object1.getUserPointer();
|
||||||
Collidable physicsObject2 = (Collidable)object2.getUserPointer();
|
Collidable physicsObject2 = (Collidable)object2.getUserPointer();
|
||||||
boolean hit = false;
|
boolean hit = false;
|
||||||
Vector3f normal = null;
|
Vector3d normal = null;
|
||||||
float magnitude = 0.0f;
|
float magnitude = 0.0f;
|
||||||
for (int j = 0; j < manifold.getNumContacts(); j++) {
|
for (int j = 0; j < manifold.getNumContacts(); j++) {
|
||||||
ManifoldPoint contactPoint = manifold.getContactPoint(j);
|
ManifoldPoint contactPoint = manifold.getContactPoint(j);
|
||||||
@ -94,13 +94,13 @@ public class CollisionEngine {
|
|||||||
magnitude = magnitude;// * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
magnitude = magnitude;// * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||||
hit = true;
|
hit = true;
|
||||||
// System.out.println(contactPoint.positionWorldOnA + " " + contactPoint.positionWorldOnB);
|
// System.out.println(contactPoint.positionWorldOnA + " " + contactPoint.positionWorldOnB);
|
||||||
normal = new Vector3f(contactPoint.normalWorldOnB.x,contactPoint.normalWorldOnB.y,contactPoint.normalWorldOnB.z);
|
normal = new Vector3d(contactPoint.normalWorldOnB.x,contactPoint.normalWorldOnB.y,contactPoint.normalWorldOnB.z);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hit) {
|
if (hit) {
|
||||||
resolveCollision(physicsObject1,physicsObject2, normal, magnitude);
|
resolveCollision(physicsObject1,physicsObject2, normal, magnitude);
|
||||||
resolveCollision(physicsObject2,physicsObject1, new Vector3f(normal).mul(-1.0f), magnitude);
|
resolveCollision(physicsObject2,physicsObject1, new Vector3d(normal).mul(-1.0f), magnitude);
|
||||||
// System.out.println("HIT + " + normal);
|
// System.out.println("HIT + " + normal);
|
||||||
// Collision happened between physicsObject1 and physicsObject2. Collision normal is in variable 'normal'.
|
// Collision happened between physicsObject1 and physicsObject2. Collision normal is in variable 'normal'.
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public class CollisionEngine {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resolveCollision(Collidable impactor, Collidable receiver, Vector3f normal, float magnitude){
|
public static void resolveCollision(Collidable impactor, Collidable receiver, Vector3d normal, float magnitude){
|
||||||
switch(receiver.getType()){
|
switch(receiver.getType()){
|
||||||
case Collidable.TYPE_CREATURE:
|
case Collidable.TYPE_CREATURE:
|
||||||
switch(impactor.getType()){
|
switch(impactor.getType()){
|
||||||
@ -123,7 +123,7 @@ public class CollisionEngine {
|
|||||||
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
||||||
// System.out.println();
|
// System.out.println();
|
||||||
// System.out.println("Terrain-creature collision: " + normal + " mag:" + magnitude);
|
// System.out.println("Terrain-creature collision: " + normal + " mag:" + magnitude);
|
||||||
receiver.addImpulse(new Impulse(new Vector3f(0,normal.y,0), -magnitude*2, Collidable.TYPE_TERRAIN));
|
receiver.addImpulse(new Impulse(new Vector3d(0,normal.y,0), -magnitude*2, Collidable.TYPE_TERRAIN));
|
||||||
break;
|
break;
|
||||||
case Collidable.TYPE_CREATURE:
|
case Collidable.TYPE_CREATURE:
|
||||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package electrosphere.game.collision.collidable;
|
|||||||
import electrosphere.collision.shapes.CollisionShape;
|
import electrosphere.collision.shapes.CollisionShape;
|
||||||
import electrosphere.dynamics.RigidBody;
|
import electrosphere.dynamics.RigidBody;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.state.movement.Impulse;
|
import electrosphere.entity.state.collidable.Impulse;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|||||||
@ -4,7 +4,7 @@ package electrosphere.game.config.creature.type;
|
|||||||
*
|
*
|
||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class PhysicsObject {
|
public class CollidableTemplate {
|
||||||
|
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ public class CreatureType {
|
|||||||
List<HitboxData> hitboxes;
|
List<HitboxData> hitboxes;
|
||||||
List<String> tokens;
|
List<String> tokens;
|
||||||
List<MovementSystem> movementSystems;
|
List<MovementSystem> movementSystems;
|
||||||
PhysicsObject physicsObject;
|
CollidableTemplate collidable;
|
||||||
List<AttackMove> attackMoves;
|
List<AttackMove> attackMoves;
|
||||||
HealthSystem healthSystem;
|
HealthSystem healthSystem;
|
||||||
String modelPath;
|
String modelPath;
|
||||||
@ -46,8 +46,8 @@ public class CreatureType {
|
|||||||
return healthSystem;
|
return healthSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PhysicsObject getPhysicsObject() {
|
public CollidableTemplate getCollidable() {
|
||||||
return physicsObject;
|
return collidable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import electrosphere.entity.Entity;
|
|||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.AttackTree;
|
import electrosphere.entity.state.AttackTree;
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.game.server.ai.AI;
|
import electrosphere.game.server.ai.AI;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
@ -70,8 +70,8 @@ public class MindlessAttacker extends AI{
|
|||||||
Vector3d characterPosition = EntityUtils.getPosition(character);
|
Vector3d characterPosition = EntityUtils.getPosition(character);
|
||||||
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
|
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
|
||||||
CreatureUtils.setMovementVector(character, new Vector3f((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
|
CreatureUtils.setMovementVector(character, new Vector3f((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
|
||||||
MovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
|
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
|
||||||
if(characterMoveTree.getState()==MovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==MovementTree.MovementTreeState.SLOWDOWN){
|
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
|
||||||
characterMoveTree.start();
|
characterMoveTree.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,9 @@ import electrosphere.entity.EntityUtils;
|
|||||||
import electrosphere.entity.state.AttackTree;
|
import electrosphere.entity.state.AttackTree;
|
||||||
import electrosphere.entity.state.GravityTree;
|
import electrosphere.entity.state.GravityTree;
|
||||||
import electrosphere.entity.state.IdleTree;
|
import electrosphere.entity.state.IdleTree;
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.state.ParticleTree;
|
import electrosphere.entity.state.ParticleTree;
|
||||||
|
import electrosphere.entity.state.collidable.CollidableTree;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||||
import electrosphere.entity.types.item.ItemUtils;
|
import electrosphere.entity.types.item.ItemUtils;
|
||||||
@ -56,7 +57,7 @@ public class MicroSimulation {
|
|||||||
}
|
}
|
||||||
//simulate creature behavior trees
|
//simulate creature behavior trees
|
||||||
for(Entity currentMoveable : Globals.entityManager.getMoveable()){
|
for(Entity currentMoveable : Globals.entityManager.getMoveable()){
|
||||||
MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
|
GroundMovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
|
||||||
behaviorTree.simulate();
|
behaviorTree.simulate();
|
||||||
}
|
}
|
||||||
//simulate creature gravity trees
|
//simulate creature gravity trees
|
||||||
@ -97,6 +98,11 @@ public class MicroSimulation {
|
|||||||
HitboxUtils.collideEntities(currentHitbox);
|
HitboxUtils.collideEntities(currentHitbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//tally collidables and offset position accordingly
|
||||||
|
for(Entity currentCollidable : Globals.entityManager.getCollidables()){
|
||||||
|
CollidableTree tree = EntityUtils.getCollidableTree(currentCollidable);
|
||||||
|
tree.simulate();
|
||||||
|
}
|
||||||
//clear collidable impulse lists
|
//clear collidable impulse lists
|
||||||
Globals.collisionEngine.clearCollidableImpulseLists();
|
Globals.collisionEngine.clearCollidableImpulseLists();
|
||||||
//delete all client side entities that aren't in visible chunks
|
//delete all client side entities that aren't in visible chunks
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import electrosphere.renderer.Model;
|
|||||||
import electrosphere.renderer.RenderUtils;
|
import electrosphere.renderer.RenderUtils;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.movement.MovementTree;
|
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||||
import electrosphere.entity.types.item.ItemUtils;
|
import electrosphere.entity.types.item.ItemUtils;
|
||||||
import electrosphere.entity.types.attach.AttachUtils;
|
import electrosphere.entity.types.attach.AttachUtils;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import electrosphere.entity.EntityDataStrings;
|
|||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
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.config.creature.type.PhysicsObject;
|
import electrosphere.game.config.creature.type.CollidableTemplate;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import static electrosphere.main.Main.deltaTime;
|
import static electrosphere.main.Main.deltaTime;
|
||||||
@ -474,7 +474,7 @@ public class RenderingEngine {
|
|||||||
Model physicsGraphicsModel;
|
Model physicsGraphicsModel;
|
||||||
for(Entity physicsEntity : Globals.collisionEngine.getDynamicPhysicsEntities()){
|
for(Entity physicsEntity : Globals.collisionEngine.getDynamicPhysicsEntities()){
|
||||||
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
|
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
|
||||||
PhysicsObject template = (PhysicsObject)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
|
CollidableTemplate template = (CollidableTemplate)physicsEntity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE);
|
||||||
switch(template.getType()){
|
switch(template.getType()){
|
||||||
case "CYLINDER":
|
case "CYLINDER":
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user