diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..e0f15db2
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "java.configuration.updateBuildConfiguration": "automatic"
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 78215dbe..89e127f9 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -29,9 +29,9 @@
{
"label": "Run",
"type": "shell",
- "command": "mvn process-classes exec:java -Dexec.mainClass=\"electrosphere.main.Main\"",
+ "command": "mvn process-classes exec:exec",
"windows": {
- "command": "mvn process-classes exec:java -Dexec.mainClass=\"electrosphere.main.Main\""
+ "command": "mvn process-classes exec:exec"
},
"group": "test",
"presentation": {
diff --git a/assets/Data/creatures.json b/assets/Data/creatures.json
index 6e67a65d..21d65290 100644
--- a/assets/Data/creatures.json
+++ b/assets/Data/creatures.json
@@ -123,6 +123,43 @@
}
}
],
+ "rotatorSystem" : {
+ "rotatorItems" : [
+ {
+ "boneName" : "myTorsoBone",
+ "constraints" : [
+ {
+ "followsView" : true,
+ "followsBone" : false,
+ "parentBone" : "",
+ "allowedMargin" : 0.2
+ }
+ ]
+ },
+ {
+ "boneName" : "myLeftLegBone",
+ "constraints" : [
+ {
+ "followsView" : false,
+ "followsBone" : true,
+ "parentBone" : "myTorsoBone",
+ "allowedMargin" : 0.2
+ }
+ ]
+ },
+ {
+ "boneName" : "myRightLegBone",
+ "constraints" : [
+ {
+ "followsView" : false,
+ "followsBone" : true,
+ "parentBone" : "myTorsoBone",
+ "allowedMargin" : 0.2
+ }
+ ]
+ }
+ ]
+ },
"collidable" : {
"type" : "CYLINDER",
"dimension1" : 0.1,
@@ -144,7 +181,7 @@
"maxHealth" : 100,
"onDamageIFrames" : 30
},
- "modelPath" : "Models/person1animpass2.fbx"
+ "modelPath" : "Models/baseman.fbx"
},
diff --git a/assets/Models/baseman.fbx b/assets/Models/baseman.fbx
new file mode 100644
index 00000000..f8b348eb
Binary files /dev/null and b/assets/Models/baseman.fbx differ
diff --git a/pom.xml b/pom.xml
index df670cf1..fa61118d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,12 +43,12 @@
org.lwjgl
lwjgl-openal
${lwjgl.version}
-
+
org.lwjgl
lwjgl-stb
${lwjgl.version}
-
+
org.lwjgl
@@ -96,27 +96,27 @@
${lwjgl.version}
${lwjgl.natives}
runtime
-
+
org.lwjgl
lwjgl-stb
${lwjgl.version}
${lwjgl.natives}
runtime
-
+
org.joml
joml
${joml.version}
-
-
+
+
com.google.code.gson
gson
2.8.6
-
+
-
+
org.apache.commons
commons-crypto
1.1.0
-
+
org.xerial
@@ -151,9 +151,9 @@
3.36.0.3
-
+
-
+
lwjgl-natives-linux
@@ -242,6 +242,31 @@
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 3.0.0
+
+
+
+ exec
+
+
+
+
+ java
+ false
+ true
+ electrosphere.main.Main
+
+
+ -cp
+ target/classes;target/Renderer-0.1-jar-with-dependencies.jar
+ electrosphere.main.Main
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/electrosphere/controls/ControlCallback.java b/src/main/java/electrosphere/controls/ControlCallback.java
new file mode 100644
index 00000000..6a2d3dcb
--- /dev/null
+++ b/src/main/java/electrosphere/controls/ControlCallback.java
@@ -0,0 +1,46 @@
+package electrosphere.controls;
+
+import org.lwjgl.glfw.GLFW;
+import org.lwjgl.glfw.GLFWKeyCallbackI;
+
+import electrosphere.logger.LoggerInterface;
+
+public class ControlCallback implements GLFWKeyCallbackI {
+
+ static final int KEY_VALUE_ARRAY_SIZE = 512;
+
+ boolean[] keyValues = new boolean[KEY_VALUE_ARRAY_SIZE];
+
+ @Override
+ public void invoke(long window, int key, int scancode, int action, int mods) {
+
+ if(key >= 0 && key < KEY_VALUE_ARRAY_SIZE){
+ if(action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT){
+ keyValues[key] = true;
+ } else {
+ keyValues[key] = false;
+ }
+ }
+ // if(key == GLFW.GLFW_KEY_D){
+ // System.out.println("[D]Action: " + action + " keyValues: " + keyValues[key]);
+ // }
+ // if(key == GLFW.GLFW_KEY_W){
+ // System.out.println("[W]Action: " + action + " keyValues: " + keyValues[key]);
+ // }
+ }
+
+ /**
+ * !!!WARNING!!!, will silently fail if
+ * @param keycode
+ * @return
+ */
+ public boolean getKey(int keycode){
+ if(keycode >= 0 && keycode < KEY_VALUE_ARRAY_SIZE){
+ return keyValues[keycode];
+ } else {
+ LoggerInterface.loggerEngine.WARNING("Trying to get key state where keycode is undefined (<0 or >400)");
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java
index 9495c6eb..ef373b67 100644
--- a/src/main/java/electrosphere/controls/ControlHandler.java
+++ b/src/main/java/electrosphere/controls/ControlHandler.java
@@ -8,6 +8,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.equip.EquipState;
import electrosphere.entity.state.movement.GroundMovementTree;
+import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
import electrosphere.entity.state.movement.SprintTree;
import electrosphere.entity.types.collision.CollisionObjUtils;
@@ -16,17 +17,12 @@ import electrosphere.game.client.targeting.crosshair.Crosshair;
import electrosphere.main.Globals;
import electrosphere.menu.MenuTransition;
import electrosphere.menu.MenuUtils;
-import electrosphere.net.parser.net.message.EntityMessage;
-import electrosphere.renderer.ui.Widget;
-import electrosphere.util.Utilities;
import java.util.HashMap;
-import java.util.List;
import org.joml.Vector2f;
import org.joml.Vector3d;
import org.joml.Vector3f;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.glfw.GLFW.glfwGetCursorPos;
-import static org.lwjgl.glfw.GLFW.glfwGetKey;
import static org.lwjgl.glfw.GLFW.glfwGetMouseButton;
import static org.lwjgl.glfw.GLFW.glfwSetInputMode;
@@ -112,7 +108,7 @@ public class ControlHandler {
HashMap controls;
ControlHandler(){
- controls = new HashMap();
+ controls = new HashMap();
}
public static ControlHandler generateExampleControlsMap(){
@@ -221,7 +217,8 @@ public class ControlHandler {
-
+ case TITLE_PAGE:
+ break;
case TITLE_MENU:
@@ -252,12 +249,20 @@ public class ControlHandler {
Move forward
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
- if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())){
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
- CreatureUtils.setMovementVector(Globals.playerCharacter, newFacingVector);
+ CreatureUtils.setFacingVector(Globals.playerCharacter, newFacingVector);
// System.out.println("Movement vector: " + newFacingVector);
- if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
- movementTree.start();
+ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.FORWARD){
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
+ movementTree.start(MovementRelativeFacing.FORWARD_LEFT);
+ } else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
+ movementTree.start(MovementRelativeFacing.FORWARD_RIGHT);
+ // System.out.println("f-r");
+ } else {
+ // System.out.println(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() + "&&" + Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue()));
+ movementTree.start(MovementRelativeFacing.FORWARD);
+ }
}
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).setState(true);
//send to server
@@ -281,10 +286,16 @@ public class ControlHandler {
Move backward
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
- if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()) == GLFW_PRESS){
- CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
- if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
- movementTree.start();
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())){
+ CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
+ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN || movementTree.getFacing() != MovementRelativeFacing.BACKWARD){
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
+ movementTree.start(MovementRelativeFacing.BACKWARD_LEFT);
+ } else if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
+ movementTree.start(MovementRelativeFacing.BACKWARD_RIGHT);
+ } else {
+ movementTree.start(MovementRelativeFacing.BACKWARD);
+ }
}
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).setState(true);
//send to server
@@ -308,10 +319,14 @@ public class ControlHandler {
Move left
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
- if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue()) == GLFW_PRESS){
- CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
- if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
- movementTree.start();
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue())){
+ CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
+ if(
+ (movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
+ (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
+ (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
+ ){
+ movementTree.start(MovementRelativeFacing.LEFT);
}
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).setState(true);
//send to server
@@ -335,10 +350,14 @@ public class ControlHandler {
Move right
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
- if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue()) == GLFW_PRESS){
- CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
- if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
- movementTree.start();
+ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue())){
+ CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z));
+ if(
+ (movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
+ (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
+ (controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
+ ){
+ movementTree.start(MovementRelativeFacing.RIGHT);
}
controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).setState(true);
//send to server
@@ -361,20 +380,20 @@ public class ControlHandler {
/*
Move up
*/
- if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).getKeyValue()) == GLFW_PRESS){
+ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_JUMP).getKeyValue())){
EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,0.6f,0).mul(1f));
}
/*
Move down
*/
- if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL).getKeyValue()) == GLFW_PRESS){
+ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FALL) && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FALL).getKeyValue())){
EntityUtils.getPosition(Globals.playerCharacter).add(new Vector3f(0,-0.6f,0).mul(1f));
}
/*
Sprint
*/
if(controls.containsKey(INPUT_CODE_SPRINT)){
- if(controls.get(INPUT_CODE_SPRINT).isIsKey() && glfwGetKey(Globals.window, controls.get(INPUT_CODE_SPRINT).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(INPUT_CODE_SPRINT).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_SPRINT).getKeyValue())){
if(controls.get(INPUT_CODE_SPRINT).isState() == false){
if(sprintTree != null){
sprintTree.start();
@@ -395,7 +414,7 @@ public class ControlHandler {
Interact
*/
if(controls.containsKey(INPUT_CODE_INTERACT)){
- if(controls.get(INPUT_CODE_INTERACT).isIsKey() && glfwGetKey(Globals.window, controls.get(INPUT_CODE_INTERACT).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(INPUT_CODE_INTERACT).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_INTERACT).getKeyValue())){
if(controls.get(INPUT_CODE_INTERACT).isState() == false){
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
@@ -414,7 +433,7 @@ public class ControlHandler {
Drop
*/
if(controls.containsKey(INPUT_CODE_DROP)){
- if(controls.get(INPUT_CODE_DROP).isIsKey() && glfwGetKey(Globals.window, controls.get(INPUT_CODE_DROP).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(INPUT_CODE_DROP).isIsKey() && Globals.controlCallback.getKey(controls.get(INPUT_CODE_DROP).getKeyValue())){
if(controls.get(INPUT_CODE_DROP).isState() == false){
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
@@ -436,7 +455,7 @@ public class ControlHandler {
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isIsMouse() && glfwGetMouseButton(Globals.window, controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).getKeyValue()) == GLFW_PRESS){
if(controls.get(DATA_STRING_INPUT_CODE_ATTACK_PRIMARY).isState() == false){
if(attackTree != null){
- CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
+ CreatureUtils.setFacingVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize());
attackTree.start(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND);
}
}
@@ -475,7 +494,7 @@ public class ControlHandler {
Main menu dialog toggle
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU)){
- if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isState() == true){
@@ -495,7 +514,7 @@ 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){
+ if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM).isState() == true){
@@ -510,7 +529,7 @@ public class ControlHandler {
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){
+ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isState() == true){
@@ -520,7 +539,7 @@ public class ControlHandler {
}
}
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_DECREMENT)){
- if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_MENU_DECREMENT).isState() == true){
@@ -530,7 +549,7 @@ public class ControlHandler {
}
}
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_SELECT)){
- if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_MENU_SELECT).isState() == true){
@@ -540,7 +559,7 @@ public class ControlHandler {
}
}
if(controls.containsKey(DATA_STRING_INPUT_CODE_MENU_BACKOUT)){
- if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(DATA_STRING_INPUT_CODE_MENU_INCREMENT).isIsKey() && Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).getKeyValue())){
controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).setState(true);
} else {
if(controls.get(DATA_STRING_INPUT_CODE_MENU_BACKOUT).isState() == true){
@@ -568,7 +587,7 @@ public class ControlHandler {
DATA_STRING_INPUT_CODE_MENU_TYPE_PERIOD,
};
for(String currentKey : typeKeybinds){
- if(controls.get(currentKey).isIsKey() && glfwGetKey(Globals.window, controls.get(currentKey).getKeyValue()) == GLFW_PRESS){
+ if(controls.get(currentKey).isIsKey() && Globals.controlCallback.getKey(controls.get(currentKey).getKeyValue())){
controls.get(currentKey).setState(true);
} else {
if(controls.get(currentKey).isState() == true){
diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java
index 97b8b89d..60a24489 100644
--- a/src/main/java/electrosphere/entity/EntityDataStrings.java
+++ b/src/main/java/electrosphere/entity/EntityDataStrings.java
@@ -33,7 +33,7 @@ public class EntityDataStrings {
public static final String DATA_STRING_CREATURE_CONTROLLER_PLAYER_ID = "creaturePlayerId";
public static final String DATA_STRING_MOVEMENT_BT = "movementBT";
public static final String SPRINT_TREE = "sprintBT";
- public static final String DATA_STRING_MOVEMENT_VECTOR = "movementVector";
+ public static final String DATA_STRING_FACING_VECTOR = "facingVector";
public static final String DATA_STRING_VELOCITY = "velocity";
public static final String DATA_STRING_ACCELERATION = "acceleration";
public static final String DATA_STRING_MAX_NATURAL_VELOCITY = "velocityMaxNatural";
diff --git a/src/main/java/electrosphere/entity/state/AttackTree.java b/src/main/java/electrosphere/entity/state/AttackTree.java
index 83883b93..9ab16c2c 100644
--- a/src/main/java/electrosphere/entity/state/AttackTree.java
+++ b/src/main/java/electrosphere/entity/state/AttackTree.java
@@ -66,7 +66,7 @@ public class AttackTree {
if(parent.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT)){
CreatureUtils.getEntityMovementTree(parent).interrupt();
}
- Vector3d movementVector = CreatureUtils.getMovementVector(parent);
+ Vector3d movementVector = CreatureUtils.getFacingVector(parent);
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z));
state = AttackTreeState.WINDUP;
frameCurrent = 0;
@@ -85,7 +85,7 @@ public class AttackTree {
float velocity = CreatureUtils.getVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);
Vector3d position = EntityUtils.getPosition(parent);
- Vector3d movementVector = CreatureUtils.getMovementVector(parent);
+ Vector3d movementVector = CreatureUtils.getFacingVector(parent);
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
@@ -120,7 +120,7 @@ public class AttackTree {
}
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
- CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
+ CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}
diff --git a/src/main/java/electrosphere/entity/state/IdleTree.java b/src/main/java/electrosphere/entity/state/IdleTree.java
index 6a2fcda5..11c05ebf 100644
--- a/src/main/java/electrosphere/entity/state/IdleTree.java
+++ b/src/main/java/electrosphere/entity/state/IdleTree.java
@@ -84,7 +84,7 @@ public class IdleTree {
break;
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
- CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
+ CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}
diff --git a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java
index 7e7b746c..da598f10 100644
--- a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java
+++ b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java
@@ -42,6 +42,17 @@ public class GroundMovementTree {
SLOWDOWN,
IDLE,
}
+
+ public static enum MovementRelativeFacing {
+ FORWARD,
+ LEFT,
+ RIGHT,
+ BACKWARD,
+ FORWARD_LEFT,
+ FORWARD_RIGHT,
+ BACKWARD_LEFT,
+ BACKWARD_RIGHT,
+ }
static final double STATE_DIFFERENCE_HARD_UPDATE_THRESHOLD = 1.0;
static final double STATE_DIFFERENCE_SOFT_UPDATE_THRESHOLD = 0.2;
@@ -55,6 +66,7 @@ public class GroundMovementTree {
String animationSprintWindDown = Animation.ANIMATION_SPRINT_WINDDOWN;
MovementTreeState state;
+ MovementRelativeFacing facing;
SprintTree sprintTree;
@@ -69,6 +81,7 @@ public class GroundMovementTree {
public GroundMovementTree(Entity e, Collidable collidable){
state = MovementTreeState.IDLE;
+ facing = MovementRelativeFacing.FORWARD;
parent = e;
this.collidable = collidable;
}
@@ -77,9 +90,10 @@ public class GroundMovementTree {
return state;
}
- public void start(){
+ public void start(MovementRelativeFacing facing){
//TODO: check if can start moving
if(canStartMoving()){
+ this.facing = facing;
state = MovementTreeState.STARTUP;
}
}
@@ -100,9 +114,36 @@ public class GroundMovementTree {
Actor entityActor = EntityUtils.getActor(parent);
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent);
- Vector3d movementVector = CreatureUtils.getMovementVector(parent);
+ Vector3d facingVector = CreatureUtils.getFacingVector(parent);
+ Vector3d movementVector = new Vector3d(facingVector);
+ switch(facing){
+ case FORWARD:
+ break;
+ case LEFT:
+ movementVector.rotateY((float)(90 * Math.PI / 180)).normalize();
+ break;
+ case RIGHT:
+ movementVector.rotateY((float)(-90 * Math.PI / 180)).normalize();
+ break;
+ case BACKWARD:
+ movementVector.x = -movementVector.x;
+ movementVector.z = -movementVector.z;
+ break;
+ case FORWARD_LEFT:
+ movementVector.rotateY((float)(45 * Math.PI / 180)).normalize();
+ break;
+ case FORWARD_RIGHT:
+ movementVector.rotateY((float)(-45 * Math.PI / 180)).normalize();
+ break;
+ case BACKWARD_LEFT:
+ movementVector.rotateY((float)(135 * Math.PI / 180)).normalize();
+ break;
+ case BACKWARD_RIGHT:
+ movementVector.rotateY((float)(-135 * Math.PI / 180)).normalize();
+ break;
+ }
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
- Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,0,(float)movementVector.z)).normalize();
+ Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingVector.x,0,(float)facingVector.z)).normalize();
Quaternionf rotation = EntityUtils.getRotation(parent);
//parse attached network messages
@@ -160,11 +201,14 @@ public class GroundMovementTree {
} else if(position.distance(message.getpositionX(),message.getpositionY(),message.getpositionZ()) > STATE_DIFFERENCE_SOFT_UPDATE_THRESHOLD){
EntityUtils.getPosition(parent).add(new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()).mul(SOFT_UPDATE_MULTIPLIER));
}
- CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
+ CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
// EntityUtils.getEntityRotation(parent).set(message.getrotationX(), message.getrotationY(), message.getrotationZ(), message.getrotationW()).normalize();
// velocity = message.getvelocity();
break;
}
+ break;
+ default:
+ break;
}
}
@@ -176,17 +220,22 @@ public class GroundMovementTree {
velocity = velocity + acceleration * Main.deltaTime;
CreatureUtils.setVelocity(parent, velocity);
if(entityActor != null){
- if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprintStart)){
- entityActor.playAnimation(animationSprintStart,1);
- entityActor.incrementAnimationTime(0.01);
- }
- } else {
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationStartUp)){
- entityActor.playAnimation(animationStartUp,1);
- entityActor.incrementAnimationTime(0.01);
- }
+ String animationToPlay = determineCorrectAnimation();
+ if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){
+ entityActor.playAnimation(animationToPlay,1);
+ entityActor.incrementAnimationTime(0.01);
}
+ // if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprintStart)){
+ // entityActor.playAnimation(animationSprintStart,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // } else {
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationStartUp)){
+ // entityActor.playAnimation(animationStartUp,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // }
}
//check if can transition state
if(velocity >= maxNaturalVelocity){
@@ -260,17 +309,22 @@ public class GroundMovementTree {
//check if can restart animation
//if yes, restart animation
if(entityActor != null){
- if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprint)){
- entityActor.playAnimation(animationSprint,1);
- entityActor.incrementAnimationTime(0.01);
- }
- } else {
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationMain)){
- entityActor.playAnimation(animationMain,1);
- entityActor.incrementAnimationTime(0.01);
- }
+ String animationToPlay = determineCorrectAnimation();
+ if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){
+ entityActor.playAnimation(animationToPlay,1);
+ entityActor.incrementAnimationTime(0.01);
}
+ // if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprint)){
+ // entityActor.playAnimation(animationSprint,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // } else {
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationMain)){
+ // entityActor.playAnimation(animationMain,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // }
}
if(velocity != maxNaturalVelocity){
velocity = maxNaturalVelocity;
@@ -342,17 +396,22 @@ public class GroundMovementTree {
velocity = velocity - acceleration * Main.deltaTime;
CreatureUtils.setVelocity(parent, velocity);
if(entityActor != null){
- if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprintWindDown)){
- entityActor.playAnimation(animationSprintWindDown,1);
- entityActor.incrementAnimationTime(0.01);
- }
- } else {
- if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSlowDown)){
- entityActor.playAnimation(animationSlowDown,1);
- entityActor.incrementAnimationTime(0.01);
- }
+ String animationToPlay = determineCorrectAnimation();
+ if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){
+ entityActor.playAnimation(animationToPlay,1);
+ entityActor.incrementAnimationTime(0.01);
}
+ // if(sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING){
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSprintWindDown)){
+ // entityActor.playAnimation(animationSprintWindDown,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // } else {
+ // if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationSlowDown)){
+ // entityActor.playAnimation(animationSlowDown,1);
+ // entityActor.incrementAnimationTime(0.01);
+ // }
+ // }
}
//check if can transition state
if(velocity <= 0){
@@ -368,7 +427,7 @@ public class GroundMovementTree {
// }
collidable.addImpulse(new Impulse(new Vector3d(movementVector), velocity * Main.deltaTime, "movement"));
// position.set(newPosition);
- rotation.rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z));
+ rotation.set(movementQuaternion);
activateGravityTree();
@@ -484,5 +543,214 @@ public class GroundMovementTree {
public void setSprintTree(SprintTree sprintTree){
this.sprintTree = sprintTree;
}
+
+ public MovementRelativeFacing getFacing(){
+ return facing;
+ }
+
+ public String determineCorrectAnimation(){
+ String rVal = "";
+ if(sprintTree != null){
+ switch(sprintTree.state){
+ case SPRINTING:
+ switch(state){
+ case IDLE:
+ break;
+ case STARTUP:
+ rVal = animationSprintStart;
+ break;
+ case MOVE:
+ rVal = animationSprint;
+ break;
+ case SLOWDOWN:
+ rVal = animationSprintWindDown;
+ break;
+ }
+ break;
+ case NOT_SPRINTING:
+ switch(state){
+ case IDLE:
+ break;
+ case STARTUP:
+ switch(facing){
+ case FORWARD:
+ rVal = animationStartUp;
+ break;
+ case BACKWARD:
+ rVal = animationStartUp;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ case MOVE:
+ switch(facing){
+ case FORWARD:
+ rVal = animationMain;
+ break;
+ case BACKWARD:
+ rVal = animationMain;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ case SLOWDOWN:
+ switch(facing){
+ case FORWARD:
+ rVal = animationSlowDown;
+ break;
+ case BACKWARD:
+ rVal = animationSlowDown;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ }
+ break;
+ }
+ } else {
+ switch(state){
+ case IDLE:
+ break;
+ case STARTUP:
+ switch(facing){
+ case FORWARD:
+ rVal = animationStartUp;
+ break;
+ case BACKWARD:
+ rVal = animationStartUp;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ case MOVE:
+ switch(facing){
+ case FORWARD:
+ rVal = animationMain;
+ break;
+ case BACKWARD:
+ rVal = animationMain;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ case SLOWDOWN:
+ switch(facing){
+ case FORWARD:
+ rVal = animationSlowDown;
+ break;
+ case BACKWARD:
+ rVal = animationSlowDown;
+ break;
+ case LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case FORWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case FORWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ case BACKWARD_LEFT:
+ rVal = Animation.ANIMATION_WALK_LEFT;
+ break;
+ case BACKWARD_RIGHT:
+ rVal = Animation.ANIMATION_WALK_RIGHT;
+ break;
+ }
+ break;
+ }
+ }
+
+
+ return rVal;
+ }
}
diff --git a/src/main/java/electrosphere/entity/state/rotator/RotatorConstraint.java b/src/main/java/electrosphere/entity/state/rotator/RotatorConstraint.java
new file mode 100644
index 00000000..8d427eec
--- /dev/null
+++ b/src/main/java/electrosphere/entity/state/rotator/RotatorConstraint.java
@@ -0,0 +1,31 @@
+package electrosphere.entity.state.rotator;
+
+public class RotatorConstraint {
+
+ boolean followsView;
+ boolean followsBone;
+ String parentBone;
+ float allowedMarginPitch;
+ float allowedMarginYaw;
+
+ public boolean getFollowsView(){
+ return followsView;
+ }
+
+ public boolean getFollowsBone(){
+ return followsBone;
+ }
+
+ public String getParentBone(){
+ return parentBone;
+ }
+
+ public float getAllowedMarginPitch(){
+ return allowedMarginPitch;
+ }
+
+ public float getAllowedMarginYaw(){
+ return allowedMarginYaw;
+ }
+
+}
diff --git a/src/main/java/electrosphere/entity/state/rotator/RotatorHierarchyNode.java b/src/main/java/electrosphere/entity/state/rotator/RotatorHierarchyNode.java
new file mode 100644
index 00000000..2bc3a72d
--- /dev/null
+++ b/src/main/java/electrosphere/entity/state/rotator/RotatorHierarchyNode.java
@@ -0,0 +1,35 @@
+package electrosphere.entity.state.rotator;
+
+import java.util.List;
+
+public class RotatorHierarchyNode {
+
+ String bone;
+ List rotatorConstraints;
+ List children;
+
+ public String getBone(){
+ return bone;
+ }
+
+ public List getRotatorContraints(){
+ return rotatorConstraints;
+ }
+
+ public List getChildren(){
+ return children;
+ }
+
+ public void addChild(RotatorHierarchyNode child){
+ this.children.add(child);
+ }
+
+ public void addRotatorConstraint(RotatorConstraint contraint){
+ this.rotatorConstraints.add(contraint);
+ }
+
+ public void setBone(String bone){
+ this.bone = bone;
+ }
+
+}
diff --git a/src/main/java/electrosphere/entity/state/rotator/RotatorTree.java b/src/main/java/electrosphere/entity/state/rotator/RotatorTree.java
new file mode 100644
index 00000000..780c9d74
--- /dev/null
+++ b/src/main/java/electrosphere/entity/state/rotator/RotatorTree.java
@@ -0,0 +1,78 @@
+package electrosphere.entity.state.rotator;
+
+import java.util.List;
+
+import org.joml.Quaternionf;
+
+import electrosphere.entity.Entity;
+import electrosphere.entity.EntityUtils;
+import electrosphere.renderer.actor.Actor;
+
+public class RotatorTree {
+
+ public static enum RotatorTreeState {
+ ACTIVE,
+ INACTIVE,
+ }
+
+ RotatorTreeState state;
+
+ Entity parent;
+ Actor entityActor;
+
+ List rootNodes;
+
+ public RotatorTree(Entity parent){
+ entityActor = EntityUtils.getActor(parent);
+ state = RotatorTreeState.INACTIVE;
+ }
+
+ public void setActive(boolean isActive){
+ if(isActive){
+ state = RotatorTreeState.ACTIVE;
+ } else {
+ state = RotatorTreeState.INACTIVE;
+ }
+ }
+
+ public void simulate(){
+ if(entityActor.modelIsLoaded() && this.state == RotatorTreeState.ACTIVE){
+ for(RotatorHierarchyNode node : rootNodes){
+ applyRotatorNode(node);
+ }
+ }
+ }
+
+ public void applyRotatorNode(RotatorHierarchyNode node){
+ //apply
+ String nodeBoneName = node.getBone();
+ Quaternionf currentRotation = entityActor.getBoneRotation(nodeBoneName);
+ for(RotatorConstraint constraint : node.getRotatorContraints()){
+ float allowedMarginPitch = constraint.getAllowedMarginPitch();
+ float allowedMarginYaw = constraint.getAllowedMarginYaw();
+ boolean followsBone = constraint.getFollowsBone();
+ boolean followsView = constraint.getFollowsView();
+ if(followsBone){
+ String parentBone = constraint.getParentBone();
+ Quaternionf parentBoneRotation = entityActor.getBoneRotation(parentBone);
+ // currentRotation.
+ }
+ if(followsView){
+
+ }
+ }
+ //recurse to children
+ for(RotatorHierarchyNode child : node.getChildren()){
+ applyRotatorNode(child);
+ }
+ }
+
+ public float calculateYawOfQuat(Quaternionf quat){
+ return (float)Math.atan2(2.0*(quat.y*quat.z + quat.w*quat.x), quat.w*quat.w - quat.x*quat.x - quat.y*quat.y + quat.z*quat.z);
+ }
+
+ public float calculatePitchOfQuat(Quaternionf quat){
+ return (float)Math.asin(-2.0*(quat.x*quat.z - quat.w*quat.y));
+ }
+
+}
diff --git a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java
index 9ac62450..b729113f 100644
--- a/src/main/java/electrosphere/entity/types/attach/AttachUtils.java
+++ b/src/main/java/electrosphere/entity/types/attach/AttachUtils.java
@@ -54,7 +54,7 @@ public class AttachUtils {
//set rotation
// Quaternionf rotation = parentActor.getBoneRotation(targetBone);
// EntityUtils.getRotation(currentEntity).set(rotation).normalize();
- Vector3d facingAngle = CreatureUtils.getMovementVector(parent);
+ Vector3d facingAngle = CreatureUtils.getFacingVector(parent);
EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingAngle.x,(float)facingAngle.y,(float)facingAngle.z)).mul(parentActor.getBoneRotation(targetBone)).normalize();
}
}
diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java
index 17c0c20a..5350e398 100644
--- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java
+++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java
@@ -125,7 +125,7 @@ public class CreatureUtils {
Globals.entityManager.registerSprintableEntity(rVal);
}
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, moveTree);
- rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
+ rVal.putData(EntityDataStrings.DATA_STRING_FACING_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);
@@ -179,7 +179,7 @@ public class CreatureUtils {
Globals.entityManager.registerCreatureEntity(rVal);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
- rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3d(0,0,1));
+ rVal.putData(EntityDataStrings.DATA_STRING_FACING_VECTOR, new Vector3d(0,0,1));
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
return rVal;
}
@@ -196,12 +196,12 @@ public class CreatureUtils {
}
}
- public static void setMovementVector(Entity e, Vector3d vector){
- e.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, vector);
+ public static void setFacingVector(Entity e, Vector3d vector){
+ e.putData(EntityDataStrings.DATA_STRING_FACING_VECTOR, vector);
}
- public static Vector3d getMovementVector(Entity e){
- return (Vector3d)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR);
+ public static Vector3d getFacingVector(Entity e){
+ return (Vector3d)e.getData(EntityDataStrings.DATA_STRING_FACING_VECTOR);
}
public static float getAcceleration(Entity e){
diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureType.java b/src/main/java/electrosphere/game/data/creature/type/CreatureType.java
index f67d445c..b0a7e22c 100644
--- a/src/main/java/electrosphere/game/data/creature/type/CreatureType.java
+++ b/src/main/java/electrosphere/game/data/creature/type/CreatureType.java
@@ -1,6 +1,8 @@
package electrosphere.game.data.creature.type;
import electrosphere.entity.types.hitbox.HitboxData;
+import electrosphere.game.data.creature.type.rotator.RotatorSystem;
+
import java.util.List;
public class CreatureType {
@@ -9,6 +11,7 @@ public class CreatureType {
List hitboxes;
List tokens;
List movementSystems;
+ RotatorSystem rotatorSystem;
CollidableTemplate collidable;
List attackMoves;
HealthSystem healthSystem;
@@ -55,7 +58,9 @@ public class CreatureType {
return lookAtSystem;
}
-
+ public RotatorSystem getRotatorSystem() {
+ return rotatorSystem;
+ }
}
diff --git a/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorConstraint.java b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorConstraint.java
new file mode 100644
index 00000000..9e0a3aa2
--- /dev/null
+++ b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorConstraint.java
@@ -0,0 +1,31 @@
+package electrosphere.game.data.creature.type.rotator;
+
+public class RotatorConstraint {
+
+ boolean followsView;
+ boolean followsBone;
+ String parentBone;
+ float allowedMarginPitch;
+ float allowedMarginYaw;
+
+ public boolean getFollowsView(){
+ return followsView;
+ }
+
+ public boolean getFollowsBone(){
+ return followsBone;
+ }
+
+ public String getParentBone(){
+ return parentBone;
+ }
+
+ public float getAllowedMarginPitch(){
+ return allowedMarginPitch;
+ }
+
+ public float getAllowedMarginYaw(){
+ return allowedMarginYaw;
+ }
+
+}
diff --git a/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorItem.java b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorItem.java
new file mode 100644
index 00000000..c0baf45a
--- /dev/null
+++ b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorItem.java
@@ -0,0 +1,16 @@
+package electrosphere.game.data.creature.type.rotator;
+
+import java.util.List;
+
+public class RotatorItem {
+ String boneName;
+ List constraints;
+
+ public String getBoneName(){
+ return boneName;
+ }
+
+ public List getConstraints(){
+ return constraints;
+ }
+}
diff --git a/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorSystem.java b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorSystem.java
new file mode 100644
index 00000000..2fa978b6
--- /dev/null
+++ b/src/main/java/electrosphere/game/data/creature/type/rotator/RotatorSystem.java
@@ -0,0 +1,11 @@
+package electrosphere.game.data.creature.type.rotator;
+
+import java.util.List;
+
+public class RotatorSystem {
+ List rotatorItems;
+
+ public List getRotatorItems() {
+ return rotatorItems;
+ }
+}
diff --git a/src/main/java/electrosphere/game/server/ai/creature/MillAbout.java b/src/main/java/electrosphere/game/server/ai/creature/MillAbout.java
index 1e6a9b1e..6cd233e8 100644
--- a/src/main/java/electrosphere/game/server/ai/creature/MillAbout.java
+++ b/src/main/java/electrosphere/game/server/ai/creature/MillAbout.java
@@ -3,6 +3,7 @@ package electrosphere.game.server.ai.creature;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.GroundMovementTree;
+import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.server.ai.AI;
import electrosphere.main.Globals;
@@ -76,10 +77,10 @@ public class MillAbout extends AI {
if(moveToTarget){
if(moveTargetPosition.distance(position) > 0.4){
Vector3d moveVector = new Vector3d(moveTargetPosition).sub(position).normalize();
- CreatureUtils.setMovementVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
+ CreatureUtils.setFacingVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
- characterMoveTree.start();
+ characterMoveTree.start(MovementRelativeFacing.FORWARD);
}
} else {
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
diff --git a/src/main/java/electrosphere/game/server/ai/creature/MindlessAttacker.java b/src/main/java/electrosphere/game/server/ai/creature/MindlessAttacker.java
index 38c66ef6..b0513800 100644
--- a/src/main/java/electrosphere/game/server/ai/creature/MindlessAttacker.java
+++ b/src/main/java/electrosphere/game/server/ai/creature/MindlessAttacker.java
@@ -5,6 +5,7 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.movement.GroundMovementTree;
+import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.server.ai.AI;
import electrosphere.main.Globals;
@@ -69,10 +70,10 @@ public class MindlessAttacker extends AI{
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
- CreatureUtils.setMovementVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
+ CreatureUtils.setFacingVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
- characterMoveTree.start();
+ characterMoveTree.start(MovementRelativeFacing.FORWARD);
}
}
diff --git a/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java b/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java
index 788d202a..c6fed489 100644
--- a/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java
+++ b/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java
@@ -6,6 +6,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.equip.EquipState;
import electrosphere.entity.state.movement.GroundMovementTree;
+import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.ai.AI;
@@ -161,10 +162,10 @@ public class OpportunisticAttacker extends AI {
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
- CreatureUtils.setMovementVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
+ CreatureUtils.setFacingVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
- characterMoveTree.start();
+ characterMoveTree.start(MovementRelativeFacing.FORWARD);
}
}
@@ -254,7 +255,7 @@ public class OpportunisticAttacker extends AI {
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d movementVector = new Vector3d(targetPosition).sub(position).normalize();
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,0,(float)movementVector.z)).normalize();
- CreatureUtils.setMovementVector(character, movementVector);
+ CreatureUtils.setFacingVector(character, movementVector);
EntityUtils.getRotation(character).set(movementQuaternion);
}
diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java
index f048cc07..0d20c8ce 100644
--- a/src/main/java/electrosphere/main/Globals.java
+++ b/src/main/java/electrosphere/main/Globals.java
@@ -8,6 +8,7 @@ import electrosphere.renderer.texture.Texture;
import electrosphere.renderer.texture.TextureMap;
import com.google.gson.Gson;
import electrosphere.audio.AudioEngine;
+import electrosphere.controls.ControlCallback;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
@@ -118,6 +119,7 @@ public class Globals {
//
public static ControlHandler controlHandler;
public static boolean updateCamera = true;
+ public static ControlCallback controlCallback;
//
diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java
index c8f440cb..56b40c91 100644
--- a/src/main/java/electrosphere/main/Main.java
+++ b/src/main/java/electrosphere/main/Main.java
@@ -103,7 +103,7 @@ public class Main {
public static Entity letterEntity;
- static float targetFrameRate = 1000.0f/144.0f;
+ static float targetFrameRate = 1.0f/144.0f;
public static void main(String args[]){
@@ -362,7 +362,13 @@ public class Main {
running = false;
}
- sleep((int)(1000.0*Math.max(0.003, deltaTime-targetFrameRate)));
+ // System.out.println(deltaTime + " - " + targetFrameRate);
+ if(deltaTime < targetFrameRate){
+ sleep((int)(1000.0 * (targetFrameRate - deltaTime)));
+ } else {
+ sleep(1);
+ }
+ // sleep((int)(1000.0*Math.max(0.001, deltaTime-targetFrameRate)));
}
//Terminate the program.
glfwTerminate();
diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java
index 6cd5279d..d1d7e00d 100644
--- a/src/main/java/electrosphere/renderer/RenderingEngine.java
+++ b/src/main/java/electrosphere/renderer/RenderingEngine.java
@@ -1,5 +1,6 @@
package electrosphere.renderer;
+import electrosphere.controls.ControlCallback;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
@@ -30,6 +31,8 @@ import org.joml.Vector3d;
import org.joml.Vector3f;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
+import org.lwjgl.glfw.GLFWKeyCallback;
+
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MINOR;
import static org.lwjgl.glfw.GLFW.GLFW_CURSOR;
@@ -155,7 +158,11 @@ public class RenderingEngine {
Globals.WINDOW_WIDTH = bufferWidth;
Globals.WINDOW_HEIGHT = bufferHeight;
-
+
+ //set key callback
+ Globals.controlCallback = new ControlCallback();
+ GLFW.glfwSetKeyCallback(Globals.window, Globals.controlCallback);
+
//get title bar dimensions
// setTitleBarDimensions();
diff --git a/src/main/java/electrosphere/renderer/actor/Actor.java b/src/main/java/electrosphere/renderer/actor/Actor.java
index 6d5fd0c2..c14055d0 100644
--- a/src/main/java/electrosphere/renderer/actor/Actor.java
+++ b/src/main/java/electrosphere/renderer/actor/Actor.java
@@ -279,6 +279,15 @@ public class Actor {
}
return rVal;
}
+
+ public boolean modelIsLoaded(){
+ Model model = Globals.assetManager.fetchModel(modelPath);
+ if(model != null){
+ return true;
+ } else {
+ return false;
+ }
+ }
public void setTextureOverride(String override){
textureOverride = override;
diff --git a/src/main/java/electrosphere/renderer/anim/Animation.java b/src/main/java/electrosphere/renderer/anim/Animation.java
index ad7e1927..5c48d63f 100644
--- a/src/main/java/electrosphere/renderer/anim/Animation.java
+++ b/src/main/java/electrosphere/renderer/anim/Animation.java
@@ -28,6 +28,8 @@ public class Animation {
public static final String ANIMATION_SPRINT_STARTUP = "Armature|RunStart";
public static final String ANIMATION_SPRINT = "Armature|Run";
public static final String ANIMATION_SPRINT_WINDDOWN = "Armature|RunStart";
+ public static final String ANIMATION_WALK_RIGHT = "Armature|JogRight";
+ public static final String ANIMATION_WALK_LEFT = "Armature|JogLeft";
@@ -69,7 +71,7 @@ public class Animation {
//Read in anim channels (bone modifications)
//
int channelCount = animData.mNumChannels();
- channels = new ArrayList();
+ channels = new ArrayList();
if(channelCount > 0){
// System.out.println("Channel count: " + channelCount);
for(int i = 0; i < channelCount; i++){