Environment updates, work on rotator system

This commit is contained in:
austin 2022-02-06 00:00:44 -05:00
parent 5b7980f545
commit a5031f20f6
28 changed files with 744 additions and 110 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

4
.vscode/tasks.json vendored
View File

@ -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": {

View File

@ -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"
},

BIN
assets/Models/baseman.fbx Normal file

Binary file not shown.

49
pom.xml
View File

@ -43,12 +43,12 @@
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-openal</artifactId>
<version>${lwjgl.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
<version>${lwjgl.version}</version>
</dependency>
</dependency>
<!-- generic LWJGL runtimes -->
<dependency>
<groupId>org.lwjgl</groupId>
@ -96,27 +96,27 @@
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
<scope>runtime</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-stb</artifactId>
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
<scope>runtime</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!--
manual: http://www.cs.kent.edu/~ruttan/GameEngines/lectures/Bullet_User_Manual
because their docs ( http://jbullet.advel.cz/javadoc/com/bulletphysics/collision/shapes/CylinderShape.html ) suck
@ -127,7 +127,7 @@
<artifactId>jBulletFork</artifactId>
<version>0.1</version>
</dependency>
<!--
Potential alternative binding for bullet ?
<dependency>
@ -136,14 +136,14 @@
<version>1.10.0</version>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-crypto -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-crypto</artifactId>
<version>1.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
@ -151,9 +151,9 @@
<version>3.36.0.3</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>lwjgl-natives-linux</id>
@ -242,6 +242,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>electrosphere.main.Main</mainClass>
<!-- <classpathScope>compile</classpathScope> -->
<arguments>
<argument>-cp</argument>
<argument>target/classes;target/Renderer-0.1-jar-with-dependencies.jar</argument>
<argument>electrosphere.main.Main</argument>
</arguments>
<!-- <classesDirectory>${project.basedir}/target/classes</classesDirectory> -->
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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;
}
}

View File

@ -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<String, Control> controls;
ControlHandler(){
controls = new HashMap();
controls = new HashMap<String, Control>();
}
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){

View File

@ -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";

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,35 @@
package electrosphere.entity.state.rotator;
import java.util.List;
public class RotatorHierarchyNode {
String bone;
List<RotatorConstraint> rotatorConstraints;
List<RotatorHierarchyNode> children;
public String getBone(){
return bone;
}
public List<RotatorConstraint> getRotatorContraints(){
return rotatorConstraints;
}
public List<RotatorHierarchyNode> 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;
}
}

View File

@ -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<RotatorHierarchyNode> 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));
}
}

View File

@ -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();
}
}

View File

@ -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){

View File

@ -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<HitboxData> hitboxes;
List<String> tokens;
List<MovementSystem> movementSystems;
RotatorSystem rotatorSystem;
CollidableTemplate collidable;
List<AttackMove> attackMoves;
HealthSystem healthSystem;
@ -55,7 +58,9 @@ public class CreatureType {
return lookAtSystem;
}
public RotatorSystem getRotatorSystem() {
return rotatorSystem;
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,16 @@
package electrosphere.game.data.creature.type.rotator;
import java.util.List;
public class RotatorItem {
String boneName;
List<RotatorConstraint> constraints;
public String getBoneName(){
return boneName;
}
public List<RotatorConstraint> getConstraints(){
return constraints;
}
}

View File

@ -0,0 +1,11 @@
package electrosphere.game.data.creature.type.rotator;
import java.util.List;
public class RotatorSystem {
List<RotatorItem> rotatorItems;
public List<RotatorItem> getRotatorItems() {
return rotatorItems;
}
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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;
//

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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<AnimChannel>();
if(channelCount > 0){
// System.out.println("Channel count: " + channelCount);
for(int i = 0; i < channelCount; i++){