Gravity collision accuracy improved dramatically
This commit is contained in:
parent
8777e63928
commit
a00f423696
@ -13,7 +13,7 @@
|
||||
"graphicsPerformanceDrawShadows" : true,
|
||||
|
||||
"graphicsDebugDrawCollisionSpheres" : false,
|
||||
"graphicsDebugDrawPhysicsObjects" : false,
|
||||
"graphicsDebugDrawPhysicsObjects" : true,
|
||||
"graphicsDebugDrawMovementVectors" : false,
|
||||
"graphicsDebugDrawNavmesh" : false
|
||||
|
||||
|
||||
@ -89,7 +89,7 @@
|
||||
{
|
||||
"type" : "GROUND",
|
||||
"acceleration" : 0.0015,
|
||||
"maxVelocity" : 0.015
|
||||
"maxVelocity" : 0.005
|
||||
}
|
||||
],
|
||||
"collidable" : {
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package electrosphere.controls;
|
||||
|
||||
import electrosphere.entity.CameraEntityUtils;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.AttackTree;
|
||||
import electrosphere.entity.state.movement.GroundMovementTree;
|
||||
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.menu.MenuTransition;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
@ -34,6 +36,7 @@ public class ControlHandler {
|
||||
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_JUMP = "jump";
|
||||
public static final String DATA_STRING_INPUT_CODE_MOVEMENT_FALL = "fall";
|
||||
public static final String DATA_STRING_INPUT_CODE_ATTACK_PRIMARY = "attackPrimary";
|
||||
public static final String DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM = "debugSpawnItem";
|
||||
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
|
||||
@ -176,6 +179,11 @@ public class ControlHandler {
|
||||
*/
|
||||
// Utilities.saveObjectToBakedJsonFile("/Config/keybinds.json", handler);
|
||||
|
||||
/*
|
||||
Debug controls
|
||||
*/
|
||||
handler.addControl(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM, new Control(true,false,GLFW_KEY_Q));
|
||||
|
||||
/*
|
||||
return
|
||||
*/
|
||||
@ -190,6 +198,7 @@ public class ControlHandler {
|
||||
|
||||
case MAIN_GAME:
|
||||
pollMainGameControls();
|
||||
pollInGameDebugControls();
|
||||
break;
|
||||
|
||||
|
||||
@ -359,6 +368,20 @@ public class ControlHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void pollInGameDebugControls(){
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).getKeyValue()) == GLFW_PRESS){
|
||||
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(true);
|
||||
} else {
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isState() == true){
|
||||
Entity bow = ItemUtils.spawnBasicItem("Bow");
|
||||
EntityUtils.getPosition(bow).set(1, 5, 2);
|
||||
}
|
||||
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pollMenuNavigationControls(){
|
||||
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_INCREMENT)){
|
||||
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).getKeyValue()) == GLFW_PRESS){
|
||||
|
||||
@ -30,15 +30,14 @@ public class GravityTree {
|
||||
|
||||
Entity parent;
|
||||
|
||||
float gravityVelocity = 0;
|
||||
float gravityAccel = 0.01f;
|
||||
|
||||
CollisionObject body;
|
||||
Collidable collidable;
|
||||
|
||||
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList();
|
||||
|
||||
int frameCurrent;
|
||||
|
||||
int maxFrame = 60;
|
||||
|
||||
public GravityTree(Entity e, Collidable collidable, CollisionObject body){
|
||||
state = GravityTreeState.ACTIVE;
|
||||
parent = e;
|
||||
@ -58,7 +57,6 @@ public class GravityTree {
|
||||
public void start(){
|
||||
//TODO: check if can start moving
|
||||
state = GravityTreeState.ACTIVE;
|
||||
frameCurrent = 0;
|
||||
}
|
||||
|
||||
public void interrupt(){
|
||||
@ -103,8 +101,6 @@ public class GravityTree {
|
||||
// }
|
||||
// }
|
||||
|
||||
boolean isIdle;
|
||||
|
||||
//state machine
|
||||
switch(state){
|
||||
case ACTIVE:
|
||||
@ -113,8 +109,15 @@ public class GravityTree {
|
||||
if(!hadStructureCollision()){
|
||||
position.set(new Vector3d(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z));
|
||||
}
|
||||
gravityVelocity = 0;
|
||||
} else {
|
||||
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||
if(gravityVelocity < gravityConstant){
|
||||
gravityVelocity = gravityVelocity + gravityAccel;
|
||||
}
|
||||
if(gravityVelocity > gravityConstant){
|
||||
gravityVelocity = gravityConstant;
|
||||
}
|
||||
float gravityDif = gravityVelocity * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||
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));
|
||||
// if(hitFraction >= 0){
|
||||
|
||||
@ -2,7 +2,9 @@ package electrosphere.entity.state.collidable;
|
||||
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.GravityTree;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.main.Globals;
|
||||
@ -39,6 +41,21 @@ public class CollidableTree {
|
||||
for(Impulse impulse : collidable.getImpulses()){
|
||||
// collidable.getImpulses().remove(impulse);
|
||||
Vector3d impulseForce = new Vector3d(impulse.getDirection()).mul(impulse.getForce());
|
||||
// if(impulse.type.matches(Collidable.TYPE_TERRAIN)){
|
||||
// System.out.println("Impulse force: " + impulseForce);
|
||||
// System.out.println("Position: " + position);
|
||||
// }
|
||||
// if(impulse.type.matches(Collidable.TYPE_ITEM)){
|
||||
// if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
|
||||
// ((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
|
||||
// }
|
||||
// }
|
||||
// if(impulse.type.matches(Collidable.TYPE_CREATURE)){
|
||||
// if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_TREE)){
|
||||
// ((GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE)).start();
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(impulse.type.matches("movement")){
|
||||
// System.out.println("Impulse force: " + impulseForce);
|
||||
// }
|
||||
|
||||
@ -100,7 +100,7 @@ public class CollisionEngine {
|
||||
}
|
||||
if (hit) {
|
||||
resolveCollision(physicsObject1,physicsObject2, normal, magnitude);
|
||||
resolveCollision(physicsObject2,physicsObject1, new Vector3d(normal).mul(-1.0f), magnitude);
|
||||
resolveCollision(physicsObject2,physicsObject1, new Vector3d(normal).mul(-1.0), magnitude);
|
||||
// System.out.println("HIT + " + normal);
|
||||
// Collision happened between physicsObject1 and physicsObject2. Collision normal is in variable 'normal'.
|
||||
}
|
||||
@ -123,17 +123,42 @@ public class CollisionEngine {
|
||||
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
||||
// System.out.println();
|
||||
// System.out.println("Terrain-creature collision: " + normal + " mag:" + magnitude);
|
||||
receiver.addImpulse(new Impulse(new Vector3d(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;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal, magnitude, Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
float realMag = 1f/(float)Math.pow(0.1, magnitude);
|
||||
System.out.println(normal + " - " + realMag);
|
||||
// System.out.println(normal + " - " + realMag);
|
||||
receiver.addImpulse(new Impulse(normal, realMag, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
receiver.addImpulse(new Impulse(normal, magnitude * 0.5, Collidable.TYPE_ITEM));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
switch(impactor.getType()){
|
||||
case Collidable.TYPE_TERRAIN:
|
||||
// System.out.println(EntityUtils.getPosition(impactor.getParent()) + " " + EntityUtils.getPosition(receiver.getParent()));
|
||||
// System.out.println();
|
||||
// System.out.println("Terrain-item collision: " + normal + " mag:" + magnitude);
|
||||
receiver.addImpulse(new Impulse(new Vector3d(0,normal.y,0), magnitude*2, Collidable.TYPE_TERRAIN));
|
||||
break;
|
||||
case Collidable.TYPE_CREATURE:
|
||||
receiver.addImpulse(new Impulse(normal, Math.min(magnitude * 0.5,0.5), Collidable.TYPE_CREATURE));
|
||||
break;
|
||||
case Collidable.TYPE_STRUCTURE:
|
||||
float realMag = 1f/(float)Math.pow(0.1, magnitude);
|
||||
// System.out.println(normal + " - " + realMag);
|
||||
receiver.addImpulse(new Impulse(normal, realMag, Collidable.TYPE_STRUCTURE));
|
||||
// System.out.println("Structure-creature collision");
|
||||
break;
|
||||
case Collidable.TYPE_ITEM:
|
||||
receiver.addImpulse(new Impulse(normal, magnitude * 0.5, Collidable.TYPE_ITEM));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -503,7 +503,7 @@ public class RenderingEngine {
|
||||
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||
modelTransformMatrix.rotate(rotation);
|
||||
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
||||
modelTransformMatrix.scale(scale);
|
||||
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
|
||||
physicsGraphicsModel.modelMatrix = modelTransformMatrix;
|
||||
physicsGraphicsModel.draw(true, true, false, true, true, true, true);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user