Hitboxes!

This commit is contained in:
austin 2021-06-06 01:59:51 -04:00
parent a3269b962d
commit 7379afbbc7
24 changed files with 521 additions and 49 deletions

View File

@ -1,7 +1,7 @@
package electrosphere.controls;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.state.MovementTree.MovementTreeState;

View File

@ -68,5 +68,17 @@ public class EntityDataStrings {
public static final String DATA_STRING_UI_ELEMENT = "uiEntity";
public static final String DATA_STRING_UI_ELEMENT_FONT = "uiFont";
/*
Collision Entity
*/
public static final String DATA_STRING_COLLISION_ENTITY = "collisionEntity";
public static final String DATA_STRING_COLLISION_ENTITY_TYPE_SPHERE = "collisionSphere";
public static final String COLLISION_ENTITY_DATA_TYPE = "collisionDataType";
public static final String COLLISION_ENTITY_DATA_PARENT = "collisionDataParent";
public static final String COLLISION_ENTITY_DATA_BONE = "collisionDataBone";
}

View File

@ -0,0 +1,90 @@
package electrosphere.entity.collision;
import electrosphere.entity.Entity;
import electrosphere.game.world.World;
import java.util.ArrayList;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class CollisionEngine {
List<Entity> collisionEntities = new ArrayList();
public CollisionEngine(){
}
/**
*
* @param e the entity that wants to move
* @param positionToCheck the position that it wants to move to
* @return true if it can occupy that position, false otherwise
*/
public boolean checkCanOccupyPosition(World w, Entity e, Vector3f positionToCheck){
boolean rVal = true;
//
// are we below the terrain?
//
if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
return false;
}
//
// check world bounds
//
if(
positionToCheck.x < w.getWorldBoundMin().x ||
positionToCheck.z < w.getWorldBoundMin().z ||
positionToCheck.x > w.getWorldBoundMax().x ||
positionToCheck.z > w.getWorldBoundMax().z
){
return false;
}
return rVal;
}
/**
*
* @param e the entity that's trying to move
* @param positionToCheck the position the entity wants to be at
* @return the position the engine recommends it move to instead (this is
* guaranteed to be a valid position)
*/
public Vector3f suggestMovementPosition(World w, Entity e, Vector3f positionToCheck){
Vector3f suggestedPosition = new Vector3f(positionToCheck);
//
// adjust for minimum height (Terrain)
//
float heightMapBias = 0.00001f;
if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
suggestedPosition.y = w.getElevationAtPoint(positionToCheck) + heightMapBias;
}
//
// adjust for world bounds
//
if(suggestedPosition.x < w.getWorldBoundMin().x){
suggestedPosition.x = w.getWorldBoundMin().x;
}
if(suggestedPosition.z < w.getWorldBoundMin().z){
suggestedPosition.z = w.getWorldBoundMin().z;
}
if(suggestedPosition.x > w.getWorldBoundMax().x){
suggestedPosition.x = w.getWorldBoundMax().x;
}
if(suggestedPosition.z > w.getWorldBoundMax().z){
suggestedPosition.z = w.getWorldBoundMax().z;
}
return suggestedPosition;
}
public List<Entity> getCollisionEntities(){
return collisionEntities;
}
}

View File

@ -1,6 +1,6 @@
package electrosphere.entity.state;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;
@ -80,6 +80,7 @@ public class MovementTree {
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3f position = EntityUtils.getEntityPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
Vector3f newPosition;
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
@ -113,8 +114,11 @@ public class MovementTree {
state = MovementTreeState.MOVE;
}
//move the entity
position.add(new Vector3f(movementVector).mul(velocity));
position.y = Globals.drawCellManager.getElevationAtRealPoint(position.x, position.z);
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.world, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.world, parent, newPosition);
}
EntityUtils.getEntityPosition(parent).set(newPosition);
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
break;
case MOVE:
@ -128,8 +132,11 @@ public class MovementTree {
}
//check if can move forward (collision engine)
//if can, move forward by entity movement stats
position.add(new Vector3f(movementVector).mul(velocity));
position.y = Globals.drawCellManager.getElevationAtRealPoint(position.x, position.z);
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.world, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.world, parent, newPosition);
}
EntityUtils.getEntityPosition(parent).set(newPosition);
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
break;
case SLOWDOWN:
@ -148,8 +155,11 @@ public class MovementTree {
state = MovementTreeState.IDLE;
}
//move the entity
position.add(new Vector3f(movementVector).mul(velocity));
position.y = Globals.drawCellManager.getElevationAtRealPoint(position.x, position.z);
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.world, parent, newPosition)){
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.world, parent, newPosition);
}
EntityUtils.getEntityPosition(parent).set(newPosition);
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
break;
case IDLE:

