Fixing gravity / adding gravity tree
This commit is contained in:
parent
dd30e73660
commit
85f60b038b
@ -82,7 +82,8 @@
|
||||
"tokens" : [
|
||||
"BLENDER_TRANSFORM",
|
||||
"SENTIENT",
|
||||
"ATTACKER"
|
||||
"ATTACKER",
|
||||
"GRAVITY"
|
||||
],
|
||||
"movementSystems" : [
|
||||
{
|
||||
@ -97,7 +98,7 @@
|
||||
"dimension2" : 0.45,
|
||||
"dimension3" : 0.2,
|
||||
"offsetX" : 0,
|
||||
"offsetY" : -0.45,
|
||||
"offsetY" : 0.45,
|
||||
"offsetZ" : 0
|
||||
},
|
||||
"attackMoves" : [
|
||||
@ -199,7 +200,8 @@
|
||||
"tokens" : [
|
||||
"BLENDER_TRANSFORM",
|
||||
"SENTIENT",
|
||||
"ATTACKER"
|
||||
"ATTACKER",
|
||||
"GRAVITY"
|
||||
],
|
||||
"movementSystems" : [
|
||||
{
|
||||
|
||||
@ -510,21 +510,21 @@ public class LoadingThread extends Thread {
|
||||
// MindlessAttacker.attachToCreature(goblin);
|
||||
//
|
||||
//
|
||||
Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
|
||||
EntityUtils.getScale(testHomie).set(0.005f);
|
||||
CreatureUtils.positionCharacter(testHomie, new Vector3f(10,1,10));
|
||||
|
||||
Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
|
||||
|
||||
|
||||
// CollisionObjUtils.spawnCollisionPlane(new Vector3f(1,1,1), new Vector3f(11,0.5f,5), new Quaternionf().rotateLocalX(0.75f));
|
||||
// Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
|
||||
// EntityUtils.getScale(testHomie).set(0.005f);
|
||||
// CreatureUtils.positionCharacter(testHomie, new Vector3f(10,1,10));
|
||||
//
|
||||
// CollisionObjUtils.spawnCollisionCube(new Vector3f(1,1,1), new Vector3f(10,1,10), new Quaternionf());
|
||||
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||
// AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
|
||||
|
||||
CreatureUtils.positionCharacter(Globals.playerCharacter, new Vector3f(5,2,10));
|
||||
|
||||
StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,15), new Quaternionf().rotateLocalY((float)Math.PI));
|
||||
CollisionObjUtils.spawnCollisionPlane(new Vector3f(1,1,1), new Vector3f(8,2,10), new Quaternionf()); // .rotateLocalX(0.75f)
|
||||
|
||||
CollisionObjUtils.spawnCollisionCube(new Vector3f(1,1,1), new Vector3f(10,1,10), new Quaternionf());
|
||||
|
||||
CreatureUtils.positionCharacter(Globals.playerCharacter, new Vector3f(10,3,10));
|
||||
|
||||
// StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,15), new Quaternionf().rotateLocalY((float)Math.PI));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -72,10 +72,17 @@ public class EntityDataStrings {
|
||||
/*
|
||||
Physics Entity
|
||||
*/
|
||||
public static final String PHYSICS_RIGID_BODY = "physicsRigidBody";
|
||||
public static final String PHYSICS_RIGID_BODY_OFFSET = "physicsRigidBodyOffset";
|
||||
public static final String PHYSICS_COLLISION_BODY = "physicsRigidBody";
|
||||
public static final String PHYSICS_COLLISION_BODY_OFFSET = "physicsRigidBodyOffset";
|
||||
public static final String PHYSICS_COLLIDABLE = "physicsCollidable";
|
||||
public static final String PHYSICS_MODEL_TEMPLATE = "physicsModelTemplate";
|
||||
|
||||
/*
|
||||
Gravity Entity
|
||||
*/
|
||||
public static final String GRAVITY_ENTITY = "gravityEntity";
|
||||
public static final String GRAVITY_TREE = "gravityTree";
|
||||
|
||||
/*
|
||||
Collision Entity
|
||||
*/
|
||||
|
||||
@ -24,6 +24,7 @@ public class EntityManager {
|
||||
static CopyOnWriteArrayList<Entity> creatureList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> particleList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> gravityList = new CopyOnWriteArrayList();
|
||||
|
||||
public EntityManager(){
|
||||
|
||||
@ -114,6 +115,14 @@ public class EntityManager {
|
||||
return particleList;
|
||||
}
|
||||
|
||||
public void registerGravityEntity(Entity e){
|
||||
gravityList.add(e);
|
||||
}
|
||||
|
||||
public CopyOnWriteArrayList<Entity> getGravityEntities(){
|
||||
return gravityList;
|
||||
}
|
||||
|
||||
public void deregisterEntity(Entity e){
|
||||
if(lightList.contains(e)){
|
||||
lightList.remove(e);
|
||||
@ -146,6 +155,9 @@ public class EntityManager {
|
||||
if(particleList.contains(e)){
|
||||
particleList.remove(e);
|
||||
}
|
||||
if(gravityList.contains(e)){
|
||||
gravityList.remove(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void overrideEntityId(Entity e, int id){
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
package electrosphere.entity.state;
|
||||
|
||||
import com.bulletphysics.collision.dispatch.CollisionObject;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.movement.Impulse;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.renderer.Actor;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
@ -14,15 +19,18 @@ import org.joml.Vector3f;
|
||||
*/
|
||||
public class GravityTree {
|
||||
|
||||
public static enum IdleTreeState {
|
||||
public static enum GravityTreeState {
|
||||
ACTIVE,
|
||||
NOT_ACTIVE,
|
||||
}
|
||||
|
||||
IdleTreeState state;
|
||||
GravityTreeState state;
|
||||
|
||||
Entity parent;
|
||||
|
||||
CollisionObject body;
|
||||
Collidable collidable;
|
||||
|
||||
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
|
||||
|
||||
int frameCurrent;
|
||||
@ -30,26 +38,31 @@ public class GravityTree {
|
||||
int maxFrame = 60;
|
||||
|
||||
public GravityTree(Entity e){
|
||||
state = IdleTreeState.NOT_ACTIVE;
|
||||
state = GravityTreeState.ACTIVE;
|
||||
parent = e;
|
||||
}
|
||||
|
||||
public IdleTreeState getState(){
|
||||
public void setCollisionObject(CollisionObject body, Collidable collidable){
|
||||
this.body = body;
|
||||
this.collidable = collidable;
|
||||
}
|
||||
|
||||
public GravityTreeState getState(){
|
||||
return state;
|
||||
}
|
||||
|
||||
public void start(){
|
||||
//TODO: check if can start moving
|
||||
state = IdleTreeState.ACTIVE;
|
||||
state = GravityTreeState.ACTIVE;
|
||||
frameCurrent = 0;
|
||||
}
|
||||
|
||||
public void interrupt(){
|
||||
state = IdleTreeState.NOT_ACTIVE;
|
||||
state = GravityTreeState.NOT_ACTIVE;
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
state = IdleTreeState.NOT_ACTIVE;
|
||||
state = GravityTreeState.NOT_ACTIVE;
|
||||
}
|
||||
|
||||
public void simulate(){
|
||||
@ -59,7 +72,9 @@ public class GravityTree {
|
||||
Actor entityActor = EntityUtils.getActor(parent);
|
||||
Vector3f position = EntityUtils.getPosition(parent);
|
||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||
Vector3f newPosition;
|
||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||
|
||||
//parse attached network messages
|
||||
// for(EntityMessage message : networkMessageQueue){
|
||||
@ -84,39 +99,55 @@ public class GravityTree {
|
||||
boolean isIdle;
|
||||
|
||||
//state machine
|
||||
// switch(state){
|
||||
// case ACTIVE:
|
||||
// isIdle = true;
|
||||
// if(hasMovementTree){
|
||||
// if(movementTree.getState() != MovementTreeState.IDLE){
|
||||
// isIdle = false;
|
||||
// }
|
||||
// }
|
||||
// if(hasAttackTree){
|
||||
// if(attackTree.getState() != AttackTreeState.IDLE){
|
||||
// isIdle = false;
|
||||
// }
|
||||
// }
|
||||
// if(!isIdle){
|
||||
// state = IdleTreeState.NOT_IDLE;
|
||||
// }
|
||||
// break;
|
||||
// case NOT_ACTIVE:
|
||||
// isIdle = true;
|
||||
// if(hasAttackTree){
|
||||
// if(attackTree.getState() != AttackTreeState.IDLE){
|
||||
// isIdle = false;
|
||||
// }
|
||||
// }
|
||||
// if(isIdle){
|
||||
// state = IdleTreeState.IDLE;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
switch(state){
|
||||
case ACTIVE:
|
||||
if(hadGroundCollision()){
|
||||
state = GravityTreeState.NOT_ACTIVE;
|
||||
} else {
|
||||
position.set(new Vector3f(position.x,position.y - 0.08f,position.z));
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
}
|
||||
break;
|
||||
case NOT_ACTIVE:
|
||||
if(hadEntityCollision()){
|
||||
start();
|
||||
}
|
||||
//nothing here atm
|
||||
//eventually want to check if need to re-activate somehow
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void addNetworkMessage(EntityMessage networkMessage) {
|
||||
networkMessageQueue.add(networkMessage);
|
||||
}
|
||||
|
||||
public boolean hadGroundCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_TERRAIN)){
|
||||
rVal = true;
|
||||
break;
|
||||
} else if(
|
||||
impulse.getType().equals(Collidable.TYPE_STRUCTURE) &&
|
||||
new Vector3f(impulse.getDirection()).normalize().y > 0.7
|
||||
){
|
||||
rVal = true;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public boolean hadEntityCollision(){
|
||||
boolean rVal = false;
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
if(impulse.getType().equals(Collidable.TYPE_CREATURE)){
|
||||
rVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,10 +10,12 @@ public class Impulse {
|
||||
|
||||
Vector3f direction;
|
||||
float force;
|
||||
String type;
|
||||
|
||||
public Impulse(Vector3f dir, float force){
|
||||
public Impulse(Vector3f dir, float force, String type){
|
||||
this.force = force;
|
||||
this.direction = dir;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Vector3f getDirection() {
|
||||
@ -23,6 +25,10 @@ public class Impulse {
|
||||
public float getForce() {
|
||||
return force;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,10 @@ import com.bulletphysics.collision.dispatch.CollisionObject;
|
||||
import com.bulletphysics.dynamics.RigidBody;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.GravityTree;
|
||||
import electrosphere.game.collision.CollisionEngine;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.main.Globals;
|
||||
@ -62,6 +65,7 @@ public class MovementTree {
|
||||
public void start(){
|
||||
//TODO: check if can start moving
|
||||
state = MovementTreeState.STARTUP;
|
||||
activateGravityTree();
|
||||
}
|
||||
|
||||
public void interrupt(){
|
||||
@ -113,14 +117,17 @@ public class MovementTree {
|
||||
case 0:
|
||||
state = MovementTreeState.STARTUP;
|
||||
// System.out.println("Set state STARTUP");
|
||||
activateGravityTree();
|
||||
break;
|
||||
case 1:
|
||||
state = MovementTreeState.MOVE;
|
||||
System.out.println("Set state MOVE");
|
||||
activateGravityTree();
|
||||
break;
|
||||
case 2:
|
||||
state = MovementTreeState.SLOWDOWN;
|
||||
// System.out.println("Set state SLOWDOWN");
|
||||
activateGravityTree();
|
||||
break;
|
||||
case 3:
|
||||
state = MovementTreeState.IDLE;
|
||||
@ -137,12 +144,13 @@ public class MovementTree {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//handle impulses
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
collidable.getImpulses().remove(impulse);
|
||||
// collidable.getImpulses().remove(impulse);
|
||||
position.add(impulse.direction.mul(impulse.force));
|
||||
}
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
|
||||
//state machine
|
||||
switch(state){
|
||||
@ -177,37 +185,37 @@ public class MovementTree {
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
|
||||
|
||||
// if(Globals.RUN_SERVER){
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 0
|
||||
// )
|
||||
// );
|
||||
// } else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
// Globals.clientConnection.queueOutgoingMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 0
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
0
|
||||
)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
0
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case MOVE:
|
||||
//check if can restart animation
|
||||
@ -233,37 +241,37 @@ public class MovementTree {
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
|
||||
// if(Globals.RUN_SERVER){
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
// } else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
// Globals.clientConnection.queueOutgoingMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 1
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
1
|
||||
)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case SLOWDOWN:
|
||||
//run slowdown code
|
||||
@ -293,37 +301,37 @@ public class MovementTree {
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
|
||||
// if(Globals.RUN_SERVER){
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 2
|
||||
// )
|
||||
// );
|
||||
// } else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
// Globals.clientConnection.queueOutgoingMessage(
|
||||
// EntityMessage.constructmoveUpdateMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// newPosition.x,
|
||||
// newPosition.y,
|
||||
// newPosition.z,
|
||||
// movementVector.x,
|
||||
// movementVector.y,
|
||||
// movementVector.z,
|
||||
// velocity,
|
||||
// 2
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
2
|
||||
)
|
||||
);
|
||||
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||
Globals.clientConnection.queueOutgoingMessage(
|
||||
EntityMessage.constructmoveUpdateMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
newPosition.x,
|
||||
newPosition.y,
|
||||
newPosition.z,
|
||||
movementVector.x,
|
||||
movementVector.y,
|
||||
movementVector.z,
|
||||
velocity,
|
||||
2
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case IDLE:
|
||||
// body.clearForces();
|
||||
@ -336,9 +344,9 @@ public class MovementTree {
|
||||
// if(Globals.collisionEngine.gravityCheck(Globals.commonWorldData, parent)){
|
||||
// position.set(Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData,parent,new Vector3f(position.x,position.y - 9.8f,position.z)));
|
||||
// }
|
||||
position.set(new Vector3f(position.x,position.y - 0.1f,position.z));
|
||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
||||
body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
// position.set(new Vector3f(position.x,position.y - 0.08f,position.z));
|
||||
// bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
||||
// body.setWorldTransform(new com.bulletphysics.linearmath.Transform(bodyTransformMatrix));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -347,5 +355,11 @@ public class MovementTree {
|
||||
networkMessageQueue.add(networkMessage);
|
||||
}
|
||||
|
||||
public void activateGravityTree(){
|
||||
if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_ENTITY)){
|
||||
GravityTree tree = (GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE);
|
||||
tree.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -65,4 +65,7 @@ public class CollisionObjUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||
import electrosphere.game.server.creature.type.CreatureType;
|
||||
import electrosphere.game.server.creature.type.MovementSystem;
|
||||
import electrosphere.entity.state.AttackTree;
|
||||
import electrosphere.entity.state.GravityTree;
|
||||
import electrosphere.entity.state.IdleTree;
|
||||
import electrosphere.entity.types.life.LifeState;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
@ -80,9 +81,10 @@ public class CreatureUtils {
|
||||
case "CYLINDER":
|
||||
CollisionObject rigidBody = PhysicsUtils.getCylinderBody(1f, new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
|
||||
Collidable collidable = new Collidable(rVal, Collidable.TYPE_CREATURE);
|
||||
rVal.putData(EntityDataStrings.PHYSICS_RIGID_BODY, rigidBody);
|
||||
rVal.putData(EntityDataStrings.PHYSICS_RIGID_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
|
||||
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);
|
||||
Globals.collisionEngine.registerPhysicsEntity(rVal);
|
||||
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
|
||||
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
|
||||
@ -103,6 +105,15 @@ public class CreatureUtils {
|
||||
rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null);
|
||||
Globals.entityManager.registerAttackerEntity(rVal);
|
||||
break;
|
||||
case "GRAVITY":
|
||||
GravityTree gravityTree = new GravityTree(rVal);
|
||||
Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE);
|
||||
CollisionObject collisionObject = (CollisionObject)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
gravityTree.setCollisionObject(collisionObject, collidable);
|
||||
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
|
||||
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
|
||||
Globals.entityManager.registerGravityEntity(rVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//add all attack moves
|
||||
@ -202,7 +213,7 @@ public class CreatureUtils {
|
||||
}
|
||||
|
||||
public static CollisionObject getCreatureRigidBody(Entity e){
|
||||
return (CollisionObject)e.getData(EntityDataStrings.PHYSICS_RIGID_BODY);
|
||||
return (CollisionObject)e.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
}
|
||||
|
||||
public static void positionCharacter(Entity e, Vector3f position){
|
||||
|
||||
@ -46,6 +46,7 @@ public class CollisionEngine {
|
||||
List<Entity> dynamicPhysicsEntities = new ArrayList();
|
||||
List<Entity> structurePhysicsEntities = new ArrayList();
|
||||
List<CollisionObject> collisionObject = new ArrayList();
|
||||
List<Collidable> collidableList = new ArrayList();
|
||||
|
||||
public CollisionEngine(){
|
||||
broadphase = new DbvtBroadphase();
|
||||
@ -108,20 +109,26 @@ public class CollisionEngine {
|
||||
switch(impactor.getType()){
|
||||
case Collidable.TYPE_TERRAIN:
|
||||
// System.out.println("Terrain-creature collision: " + normal + " mag:" + realMagnitude);
|
||||
receiver.addImpulse(new Impulse(new Vector3f(0,1.0f,0), -1.0f * magnitude));
|
||||
receiver.addImpulse(new Impulse(new Vector3f(0,1.0f,0), -1.0f * magnitude, Collidable.TYPE_TERRAIN));
|
||||
break;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal,magnitude));
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
receiver.addImpulse(new Impulse(normal, magnitude));
|
||||
System.out.println("Structure-creature collision");
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCollidableImpulseLists(){
|
||||
for(Collidable collidable : collidableList){
|
||||
collidable.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@ -239,9 +246,9 @@ public class CollisionEngine {
|
||||
|
||||
public void updateDynamicObjectTransforms(){
|
||||
for(Entity dynamicEntity : dynamicPhysicsEntities){
|
||||
CollisionObject rigidBody = (CollisionObject)dynamicEntity.getData(EntityDataStrings.PHYSICS_RIGID_BODY);
|
||||
Vector3f offset = (Vector3f)dynamicEntity.getData(EntityDataStrings.PHYSICS_RIGID_BODY_OFFSET);
|
||||
Vector3f newPosition = PhysicsUtils.getRigidBodyPosition(rigidBody).add(offset);
|
||||
CollisionObject rigidBody = (CollisionObject)dynamicEntity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
Vector3f offset = (Vector3f)dynamicEntity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET);
|
||||
Vector3f newPosition = PhysicsUtils.getRigidBodyPosition(rigidBody).sub(offset);
|
||||
// System.out.println(rigidBody + " position " + newPosition);
|
||||
// System.out.println("Linear velocity: " + rigidBody.getLinearVelocity(new javax.vecmath.Vector3f()));
|
||||
EntityUtils.getPosition(dynamicEntity).set(newPosition);
|
||||
@ -251,6 +258,7 @@ public class CollisionEngine {
|
||||
public void registerCollisionObject(CollisionObject object, Collidable collidable){
|
||||
world.addCollisionObject(object);
|
||||
object.setUserPointer(collidable);
|
||||
collidableList.add(collidable);
|
||||
collisionObject.add(object);
|
||||
}
|
||||
|
||||
|
||||
@ -160,7 +160,7 @@ public class PhysicsUtils {
|
||||
// System.out.println("aabbMin: " + aabbMin + " aabbMax: " + aabbMax);
|
||||
|
||||
|
||||
terrain.putData(EntityDataStrings.PHYSICS_RIGID_BODY, terrainRigidBody);
|
||||
terrain.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, terrainRigidBody);
|
||||
|
||||
return terrainRigidBody;
|
||||
|
||||
@ -308,7 +308,7 @@ public class PhysicsUtils {
|
||||
|
||||
public static CollisionObject getPlaneObject(Vector3f dimensions){
|
||||
int[] indices = {
|
||||
0, 1, 3,
|
||||
0, 1, 2,
|
||||
1, 2, 3
|
||||
};
|
||||
|
||||
|
||||
@ -47,6 +47,10 @@ public class Collidable {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
impulses.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package electrosphere.game.state;
|
||||
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.AttackTree;
|
||||
import electrosphere.entity.state.GravityTree;
|
||||
import electrosphere.entity.state.IdleTree;
|
||||
import electrosphere.entity.state.movement.MovementTree;
|
||||
import electrosphere.entity.state.ParticleTree;
|
||||
@ -56,6 +58,11 @@ public class MicroSimulation {
|
||||
MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
|
||||
behaviorTree.simulate();
|
||||
}
|
||||
//simulate creature gravity trees
|
||||
for(Entity currentGravity : Globals.entityManager.getGravityEntities()){
|
||||
GravityTree gravityTree = (GravityTree)currentGravity.getData(EntityDataStrings.GRAVITY_TREE);
|
||||
gravityTree.simulate();
|
||||
}
|
||||
//attacker behavior tree
|
||||
for(Entity currentAttacker : Globals.entityManager.getAttackerEntities()){
|
||||
AttackTree attackTree = CreatureUtils.getAttackTree(currentAttacker);
|
||||
@ -89,6 +96,8 @@ public class MicroSimulation {
|
||||
HitboxUtils.collideEntities(currentHitbox);
|
||||
}
|
||||
}
|
||||
//clear collidable impulse lists
|
||||
Globals.collisionEngine.clearCollidableImpulseLists();
|
||||
}
|
||||
|
||||
public boolean isReady(){
|
||||
|
||||
@ -374,7 +374,7 @@ public class RenderingEngine {
|
||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
|
||||
Vector3f position = EntityUtils.getPosition(physicsEntity);
|
||||
modelTransformMatrix.identity();
|
||||
modelTransformMatrix.translate(new Vector3f(position));
|
||||
modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()));
|
||||
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
||||
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
|
||||
physicsGraphicsModel.modelMatrix = modelTransformMatrix;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user