View File

@ -1,6 +1,12 @@
package electrosphere.entity;
package electrosphere.entity.types.creature;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.creature.creaturemap.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.message.EntityMessage;
@ -35,7 +41,11 @@ public class CreatureUtils {
// }
public static Entity spawnBasicCreature(int creatureId, float acceleration, float maxVelocity){
Entity rVal = EntityUtils.spawnDrawableEntity(Globals.entityTypeMap.get(creatureId).getModelPath());
CreatureType rawType = Globals.entityTypeMap.get(creatureId);
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
for(HitboxData hitboxdata : rawType.getHitboxes()){
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone()));
}
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, creatureId);
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));

View File

@ -1,4 +1,6 @@
package electrosphere.entity.types.creature;
package electrosphere.entity.types.creature.creaturemap;
import java.util.List;
/**
*
@ -7,6 +9,7 @@ package electrosphere.entity.types.creature;
public class CreatureType {
int id;
String modelPath;
List<HitboxData> hitboxes;
public int getId() {
return id;
@ -23,5 +26,15 @@ public class CreatureType {
public void setModelPath(String modelPath) {
this.modelPath = modelPath;
}
public List<HitboxData> getHitboxes() {
return hitboxes;
}
public void setHitboxes(List<HitboxData> hitboxes) {
this.hitboxes = hitboxes;
}
}

View File

@ -1,4 +1,4 @@
package electrosphere.entity.types.creature;
package electrosphere.entity.types.creature.creaturemap;
import java.util.List;

View File

@ -0,0 +1,20 @@
package electrosphere.entity.types.creature.creaturemap;
/**
*
* @author amaterasu
*/
public class HitboxData {
String type;
String bone;
public String getType() {
return type;
}
public String getBone() {
return bone;
}
}

View File

@ -0,0 +1,26 @@
package electrosphere.entity.types.hitbox;
import electrosphere.entity.Entity;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author amaterasu
*/
public class HitboxManager {
List<Entity> hitboxes = new ArrayList();
public HitboxManager(){
}
public void registerHitbox(Entity hitbox){
hitboxes.add(hitbox);
}
public List<Entity> getAllHitboxes(){
return hitboxes;
}
}

View File

@ -0,0 +1,60 @@
package electrosphere.entity.types.hitbox;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.joml.Vector4f;
/**
*
* @author amaterasu
*/
public class HitboxUtils {
public static Entity spawnRegularHitbox(Entity parent, String bone){
Entity rVal = new Entity();
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE, bone);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
return rVal;
}
public static void updatePosition(Entity hitbox){
Entity parent = ((Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT));
String boneName = ((String)(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_BONE)));
Quaternionf parentRotation = ((Quaternionf)EntityUtils.getEntityRotation(parent));
Vector3f positionScale = ((Vector3f)EntityUtils.getEntityScale(parent));
Vector3f worldPosition = new Vector3f();
Vector3f bonePosition = EntityUtils.getEntityActor(parent).getBonePosition(boneName);
worldPosition.set(bonePosition.x,bonePosition.y,bonePosition.z);
Quaternionf rotation = new Quaternionf(parentRotation);
// rotation.w = -rotation.w;
// rotation.x = -rotation.x;
// rotation.y = -rotation.y;
// rotation.z = -rotation.z;
// System.out.println(bonePosition);
worldPosition = worldPosition.mul(positionScale);
worldPosition = worldPosition.rotate(rotation);
// Matrix4f rotationMatrix = new Matrix4f().rotate(parentRotation);
// Vector4f rawRotatedOffset = rotationMatrix.transform(new Vector4f(worldPosition.x,worldPosition.y,worldPosition.z,1));
// worldPosition = new Vector3f(rawRotatedOffset.x,rawRotatedOffset.y,rawRotatedOffset.z);
worldPosition.add(EntityUtils.getEntityPosition(parent));
// System.out.println(worldPosition);
//
// System.out.println("parent rotation: " + new Vector3f(0,0,1).rotate(rotation));
((Vector3f)hitbox.getData(EntityDataStrings.DATA_STRING_POSITION)).set(worldPosition);
}
}

View File

@ -4,9 +4,12 @@ import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.collision.CollisionEngine;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.cell.DrawCellManager;
import electrosphere.game.state.SimulationState.SimulationStateMachine;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.game.world.World;
import electrosphere.main.Globals;
import static electrosphere.main.Globals.loadingBox;
import electrosphere.menu.MenuUtils;
@ -16,6 +19,7 @@ import electrosphere.net.server.Server;
import electrosphere.renderer.Model;
import electrosphere.renderer.RenderUtils;
import electrosphere.renderer.assetmanager.AssetDataStrings;
import java.util.Random;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@ -82,6 +86,9 @@ public class LoadingThread extends Thread {
//initialize the terrain manager (server only)
initTerrainManager();
//init the data of the world
initGameWorld();
//initialize the server thread (server only)
if(FLAG_INIT_SERVER){
initServerThread();
@ -95,6 +102,9 @@ public class LoadingThread extends Thread {
//initialize the cell manager (client)
initDynamicCellManager();
//collision engine
initCollisionEngine();
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
@ -123,7 +133,8 @@ public class LoadingThread extends Thread {
case LOAD_ARENA:
loadingBox.setDraw(true);
Globals.spawnPoint = new Vector3f(1,0,1);
//init the data of the world
initArenaWorld();
//initialize the server thread (server only)
if(FLAG_INIT_SERVER){
@ -138,9 +149,14 @@ public class LoadingThread extends Thread {
//initialize the cell manager (client)
initArenaCellManager();
//collision engine
initCollisionEngine();
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
creatingRandomEntities();
loadingBox.setDraw(false);
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
@ -223,6 +239,19 @@ public class LoadingThread extends Thread {
}
static void initArenaWorld(){
Globals.world = World.createArenaWorld();
Globals.spawnPoint = new Vector3f(0,0,0);
}
static void initGameWorld(){
Globals.world = World.createGameWorld(Globals.terrainManager);
}
static void initCollisionEngine(){
Globals.collisionEngine = new CollisionEngine();
}
static void initServerThread(){
@ -313,6 +342,45 @@ public class LoadingThread extends Thread {
}
static void creatingRandomEntities(){
// String unitCubeModelPath = Globals.assetManager.registerModel(ModelUtils.createUnitCube());
// Entity unitCube = EntityUtils.spawnDrawableEntity(unitCubeModelPath);
// EntityUtils.getEntityPosition(unitCube).set(10,2,10);
// String goundPlaneModelPath = "Models/groundplanemassiveuv.fbx";
// Entity groundPlane = EntityUtils.spawnDrawableEntity(goundPlaneModelPath);
// EntityUtils.getEntityPosition(groundPlane).set(10f,2f,10f);
// EntityUtils.getEntityRotation(groundPlane).rotateAxis((float)Math.PI/2, new Vector3f(1,0,0));
// EntityUtils.getEntityScale(groundPlane).set(5);
// String unitsphereModelPath = "Models/unitsphere.fbx";
// Entity unitsphere = EntityUtils.spawnDrawableEntity(unitsphereModelPath);
// EntityUtils.getEntityPosition(unitsphere).set(10f,2f,10f);
// EntityUtils.getEntityScale(unitsphere).set(1);
// String smallCubePath = "Models/SmallCube.fbx";
// Entity originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
// EntityUtils.getEntityPosition(originCube).set(0, 0, 0);
//
// originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
// EntityUtils.getEntityPosition(originCube).set(1, 0, 0);
//
// originCube = EntityUtils.spawnDrawableEntity(smallCubePath);
// EntityUtils.getEntityPosition(originCube).set(0, 0, 1);
// Entity font = FontUtils.makeFont(7, 1);
// EntityUtils.getEntityPosition(font).set(new Vector3f(0.2f,0.2f,0.0f));
// for(int i = 0; i < 10; i++){
// Random rand = new Random();
// Entity creature = CreatureUtils.spawnBasicCreature(0, 0.01f, 0.01f);
// EntityUtils.getEntityPosition(creature).set(rand.nextFloat() * 10, rand.nextFloat() * 10, rand.nextFloat() * 10);
// EntityUtils.getEntityScale(creature).set(0.01f);
// }
}
public void setFLAG_INIT_SERVER(boolean FLAG_INIT_SERVER) {
this.FLAG_INIT_SERVER = FLAG_INIT_SERVER;

View File

@ -0,0 +1,89 @@
package electrosphere.game.world;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.game.world.datacell.DataCell;
import java.util.List;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class World {
public static enum WorldType {
GAME_WORLD,
ARENA_WORLD,
}
WorldType type;
List<DataCell> cellsLoadedIntoMemory;
TerrainManager terrainManager;
/*
world max
+---------------------+
| |
| |
| |
| |
| |
+---------------------+
world min
basically we're saying what the maximum and minimum x and z something can occupy are
FOR THE TIME BEING DOES NOT ACCOUNT FOR Y
*/
Vector3f worldMinPoint;
Vector3f worldMaxPoint;
public static World createArenaWorld(){
World rVal = new World();
rVal.type = WorldType.ARENA_WORLD;
rVal.worldMinPoint = new Vector3f(0,0,0);
rVal.worldMaxPoint = new Vector3f(200,0,200);
return rVal;
}
public static World createGameWorld(TerrainManager terrainManager){
World rVal = new World();
rVal.type = WorldType.GAME_WORLD;
rVal.terrainManager = terrainManager;
rVal.worldMinPoint = new Vector3f(0,0,0);
int worldDim = rVal.terrainManager.getWorldDiscreteSize();
rVal.worldMaxPoint = new Vector3f(worldDim,0,worldDim);
return rVal;
}
public float getElevationAtPoint(Vector3f point){
float rVal = 0.0f;
switch(type){
case GAME_WORLD:
rVal = terrainManager.getHeightAtPosition(point.x, point.z);
break;
case ARENA_WORLD:
break;
}
return rVal;
}
public Vector3f getWorldBoundMin(){
return worldMinPoint;
}
public Vector3f getWorldBoundMax(){
return worldMaxPoint;
}
public TerrainManager getTerrainManager(){
return terrainManager;
}
}

View File

@ -0,0 +1,9 @@
package electrosphere.game.world.datacell;
/**
*
* @author amaterasu
*/
public class DataCell {
}

View File

@ -13,11 +13,14 @@ import electrosphere.cfg.MainConfig;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
import electrosphere.entity.types.creature.CreatureType;
import electrosphere.entity.types.creature.CreatureTypeList;
import electrosphere.entity.collision.CollisionEngine;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.creature.creaturemap.CreatureTypeList;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.cell.DrawCellManager;
import electrosphere.game.state.LoadingThread;
import electrosphere.game.terrain.TerrainManager;
import electrosphere.game.world.World;
import electrosphere.menu.Menu;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
@ -75,6 +78,18 @@ public class Globals {
public static ControlHandler controlHandler;
//
// Collision engine
//
public static CollisionEngine collisionEngine;
//
//current world
//
public static World world;
//
//Entity Types Map
//
@ -148,6 +163,9 @@ public class Globals {
public static AssetManager assetManager;
//manages hitboxes
public static HitboxManager hitboxManager;
//chunk stuff
//constant for how far in game units you have to move to load chunks
public static DrawCellManager drawCellManager;
@ -205,6 +223,8 @@ public class Globals {
assetManager = new AssetManager();
//load widget manager
widgetManager = new WidgetManager();
//hitbox manager
hitboxManager = new HitboxManager();
}
public static void initDefaultGraphicalResources(){
@ -226,7 +246,12 @@ public class Globals {
loadingBox = WidgetUtils.createVerticallyAlignedTextBox(520, 100, 50, 7, 1, "LOADING", true);
//init default shaderProgram
defaultMeshShader = ShaderProgram.smart_assemble_shader(false,true);
//init skybox
assetManager.registerModelToSpecificString(RenderUtils.createSkyboxModel(null), AssetDataStrings.ASSET_STRING_SKYBOX_BASIC);
//init hitbox
assetManager.addModelPathToQueue("Models/unitsphere.fbx");
//init smallcube
assetManager.addModelPathToQueue("Models/SmallCube.fbx");
}
static void initEntityTypeMap(){

View File

@ -4,7 +4,7 @@ import com.google.gson.Gson;
import electrosphere.cfg.MainConfig;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.renderer.Camera;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
@ -12,8 +12,10 @@ import electrosphere.renderer.RenderUtils;
import electrosphere.renderer.ShaderProgram;
import electrosphere.renderer.texture.Texture;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.cell.DrawCellManager;
import electrosphere.game.state.LoadingThread;
import electrosphere.game.state.SimulationState;
@ -213,6 +215,9 @@ public class Main {
MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
behaviorTree.simulate();
}
for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){
HitboxUtils.updatePosition(currentHitbox);
}
}
@ -317,30 +322,5 @@ public class Main {
}
static void creatingRandomEntities(){
// String unitCubeModelPath = Globals.assetManager.registerModel(ModelUtils.createUnitCube());
// Entity unitCube = EntityUtils.spawnDrawableEntity(unitCubeModelPath);
// EntityUtils.getEntityPosition(unitCube).set(10,2,10);
// String goundPlaneModelPath = "Models/groundplanemassiveuv.fbx";
// Entity groundPlane = EntityUtils.spawnDrawableEntity(goundPlaneModelPath);
// EntityUtils.getEntityPosition(groundPlane).set(10f,2f,10f);
// EntityUtils.getEntityRotation(groundPlane).rotateAxis((float)Math.PI/2, new Vector3f(1,0,0));
// EntityUtils.getEntityScale(groundPlane).set(5);
String unitsphereModelPath = "Models/unitsphere.fbx";
Entity unitsphere = EntityUtils.spawnDrawableEntity(unitsphereModelPath);
EntityUtils.getEntityPosition(unitsphere).set(10f,2f,10f);
EntityUtils.getEntityScale(unitsphere).set(1);
// Entity font = FontUtils.makeFont(7, 1);
// EntityUtils.getEntityPosition(font).set(new Vector3f(0.2f,0.2f,0.0f));
for(int i = 0; i < 10; i++){
Random rand = new Random();
Entity creature = CreatureUtils.spawnBasicCreature(0, 0.01f, 0.01f);
EntityUtils.getEntityPosition(creature).set(rand.nextFloat() * 10, rand.nextFloat() * 10, rand.nextFloat() * 10);
EntityUtils.getEntityScale(creature).set(0.01f);
}
}
}

View File

@ -1,6 +1,6 @@
package electrosphere.net;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.net.message.EntityMessage;

View File

@ -1,6 +1,6 @@
package electrosphere.net.client;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;

View File

@ -1,6 +1,6 @@
package electrosphere.net.server;
import electrosphere.entity.CreatureUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;
@ -85,7 +85,7 @@ public class ServerConnectionHandler implements Runnable {
System.exit(1);
}
//spawn player in world
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.55f);
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f);
EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,Globals.drawCellManager.getElevationAtRealPoint(Globals.spawnPoint.x, Globals.spawnPoint.z),Globals.spawnPoint.z);
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);

View File

@ -3,6 +3,8 @@
import electrosphere.main.Globals;
import electrosphere.renderer.anim.Animation;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Vector4f;
/**
*
@ -101,4 +103,28 @@ public class Actor {
return modelPath;
}
public Vector3f getBonePosition(String boneName){
Vector3f rVal = new Vector3f();
Model model = Globals.assetManager.fetchModel(modelPath);
if(model != null){
if(animation != null){
model.playAnimation(animation);
model.incrementTime(0.001);
model.incrementTime(animationTime);
if(model.currentAnimation == null){
playingAnimation = false;
}
Bone currentBone = model.boneMap.get(boneName);
if(currentBone != null){
Vector4f result = currentBone.final_transform.transform(new Matrix4f(currentBone.inverseBindPoseMatrix).invert().transform(new Vector4f(rVal.x,rVal.y,rVal.z,1)));
// currentBone.inverseBindPoseMatrix
rVal.x = result.x;
rVal.y = result.y;
rVal.z = result.z;
}
}
}
return rVal;
}
}

View File

@ -0,0 +1,9 @@
package electrosphere.renderer.Light;
/**
*
* @author amaterasu
*/
public class LightManager {
}

View File

@ -361,4 +361,10 @@ public class Model {
}
}
}
public void listAllBoneIDs(){
for(String id : boneMap.keySet()){
System.out.println(id);
}
}
}

View File

@ -23,6 +23,7 @@ import electrosphere.renderer.framebuffer.Renderbuffer;
import electrosphere.renderer.ui.Widget;
import electrosphere.util.Utilities;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.lwjgl.BufferUtils;
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
@ -612,7 +613,7 @@ public class RenderUtils {
//draw
currentActor.drawForDepthBuffer();
}
//bind default framebuffer
@ -677,6 +678,18 @@ public class RenderUtils {
// }
}
for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){
Model hitboxModel;
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
Vector3f position = EntityUtils.getEntityPosition(currentHitbox);
modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)).sub(new Vector3f(0,1,0)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(0.1f);
hitboxModel.modelMatrix = modelTransformMatrix;
hitboxModel.draw();
}
}

View File

@ -2,11 +2,17 @@
"types": [
{
"id" : 0,
"modelPath" : "Models/person1walkanim.fbx"
"modelPath" : "Models/person1walkanim.fbx",
"hitboxes" : [
{
"bone": "Bone.031"
}
]
},
{
"id" : 1,
"modelPath" : ""
"modelPath" : "",
"hitboxes" : []
}
]
}

Binary file not shown.