Convert entity position to double from float
This commit is contained in:
parent
e39af4a78c
commit
236eb59274
@ -346,7 +346,7 @@ public class LoadingThread extends Thread {
|
|||||||
Vector2i townLoc = Town.findValidTownLocation();
|
Vector2i townLoc = Town.findValidTownLocation();
|
||||||
if(townLoc != null){
|
if(townLoc != null){
|
||||||
int chunkSize = Globals.serverTerrainManager.getChunkWidth();
|
int chunkSize = Globals.serverTerrainManager.getChunkWidth();
|
||||||
Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
|
Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, (float)Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
|
||||||
// System.out.println("Setting spawn point @ " + Globals.spawnPoint);
|
// System.out.println("Setting spawn point @ " + Globals.spawnPoint);
|
||||||
Town.createTown(townLoc.x,townLoc.y);
|
Town.createTown(townLoc.x,townLoc.y);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,8 @@ public class CameraEntityUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_BASIC);
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_BASIC);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center);
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center);
|
||||||
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye);
|
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye);
|
||||||
|
rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f);
|
||||||
|
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +29,8 @@ public class CameraEntityUtils {
|
|||||||
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center);
|
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center);
|
||||||
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye);
|
rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye);
|
||||||
|
rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f);
|
||||||
|
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +58,22 @@ public class CameraEntityUtils {
|
|||||||
return (Vector3f)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_EYE);
|
return (Vector3f)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_EYE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setCameraPitch(Entity camera, float pitch){
|
||||||
|
camera.putData(EntityDataStrings.CAMERA_PITCH, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getCameraPitch(Entity camera){
|
||||||
|
return (float)camera.getData(EntityDataStrings.CAMERA_PITCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCameraYaw(Entity camera, float yaw){
|
||||||
|
camera.putData(EntityDataStrings.CAMERA_YAW, yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getCameraYaw(Entity camera){
|
||||||
|
return (float)camera.getData(EntityDataStrings.CAMERA_YAW);
|
||||||
|
}
|
||||||
|
|
||||||
public static void destroyCameraEntity(Entity e){
|
public static void destroyCameraEntity(Entity e){
|
||||||
if(e != null){
|
if(e != null){
|
||||||
Globals.entityManager.deregisterEntity(e);
|
Globals.entityManager.deregisterEntity(e);
|
||||||
|
|||||||
@ -45,6 +45,8 @@ public class EntityDataStrings {
|
|||||||
public static final String DATA_STRING_CAMERA_TYPE_ORBIT = "cameraTypeOrbit";
|
public static final String DATA_STRING_CAMERA_TYPE_ORBIT = "cameraTypeOrbit";
|
||||||
public static final String DATA_STRING_CAMERA_EYE = "cameraEye";
|
public static final String DATA_STRING_CAMERA_EYE = "cameraEye";
|
||||||
public static final String DATA_STRING_CAMERA_CENTER = "cameraCenter";
|
public static final String DATA_STRING_CAMERA_CENTER = "cameraCenter";
|
||||||
|
public static final String CAMERA_PITCH = "cameraPitch";
|
||||||
|
public static final String CAMERA_YAW = "cameraYaw";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,7 +210,7 @@ public class EntityManager {
|
|||||||
|
|
||||||
public void clearOutOfBoundsEntities(){
|
public void clearOutOfBoundsEntities(){
|
||||||
if(Globals.commonWorldData != null && Globals.playerCharacter != null && Globals.clientPlayerData != null){
|
if(Globals.commonWorldData != null && Globals.playerCharacter != null && Globals.clientPlayerData != null){
|
||||||
Vector3f playerCharacterPos = EntityUtils.getPosition(Globals.playerCharacter);
|
Vector3d playerCharacterPos = EntityUtils.getPosition(Globals.playerCharacter);
|
||||||
int playerCharacterWorldX = Globals.commonWorldData.convertRealToWorld(playerCharacterPos.x);
|
int playerCharacterWorldX = Globals.commonWorldData.convertRealToWorld(playerCharacterPos.x);
|
||||||
int playerCharacterWorldY = Globals.commonWorldData.convertRealToWorld(playerCharacterPos.z);
|
int playerCharacterWorldY = Globals.commonWorldData.convertRealToWorld(playerCharacterPos.z);
|
||||||
if(playerCharacterWorldX != Globals.clientPlayerData.getWorldPositionX() || playerCharacterWorldY != Globals.clientPlayerData.getWorldPositionY()){
|
if(playerCharacterWorldX != Globals.clientPlayerData.getWorldPositionX() || playerCharacterWorldY != Globals.clientPlayerData.getWorldPositionY()){
|
||||||
@ -217,7 +218,7 @@ public class EntityManager {
|
|||||||
if(entity.getDataKeys().contains(EntityDataStrings.TERRAIN_IS_TERRAIN) || entity.getDataKeys().contains(EntityDataStrings.ATTACH_PARENT) || entity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_PARENT)){
|
if(entity.getDataKeys().contains(EntityDataStrings.TERRAIN_IS_TERRAIN) || entity.getDataKeys().contains(EntityDataStrings.ATTACH_PARENT) || entity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_PARENT)){
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Vector3f position = EntityUtils.getPosition(entity);
|
Vector3d position = EntityUtils.getPosition(entity);
|
||||||
//common world data is initialized with the collision data
|
//common world data is initialized with the collision data
|
||||||
//if this is null then the engine hasn't fully started up yet
|
//if this is null then the engine hasn't fully started up yet
|
||||||
if(position != null){
|
if(position != null){
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import electrosphere.main.Globals;
|
|||||||
import electrosphere.renderer.Actor;
|
import electrosphere.renderer.Actor;
|
||||||
import electrosphere.renderer.ActorUtils;
|
import electrosphere.renderer.ActorUtils;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,8 +22,8 @@ import org.joml.Vector3f;
|
|||||||
*/
|
*/
|
||||||
public class EntityUtils {
|
public class EntityUtils {
|
||||||
|
|
||||||
public static Vector3f getPosition(Entity e){
|
public static Vector3d getPosition(Entity e){
|
||||||
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_POSITION);
|
return (Vector3d)e.getData(EntityDataStrings.DATA_STRING_POSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Quaternionf getRotation(Entity e){
|
public static Quaternionf getRotation(Entity e){
|
||||||
@ -41,7 +42,7 @@ public class EntityUtils {
|
|||||||
Entity rVal = new Entity();
|
Entity rVal = new Entity();
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
||||||
// rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath);
|
// rVal.putData(EntityDataStrings.DATA_STRING_MODEL_PATH, modelPath);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity());
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity());
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
@ -53,7 +54,7 @@ public class EntityUtils {
|
|||||||
public static Entity spawnDrawableEntityWithPreexistingModel(String modelPath){
|
public static Entity spawnDrawableEntityWithPreexistingModel(String modelPath){
|
||||||
Entity rVal = new Entity();
|
Entity rVal = new Entity();
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
|
||||||
@ -65,7 +66,7 @@ public class EntityUtils {
|
|||||||
public static Entity spawnUIEntity(String modelPath){
|
public static Entity spawnUIEntity(String modelPath){
|
||||||
Entity rVal = new Entity();
|
Entity rVal = new Entity();
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
rVal.putData(EntityDataStrings.DATA_STRING_ACTOR, ActorUtils.createActorFromModelPath(modelPath));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().rotateAxis((float)0, new Vector3f(1,0,0)));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_UI_ELEMENT, true);
|
rVal.putData(EntityDataStrings.DATA_STRING_UI_ELEMENT, true);
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import electrosphere.renderer.Actor;
|
|||||||
import electrosphere.renderer.anim.Animation;
|
import electrosphere.renderer.anim.Animation;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public class AttackTree {
|
public class AttackTree {
|
||||||
@ -76,7 +77,7 @@ public class AttackTree {
|
|||||||
public void simulate(){
|
public void simulate(){
|
||||||
float velocity = CreatureUtils.getVelocity(parent);
|
float velocity = CreatureUtils.getVelocity(parent);
|
||||||
Actor entityActor = EntityUtils.getActor(parent);
|
Actor entityActor = EntityUtils.getActor(parent);
|
||||||
Vector3f position = EntityUtils.getPosition(parent);
|
Vector3d position = EntityUtils.getPosition(parent);
|
||||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
|
|
||||||
//parse attached network messages
|
//parse attached network messages
|
||||||
@ -135,9 +136,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -150,9 +151,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -184,9 +185,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -199,9 +200,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -234,9 +235,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -249,9 +250,9 @@ public class AttackTree {
|
|||||||
EntityMessage.constructattackUpdateMessage(
|
EntityMessage.constructattackUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
position.x,
|
(float)position.x,
|
||||||
position.y,
|
(float)position.y,
|
||||||
position.z,
|
(float)position.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import electrosphere.net.parser.net.message.EntityMessage;
|
|||||||
import electrosphere.renderer.Actor;
|
import electrosphere.renderer.Actor;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +75,7 @@ public class GravityTree {
|
|||||||
float acceleration = CreatureUtils.getAcceleration(parent);
|
float acceleration = CreatureUtils.getAcceleration(parent);
|
||||||
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
||||||
Actor entityActor = EntityUtils.getActor(parent);
|
Actor entityActor = EntityUtils.getActor(parent);
|
||||||
Vector3f position = EntityUtils.getPosition(parent);
|
Vector3d position = EntityUtils.getPosition(parent);
|
||||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
Vector3f newPosition;
|
Vector3f newPosition;
|
||||||
@ -108,19 +109,19 @@ public class GravityTree {
|
|||||||
if(hadGroundCollision()){
|
if(hadGroundCollision()){
|
||||||
state = GravityTreeState.NOT_ACTIVE;
|
state = GravityTreeState.NOT_ACTIVE;
|
||||||
if(!hadStructureCollision()){
|
if(!hadStructureCollision()){
|
||||||
position.set(new Vector3f(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z));
|
position.set(new Vector3d(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
float gravityDif = gravityConstant * (float)Math.pow(1.0f - linearDamping,deltaTime * 2);
|
||||||
Vector3f newGravityPos = new Vector3f(position.x,position.y - gravityDif,position.z);
|
Vector3d newGravityPos = new Vector3d(position.x,position.y - gravityDif,position.z);
|
||||||
float hitFraction = Globals.collisionEngine.sweepTest(body, position, newGravityPos);
|
float hitFraction = Globals.collisionEngine.sweepTest(body, new Vector3f((float)position.x,(float)position.y,(float)position.z), new Vector3f((float)newGravityPos.x,(float)newGravityPos.y,(float)newGravityPos.z));
|
||||||
if(hitFraction >= 0){
|
if(hitFraction >= 0){
|
||||||
position.set(new Vector3f(position.x,position.y - gravityDif * hitFraction,position.z));
|
position.set(new Vector3d(position.x,position.y - gravityDif * hitFraction,position.z));
|
||||||
} else {
|
} else {
|
||||||
position.set(new Vector3f(position.x,position.y - gravityDif,position.z));
|
position.set(new Vector3d(position.x,position.y - gravityDif,position.z));
|
||||||
}
|
}
|
||||||
// System.out.println(hitFraction);
|
// System.out.println(hitFraction);
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package electrosphere.entity.state;
|
|||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +48,7 @@ public class ParticleTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void simulate(){
|
public void simulate(){
|
||||||
Vector3f parentPosition = EntityUtils.getPosition(parent);
|
Vector3d parentPosition = EntityUtils.getPosition(parent);
|
||||||
parentPosition.add(new Vector3f(destination).mul(velocity));
|
parentPosition.add(new Vector3f(destination).mul(velocity));
|
||||||
velocity = velocity - acceleration;
|
velocity = velocity - acceleration;
|
||||||
if(velocity < 0){
|
if(velocity < 0){
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package electrosphere.entity.state.movement;
|
|||||||
|
|
||||||
import electrosphere.collision.dispatch.CollisionObject;
|
import electrosphere.collision.dispatch.CollisionObject;
|
||||||
import electrosphere.dynamics.RigidBody;
|
import electrosphere.dynamics.RigidBody;
|
||||||
|
import electrosphere.entity.CameraEntityUtils;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
@ -20,6 +21,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -81,11 +83,12 @@ public class MovementTree {
|
|||||||
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
||||||
Actor entityActor = EntityUtils.getActor(parent);
|
Actor entityActor = EntityUtils.getActor(parent);
|
||||||
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
|
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
|
||||||
Vector3f position = EntityUtils.getPosition(parent);
|
Vector3d position = EntityUtils.getPosition(parent);
|
||||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
|
float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
|
||||||
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
|
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
|
||||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
Vector3f newPosition;
|
Vector3d newPosition;
|
||||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||||
|
|
||||||
//parse attached network messages
|
//parse attached network messages
|
||||||
@ -151,7 +154,7 @@ public class MovementTree {
|
|||||||
// System.out.println("Impulse force: " + impulseForce);
|
// System.out.println("Impulse force: " + impulseForce);
|
||||||
position.add(impulseForce);
|
position.add(impulseForce);
|
||||||
}
|
}
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(position),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)position.x,(float)position.y,(float)position.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
//state machine
|
//state machine
|
||||||
@ -174,7 +177,7 @@ public class MovementTree {
|
|||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).set(movementQuaternion);
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//move the entity
|
//move the entity
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(0,0,1).rotate(movementQuaternion).mul(velocity));
|
newPosition = new Vector3d(position).add(new Vector3d(-Math.cos(movementYaw / 180.0f * Math.PI),0,-Math.sin(movementYaw / 180.0f * Math.PI)).mul(velocity));
|
||||||
//check/update if collision
|
//check/update if collision
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
@ -183,7 +186,7 @@ public class MovementTree {
|
|||||||
position.set(newPosition);
|
position.set(newPosition);
|
||||||
rotation.set(movementQuaternion);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
@ -207,9 +210,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -224,9 +227,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -249,14 +252,14 @@ public class MovementTree {
|
|||||||
EntityUtils.getRotation(parent).set(movementQuaternion);
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//check if can move forward (collision engine)
|
//check if can move forward (collision engine)
|
||||||
//if can, move forward by entity movement stats
|
//if can, move forward by entity movement stats
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(0,0,1).rotate(movementQuaternion).mul(velocity));
|
newPosition = new Vector3d(position).add(new Vector3d(-Math.cos(movementYaw / 180.0f * Math.PI),0,-Math.sin(movementYaw / 180.0f * Math.PI)).mul(velocity));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
}
|
||||||
position.set(newPosition);
|
position.set(newPosition);
|
||||||
rotation.set(movementQuaternion);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
@ -280,9 +283,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -297,9 +300,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -327,14 +330,14 @@ public class MovementTree {
|
|||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
//move the entity
|
//move the entity
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
|
newPosition = new Vector3d(position).add(new Vector3d(-Math.cos(movementYaw / 180.0f * Math.PI),0,-Math.sin(movementYaw / 180.0f * Math.PI)).mul(velocity));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
}
|
||||||
position.set(newPosition);
|
position.set(newPosition);
|
||||||
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(new Vector3f((float)newPosition.x,(float)newPosition.y,(float)newPosition.z)),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
|
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
@ -358,9 +361,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
@ -375,9 +378,9 @@ public class MovementTree {
|
|||||||
EntityMessage.constructmoveUpdateMessage(
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
parent.getId(),
|
parent.getId(),
|
||||||
System.currentTimeMillis(),
|
System.currentTimeMillis(),
|
||||||
newPosition.x,
|
(float)newPosition.x,
|
||||||
newPosition.y,
|
(float)newPosition.y,
|
||||||
newPosition.z,
|
(float)newPosition.z,
|
||||||
movementVector.x,
|
movementVector.x,
|
||||||
movementVector.y,
|
movementVector.y,
|
||||||
movementVector.z,
|
movementVector.z,
|
||||||
|
|||||||
@ -8,7 +8,9 @@ import electrosphere.main.Globals;
|
|||||||
import electrosphere.renderer.Actor;
|
import electrosphere.renderer.Actor;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,11 +42,12 @@ public class AttachUtils {
|
|||||||
if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){
|
if((targetBone = (String)currentEntity.getData(EntityDataStrings.ATTACH_TARGET_BONE))!=null){
|
||||||
Actor parentActor = EntityUtils.getActor(parent);
|
Actor parentActor = EntityUtils.getActor(parent);
|
||||||
//transform bone space
|
//transform bone space
|
||||||
Vector3f position = new Vector3f(parentActor.getBonePosition(targetBone));
|
Vector3d position = new Vector3d(parentActor.getBonePosition(targetBone));
|
||||||
position = position.mul(((Vector3f)EntityUtils.getScale(parent)));
|
position = position.mul(((Vector3f)EntityUtils.getScale(parent)));
|
||||||
position = position.rotate(((Quaternionf)EntityUtils.getRotation(parent)));
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
|
position = position.rotate(new Quaterniond(rotation.x,rotation.y,rotation.z,rotation.w));
|
||||||
//transform worldspace
|
//transform worldspace
|
||||||
position.add(new Vector3f(EntityUtils.getPosition(parent)));
|
position.add(new Vector3d(EntityUtils.getPosition(parent)));
|
||||||
//set
|
//set
|
||||||
EntityUtils.getPosition(currentEntity).set(position);
|
EntityUtils.getPosition(currentEntity).set(position);
|
||||||
//set rotation
|
//set rotation
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import electrosphere.game.collision.PhysicsUtils;
|
|||||||
import electrosphere.game.collision.collidable.Collidable;
|
import electrosphere.game.collision.collidable.Collidable;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +33,7 @@ public class CollisionObjUtils {
|
|||||||
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
||||||
|
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE, true);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE, true);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject);
|
||||||
@ -57,7 +58,7 @@ public class CollisionObjUtils {
|
|||||||
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
||||||
|
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE, true);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE, true);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
||||||
@ -81,7 +82,7 @@ public class CollisionObjUtils {
|
|||||||
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
||||||
|
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CYLINDER, true);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CYLINDER, true);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
||||||
|
|||||||
@ -30,6 +30,7 @@ import electrosphere.renderer.ActorUtils;
|
|||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import electrosphere.util.ModelLoader;
|
import electrosphere.util.ModelLoader;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,8 +144,8 @@ public class CreatureUtils {
|
|||||||
public static void sendEntityToPlayer(Player player, Entity creature){
|
public static void sendEntityToPlayer(Player player, Entity creature){
|
||||||
int id = creature.getId();
|
int id = creature.getId();
|
||||||
String type = CreatureUtils.getType(creature);
|
String type = CreatureUtils.getType(creature);
|
||||||
Vector3f position = EntityUtils.getPosition(creature);
|
Vector3d position = EntityUtils.getPosition(creature);
|
||||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, position.x, position.y, position.z);
|
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||||
player.addMessage(message);
|
player.addMessage(message);
|
||||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||||
LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import electrosphere.game.server.effects.ParticleEffects;
|
|||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector4f;
|
import org.joml.Vector4f;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class HitboxUtils {
|
|||||||
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT);
|
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
||||||
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
Globals.hitboxManager.registerHitbox(rVal);
|
Globals.hitboxManager.registerHitbox(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ public class HitboxUtils {
|
|||||||
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT);
|
data.setType(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT);
|
||||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
rVal.putData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT, parent);
|
||||||
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
rVal.putData(EntityDataStrings.HITBOX_DATA, data);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(0,0,0));
|
||||||
Globals.hitboxManager.registerHitbox(rVal);
|
Globals.hitboxManager.registerHitbox(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
@ -58,6 +59,7 @@ public class HitboxUtils {
|
|||||||
Vector3f positionScale = ((Vector3f)EntityUtils.getScale(parent));
|
Vector3f positionScale = ((Vector3f)EntityUtils.getScale(parent));
|
||||||
Vector3f worldPosition = new Vector3f();
|
Vector3f worldPosition = new Vector3f();
|
||||||
Vector3f bonePosition = EntityUtils.getActor(parent).getBonePosition(boneName);
|
Vector3f bonePosition = EntityUtils.getActor(parent).getBonePosition(boneName);
|
||||||
|
Vector3d parentPos = EntityUtils.getPosition(parent);
|
||||||
worldPosition.set(bonePosition.x,bonePosition.y,bonePosition.z);
|
worldPosition.set(bonePosition.x,bonePosition.y,bonePosition.z);
|
||||||
Quaternionf rotation = new Quaternionf(parentRotation);
|
Quaternionf rotation = new Quaternionf(parentRotation);
|
||||||
|
|
||||||
@ -66,9 +68,9 @@ public class HitboxUtils {
|
|||||||
worldPosition = worldPosition.rotate(rotation);
|
worldPosition = worldPosition.rotate(rotation);
|
||||||
|
|
||||||
|
|
||||||
worldPosition.add(EntityUtils.getPosition(parent));
|
worldPosition.add(new Vector3f((float)parentPos.x,(float)parentPos.y,(float)parentPos.z));
|
||||||
|
|
||||||
((Vector3f)hitbox.getData(EntityDataStrings.DATA_STRING_POSITION)).set(worldPosition);
|
((Vector3d)hitbox.getData(EntityDataStrings.DATA_STRING_POSITION)).set(worldPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void collideEntities(Entity generatorHitbox){
|
public static void collideEntities(Entity generatorHitbox){
|
||||||
@ -123,7 +125,8 @@ public class HitboxUtils {
|
|||||||
int currentHp = lifeState.getLifeCurrent();
|
int currentHp = lifeState.getLifeCurrent();
|
||||||
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
||||||
if(currentHp > lifeState.getLifeCurrent()){
|
if(currentHp > lifeState.getLifeCurrent()){
|
||||||
ParticleEffects.spawnSparks(new Vector3f(EntityUtils.getPosition(hurtbox)).add(0,0.1f,0), 20, 40);
|
Vector3d hurtboxPos = EntityUtils.getPosition(hurtbox);
|
||||||
|
ParticleEffects.spawnSparks(new Vector3f((float)hurtboxPos.x,(float)hurtboxPos.y,(float)hurtboxPos.z).add(0,0.1f,0), 20, 40);
|
||||||
}
|
}
|
||||||
if(!LifeUtils.getLifeState(hurtboxParent).isIsAlive()){
|
if(!LifeUtils.getLifeState(hurtboxParent).isIsAlive()){
|
||||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import electrosphere.renderer.Actor;
|
|||||||
import electrosphere.renderer.ActorUtils;
|
import electrosphere.renderer.ActorUtils;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,8 +60,8 @@ public class ItemUtils {
|
|||||||
public static void sendEntityToPlayer(Player player, Entity item){
|
public static void sendEntityToPlayer(Player player, Entity item){
|
||||||
int id = item.getId();
|
int id = item.getId();
|
||||||
String type = ItemUtils.getType(item);
|
String type = ItemUtils.getType(item);
|
||||||
Vector3f position = EntityUtils.getPosition(item);
|
Vector3d position = EntityUtils.getPosition(item);
|
||||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_ITEM, type, position.x, position.y, position.z);
|
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_ITEM, type, (float)position.x, (float)position.y, (float)position.z);
|
||||||
player.addMessage(message);
|
player.addMessage(message);
|
||||||
if(AttachUtils.isAttached(item)){
|
if(AttachUtils.isAttached(item)){
|
||||||
player.addMessage(
|
player.addMessage(
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import electrosphere.main.Globals;
|
|||||||
import org.joml.AxisAngle4f;
|
import org.joml.AxisAngle4f;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +34,7 @@ public class ParticleUtils {
|
|||||||
public static void makeParticleBillboardFaceCamera(Entity particle){
|
public static void makeParticleBillboardFaceCamera(Entity particle){
|
||||||
Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
||||||
Vector3f cameraEye = new Vector3f(CameraEntityUtils.getCameraEye(Globals.playerCamera)).add(cameraCenter).mul(-1.0f);
|
Vector3f cameraEye = new Vector3f(CameraEntityUtils.getCameraEye(Globals.playerCamera)).add(cameraCenter).mul(-1.0f);
|
||||||
Vector3f particlePosition = EntityUtils.getPosition(particle);
|
Vector3d particlePosition = EntityUtils.getPosition(particle);
|
||||||
// Vector3f cameraEye = new Vector3f(CameraEntityUtils.getCameraEye(Globals.playerCamera)).mul(1.0f,-1.0f,-1.0f);
|
// Vector3f cameraEye = new Vector3f(CameraEntityUtils.getCameraEye(Globals.playerCamera)).mul(1.0f,-1.0f,-1.0f);
|
||||||
// Vector3f directionVector = new Vector3f(cameraCenter).sub(cameraEye);
|
// Vector3f directionVector = new Vector3f(cameraCenter).sub(cameraEye);
|
||||||
Matrix4f rotationMatrix = new Matrix4f(Globals.viewMatrix).invert();
|
Matrix4f rotationMatrix = new Matrix4f(Globals.viewMatrix).invert();
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import electrosphere.net.parser.net.message.NetworkMessage;
|
|||||||
import electrosphere.net.server.Player;
|
import electrosphere.net.server.Player;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.joml.Vector4f;
|
import org.joml.Vector4f;
|
||||||
|
|
||||||
@ -60,8 +61,8 @@ public class StructureUtils {
|
|||||||
public static void sendStructureToPlayer(Player player, Entity structure){
|
public static void sendStructureToPlayer(Player player, Entity structure){
|
||||||
int id = structure.getId();
|
int id = structure.getId();
|
||||||
String type = StructureUtils.getType(structure);
|
String type = StructureUtils.getType(structure);
|
||||||
Vector3f position = EntityUtils.getPosition(structure);
|
Vector3d position = EntityUtils.getPosition(structure);
|
||||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_STRUCTURE, type, position.x, position.y, position.z);
|
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_STRUCTURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||||
player.addMessage(message);
|
player.addMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import electrosphere.net.parser.net.message.WorldMessage;
|
|||||||
import electrosphere.renderer.ShaderProgram;
|
import electrosphere.renderer.ShaderProgram;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -527,7 +528,7 @@ public class DrawCellManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int transformRealSpaceToCellSpace(float input){
|
public int transformRealSpaceToCellSpace(double input){
|
||||||
return (int)(input / clientWorldData.getDynamicInterpolationRatio());
|
return (int)(input / clientWorldData.getDynamicInterpolationRatio());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,7 +541,7 @@ public class DrawCellManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateDeltas(Vector3f oldPosition, Vector3f newPosition){
|
public void calculateDeltas(Vector3d oldPosition, Vector3d newPosition){
|
||||||
// if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
// if(DRAW_CELL_MANAGER_FLAG_UPDATE_DYNAMIC_TERRAIN){
|
||||||
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
|
if(transformRealSpaceToCellSpace(newPosition.x()) < transformRealSpaceToCellSpace(oldPosition.x())){
|
||||||
shiftChunksNegX();
|
shiftChunksNegX();
|
||||||
|
|||||||
@ -138,7 +138,7 @@ public class ClientTerrainManager {
|
|||||||
return terrainCache.containsHeightmapAtChunkPoint(x, y);
|
return terrainCache.containsHeightmapAtChunkPoint(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsHeightmapAtRealPoint(float x, float z){
|
public boolean containsHeightmapAtRealPoint(double x, double z){
|
||||||
return terrainCache.containsHeightmapAtChunkPoint(clientWorldData.convertRealToChunkSpace(x), clientWorldData.convertRealToChunkSpace(z));
|
return terrainCache.containsHeightmapAtChunkPoint(clientWorldData.convertRealToChunkSpace(x), clientWorldData.convertRealToChunkSpace(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,13 +147,13 @@ public class ClientTerrainManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float getHeightAtPosition(float x, float y){
|
public double getHeightAtPosition(double x, double y){
|
||||||
//get chunk coordinate space of input x,y
|
//get chunk coordinate space of input x,y
|
||||||
int chunkX = (int)Math.floor(x / clientWorldData.getDynamicInterpolationRatio());
|
int chunkX = (int)Math.floor(x / clientWorldData.getDynamicInterpolationRatio());
|
||||||
int chunkY = (int)Math.floor(y / clientWorldData.getDynamicInterpolationRatio());
|
int chunkY = (int)Math.floor(y / clientWorldData.getDynamicInterpolationRatio());
|
||||||
//get local coordinate space of input x,y
|
//get local coordinate space of input x,y
|
||||||
float localX = x - chunkX * clientWorldData.getDynamicInterpolationRatio();
|
double localX = x - chunkX * clientWorldData.getDynamicInterpolationRatio();
|
||||||
float localY = y - chunkY * clientWorldData.getDynamicInterpolationRatio();
|
double localY = y - chunkY * clientWorldData.getDynamicInterpolationRatio();
|
||||||
//get chunk elevation map
|
//get chunk elevation map
|
||||||
float[][] chunkElevationMap = getHeightmapAtPoint(chunkX,chunkY);
|
float[][] chunkElevationMap = getHeightmapAtPoint(chunkX,chunkY);
|
||||||
//floored variants of local values
|
//floored variants of local values
|
||||||
@ -174,7 +174,7 @@ public class ClientTerrainManager {
|
|||||||
float elevation01 = chunkElevationMap[(int)localX+0][(int)localY+1];
|
float elevation01 = chunkElevationMap[(int)localX+0][(int)localY+1];
|
||||||
float elevation11 = chunkElevationMap[(int)localX+1][(int)localY+1];
|
float elevation11 = chunkElevationMap[(int)localX+1][(int)localY+1];
|
||||||
|
|
||||||
float rVal =
|
double rVal =
|
||||||
(1-(localX-localXf))*(1-(localY-localYf)) * elevation00 +
|
(1-(localX-localXf))*(1-(localY-localYf)) * elevation00 +
|
||||||
( (localX-localXf))*(1-(localY-localYf)) * elevation10 +
|
( (localX-localXf))*(1-(localY-localYf)) * elevation10 +
|
||||||
(1-(localX-localXf))*( (localY-localYf)) * elevation01 +
|
(1-(localX-localXf))*( (localY-localYf)) * elevation01 +
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class ClientWorldData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int convertRealToChunkSpace(float real){
|
public int convertRealToChunkSpace(double real){
|
||||||
return (int)Math.floor(real / dynamicInterpolationRatio);
|
return (int)Math.floor(real / dynamicInterpolationRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import electrosphere.game.collision.collidable.Collidable;
|
|||||||
import static electrosphere.main.Main.deltaTime;
|
import static electrosphere.main.Main.deltaTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,7 +148,7 @@ public class CollisionEngine {
|
|||||||
* @param positionToCheck the position that it wants to move to
|
* @param positionToCheck the position that it wants to move to
|
||||||
* @return true if it can occupy that position, false otherwise
|
* @return true if it can occupy that position, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean checkCanOccupyPosition(CommonWorldData w, Entity e, Vector3f positionToCheck){
|
public boolean checkCanOccupyPosition(CommonWorldData w, Entity e, Vector3d positionToCheck){
|
||||||
boolean rVal = true;
|
boolean rVal = true;
|
||||||
//
|
//
|
||||||
// check world bounds
|
// check world bounds
|
||||||
@ -182,15 +183,15 @@ public class CollisionEngine {
|
|||||||
* @return the position the engine recommends it move to instead (this is
|
* @return the position the engine recommends it move to instead (this is
|
||||||
* guaranteed to be a valid position)
|
* guaranteed to be a valid position)
|
||||||
*/
|
*/
|
||||||
public Vector3f suggestMovementPosition(CommonWorldData w, Entity e, Vector3f positionToCheck){
|
public Vector3d suggestMovementPosition(CommonWorldData w, Entity e, Vector3d positionToCheck){
|
||||||
Vector3f suggestedPosition = new Vector3f(positionToCheck);
|
Vector3d suggestedPosition = new Vector3d(positionToCheck);
|
||||||
//
|
//
|
||||||
// adjust for minimum height (Terrain)
|
// adjust for minimum height (Terrain)
|
||||||
//
|
//
|
||||||
float heightMapBias = 0.00001f;
|
// float heightMapBias = 0.00001f;
|
||||||
if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
|
// if(w.getElevationAtPoint(positionToCheck) > positionToCheck.y){
|
||||||
suggestedPosition.y = w.getElevationAtPoint(positionToCheck) + heightMapBias;
|
// suggestedPosition.y = w.getElevationAtPoint(positionToCheck) + heightMapBias;
|
||||||
}
|
// }
|
||||||
//
|
//
|
||||||
// adjust for world bounds
|
// adjust for world bounds
|
||||||
//
|
//
|
||||||
@ -221,11 +222,11 @@ public class CollisionEngine {
|
|||||||
|
|
||||||
|
|
||||||
public boolean collisionSphereCheck(Entity hitbox1, HitboxData hitbox1data, Entity hitbox2, HitboxData hitbox2data){
|
public boolean collisionSphereCheck(Entity hitbox1, HitboxData hitbox1data, Entity hitbox2, HitboxData hitbox2data){
|
||||||
Vector3f position1 = EntityUtils.getPosition(hitbox1);
|
Vector3d position1 = EntityUtils.getPosition(hitbox1);
|
||||||
Vector3f position2 = EntityUtils.getPosition(hitbox2);
|
Vector3d position2 = EntityUtils.getPosition(hitbox2);
|
||||||
float radius1 = hitbox1data.getRadius();
|
float radius1 = hitbox1data.getRadius();
|
||||||
float radius2 = hitbox2data.getRadius();
|
float radius2 = hitbox2data.getRadius();
|
||||||
float distance = position1.distance(position2);
|
double distance = position1.distance(position2);
|
||||||
if(distance < radius1 + radius2){
|
if(distance < radius1 + radius2){
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -286,8 +287,8 @@ public class CollisionEngine {
|
|||||||
Check if the entity is being accelerated by gravity
|
Check if the entity is being accelerated by gravity
|
||||||
*/
|
*/
|
||||||
public boolean gravityCheck(CommonWorldData w, Entity e){
|
public boolean gravityCheck(CommonWorldData w, Entity e){
|
||||||
float worldHeight = w.getElevationAtPoint(EntityUtils.getPosition(e));
|
double worldHeight = w.getElevationAtPoint(EntityUtils.getPosition(e));
|
||||||
float entityHeight = EntityUtils.getPosition(e).y;
|
double entityHeight = EntityUtils.getPosition(e).y;
|
||||||
return entityHeight > worldHeight + 0.1f;
|
return entityHeight > worldHeight + 0.1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
|||||||
import electrosphere.game.client.world.ClientWorldData;
|
import electrosphere.game.client.world.ClientWorldData;
|
||||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||||
import electrosphere.game.server.world.ServerWorldData;
|
import electrosphere.game.server.world.ServerWorldData;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public class CommonWorldData {
|
public class CommonWorldData {
|
||||||
@ -42,7 +43,7 @@ public class CommonWorldData {
|
|||||||
* @param position
|
* @param position
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public float getElevationAtPoint(Vector3f position){
|
public double getElevationAtPoint(Vector3d position){
|
||||||
if(clientWorldData != null){
|
if(clientWorldData != null){
|
||||||
if(clientTerrainManager.containsHeightmapAtRealPoint(position.x, position.z)){
|
if(clientTerrainManager.containsHeightmapAtRealPoint(position.x, position.z)){
|
||||||
return clientTerrainManager.getHeightAtPosition(position.x, position.z);
|
return clientTerrainManager.getHeightAtPosition(position.x, position.z);
|
||||||
@ -71,7 +72,7 @@ public class CommonWorldData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int convertRealToWorld(float real){
|
public int convertRealToWorld(double real){
|
||||||
if(clientWorldData != null){
|
if(clientWorldData != null){
|
||||||
return clientWorldData.convertRealToChunkSpace(real);
|
return clientWorldData.convertRealToChunkSpace(real);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import java.nio.ByteOrder;
|
|||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +44,7 @@ public class PhysicsUtils {
|
|||||||
|
|
||||||
public static RigidBody attachTerrainRigidBody(Entity terrain, float[][] heightfield){
|
public static RigidBody attachTerrainRigidBody(Entity terrain, float[][] heightfield){
|
||||||
|
|
||||||
Vector3f position = EntityUtils.getPosition(terrain);
|
Vector3d position = EntityUtils.getPosition(terrain);
|
||||||
|
|
||||||
int arrayLength = heightfield.length;
|
int arrayLength = heightfield.length;
|
||||||
int arrayWidth = heightfield[0].length;
|
int arrayWidth = heightfield[0].length;
|
||||||
@ -146,7 +147,7 @@ public class PhysicsUtils {
|
|||||||
// terrainShape.getLocalAabbMax(aabbMax);
|
// terrainShape.getLocalAabbMax(aabbMax);
|
||||||
|
|
||||||
|
|
||||||
DefaultMotionState defaultMotionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f(new javax.vecmath.Quat4f(0,0,0,1),new javax.vecmath.Vector3f(position.x,position.y,position.z),1.0f)));
|
DefaultMotionState defaultMotionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f(new javax.vecmath.Quat4f(0,0,0,1),new javax.vecmath.Vector3f((float)position.x,(float)position.y,(float)position.z),1.0f)));
|
||||||
RigidBodyConstructionInfo terrainRigidBodyCI = new RigidBodyConstructionInfo(0, defaultMotionState, terrainShape);
|
RigidBodyConstructionInfo terrainRigidBodyCI = new RigidBodyConstructionInfo(0, defaultMotionState, terrainShape);
|
||||||
RigidBody terrainRigidBody = new RigidBody(terrainRigidBodyCI);
|
RigidBody terrainRigidBody = new RigidBody(terrainRigidBodyCI);
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import electrosphere.entity.state.movement.MovementTree;
|
|||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.game.server.ai.AI;
|
import electrosphere.game.server.ai.AI;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,10 +66,10 @@ public class MindlessAttacker extends AI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void moveToTarget(){
|
void moveToTarget(){
|
||||||
Vector3f targetPosition = EntityUtils.getPosition(target);
|
Vector3d targetPosition = EntityUtils.getPosition(target);
|
||||||
Vector3f charactterPosition = EntityUtils.getPosition(character);
|
Vector3d characterPosition = EntityUtils.getPosition(character);
|
||||||
Vector3f moveVector = new Vector3f(targetPosition).sub(charactterPosition).normalize();
|
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
|
||||||
CreatureUtils.setMovementVector(character, moveVector);
|
CreatureUtils.setMovementVector(character, new Vector3f((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
|
||||||
MovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
|
MovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
|
||||||
if(characterMoveTree.getState()==MovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==MovementTree.MovementTreeState.SLOWDOWN){
|
if(characterMoveTree.getState()==MovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==MovementTree.MovementTreeState.SLOWDOWN){
|
||||||
characterMoveTree.start();
|
characterMoveTree.start();
|
||||||
@ -77,9 +78,9 @@ public class MindlessAttacker extends AI{
|
|||||||
|
|
||||||
boolean inAttackRange(){
|
boolean inAttackRange(){
|
||||||
boolean rVal = false;
|
boolean rVal = false;
|
||||||
Vector3f position = EntityUtils.getPosition(character);
|
Vector3d position = EntityUtils.getPosition(character);
|
||||||
Vector3f targetPosition = EntityUtils.getPosition(target);
|
Vector3d targetPosition = EntityUtils.getPosition(target);
|
||||||
if(new Vector3f(position).distance(targetPosition) < attackRange){
|
if(new Vector3d(position).distance(targetPosition) < attackRange){
|
||||||
rVal = true;
|
rVal = true;
|
||||||
}
|
}
|
||||||
return rVal;
|
return rVal;
|
||||||
@ -87,9 +88,9 @@ public class MindlessAttacker extends AI{
|
|||||||
|
|
||||||
boolean inAggroRange(){
|
boolean inAggroRange(){
|
||||||
boolean rVal = false;
|
boolean rVal = false;
|
||||||
Vector3f position = EntityUtils.getPosition(character);
|
Vector3d position = EntityUtils.getPosition(character);
|
||||||
Vector3f targetPosition = EntityUtils.getPosition(target);
|
Vector3d targetPosition = EntityUtils.getPosition(target);
|
||||||
if(new Vector3f(position).distance(targetPosition) < aggroRange){
|
if(new Vector3d(position).distance(targetPosition) < aggroRange){
|
||||||
rVal = true;
|
rVal = true;
|
||||||
}
|
}
|
||||||
return rVal;
|
return rVal;
|
||||||
@ -97,10 +98,10 @@ public class MindlessAttacker extends AI{
|
|||||||
|
|
||||||
|
|
||||||
void searchForTarget(){
|
void searchForTarget(){
|
||||||
Vector3f position = EntityUtils.getPosition(character);
|
Vector3d position = EntityUtils.getPosition(character);
|
||||||
for(Entity current : Globals.entityManager.getLifeStateEntities()){
|
for(Entity current : Globals.entityManager.getLifeStateEntities()){
|
||||||
if(current != character){
|
if(current != character){
|
||||||
Vector3f potentialTargetPosition = EntityUtils.getPosition(current);
|
Vector3d potentialTargetPosition = EntityUtils.getPosition(current);
|
||||||
if(position.distance(potentialTargetPosition) < aggroRange){
|
if(position.distance(potentialTargetPosition) < aggroRange){
|
||||||
target = current;
|
target = current;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -16,21 +16,21 @@ public class StructurePlacer {
|
|||||||
public static Structure placeStructureAtPoint(float posX, float posY, String type){
|
public static Structure placeStructureAtPoint(float posX, float posY, String type){
|
||||||
Structure rVal = new Structure(posX,posY,type);
|
Structure rVal = new Structure(posX,posY,type);
|
||||||
|
|
||||||
float centerHeight = Globals.serverTerrainManager.getHeightAtPosition(posX, posY);
|
double centerHeight = Globals.serverTerrainManager.getHeightAtPosition(posX, posY);
|
||||||
StructureType currentTypeObject = Globals.gameConfigCurrent.getStructureTypeMap().getType(type);
|
StructureType currentTypeObject = Globals.gameConfigCurrent.getStructureTypeMap().getType(type);
|
||||||
float radius = currentTypeObject.getRadius();
|
float radius = currentTypeObject.getRadius();
|
||||||
for(int x = -(int)radius; x < radius; x++){
|
for(int x = -(int)radius; x < radius; x++){
|
||||||
for(int y = -(int)radius; y < radius; y++){
|
for(int y = -(int)radius; y < radius; y++){
|
||||||
int newWorldX = Globals.serverWorldData.convertRealToChunkSpace(posX + x);
|
int newWorldX = Globals.serverWorldData.convertRealToChunkSpace(posX + x);
|
||||||
int newWorldY = Globals.serverWorldData.convertRealToChunkSpace(posY + y);
|
int newWorldY = Globals.serverWorldData.convertRealToChunkSpace(posY + y);
|
||||||
float newLocationX = Globals.serverWorldData.getRelativeLocation(posX + x, newWorldX);
|
double newLocationX = Globals.serverWorldData.getRelativeLocation(posX + x, newWorldX);
|
||||||
float newLocationY = Globals.serverWorldData.getRelativeLocation(posY + y, newWorldY);
|
double newLocationY = Globals.serverWorldData.getRelativeLocation(posY + y, newWorldY);
|
||||||
// System.out.println("Set height: " + centerHeight);
|
// System.out.println("Set height: " + centerHeight);
|
||||||
// System.out.println("Deform in chunk: " + newWorldX + "," + newWorldY);
|
// System.out.println("Deform in chunk: " + newWorldX + "," + newWorldY);
|
||||||
Globals.serverTerrainManager.deformTerrainAtLocationToValue(newWorldX, newWorldY, (int)(newLocationX), (int)(newLocationY), centerHeight);
|
Globals.serverTerrainManager.deformTerrainAtLocationToValue(newWorldX, newWorldY, (int)(newLocationX), (int)(newLocationY), (float)centerHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StructureUtils.spawnBasicStructure(type, new Vector3f(posX,centerHeight + 2.4f,posY), new Quaternionf());
|
StructureUtils.spawnBasicStructure(type, new Vector3f(posX,(float)centerHeight + 2.4f,posY), new Quaternionf());
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,13 +138,13 @@ public class ServerTerrainManager {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public float getHeightAtPosition(float x, float y){
|
public double getHeightAtPosition(double x, double y){
|
||||||
//get chunk coordinate space of input x,y
|
//get chunk coordinate space of input x,y
|
||||||
int chunkX = (int)Math.floor(x / dynamicInterpolationRatio);
|
int chunkX = (int)Math.floor(x / dynamicInterpolationRatio);
|
||||||
int chunkY = (int)Math.floor(y / dynamicInterpolationRatio);
|
int chunkY = (int)Math.floor(y / dynamicInterpolationRatio);
|
||||||
//get local coordinate space of input x,y
|
//get local coordinate space of input x,y
|
||||||
float localX = x - chunkX * dynamicInterpolationRatio;
|
double localX = x - chunkX * dynamicInterpolationRatio;
|
||||||
float localY = y - chunkY * dynamicInterpolationRatio;
|
double localY = y - chunkY * dynamicInterpolationRatio;
|
||||||
//get chunk elevation map
|
//get chunk elevation map
|
||||||
float[][] chunkElevationMap = getChunk(chunkX,chunkY).heightMap;
|
float[][] chunkElevationMap = getChunk(chunkX,chunkY).heightMap;
|
||||||
//floored variants of local values
|
//floored variants of local values
|
||||||
@ -165,7 +165,7 @@ public class ServerTerrainManager {
|
|||||||
float elevation01 = chunkElevationMap[(int)localX+0][(int)localY+1];
|
float elevation01 = chunkElevationMap[(int)localX+0][(int)localY+1];
|
||||||
float elevation11 = chunkElevationMap[(int)localX+1][(int)localY+1];
|
float elevation11 = chunkElevationMap[(int)localX+1][(int)localY+1];
|
||||||
|
|
||||||
float rVal =
|
double rVal =
|
||||||
(1-(localX-localXf))*(1-(localY-localYf)) * elevation00 +
|
(1-(localX-localXf))*(1-(localY-localYf)) * elevation00 +
|
||||||
( (localX-localXf))*(1-(localY-localYf)) * elevation10 +
|
( (localX-localXf))*(1-(localY-localYf)) * elevation10 +
|
||||||
(1-(localX-localXf))*( (localY-localYf)) * elevation01 +
|
(1-(localX-localXf))*( (localY-localYf)) * elevation01 +
|
||||||
|
|||||||
@ -92,11 +92,11 @@ public class ServerWorldData {
|
|||||||
return randomDampener;
|
return randomDampener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int convertRealToChunkSpace(float real){
|
public int convertRealToChunkSpace(double real){
|
||||||
return (int)Math.floor(real / dynamicInterpolationRatio);
|
return (int)Math.floor(real / dynamicInterpolationRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getRelativeLocation(float real, int world){
|
public double getRelativeLocation(double real, int world){
|
||||||
return real - (world * dynamicInterpolationRatio);
|
return real - (world * dynamicInterpolationRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import electrosphere.net.parser.net.message.NetworkMessage;
|
|||||||
import electrosphere.net.server.Player;
|
import electrosphere.net.server.Player;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,7 +116,7 @@ public class DataCellManager {
|
|||||||
for(Player player : playerList){
|
for(Player player : playerList){
|
||||||
Entity playerEntity = player.getPlayerEntity();
|
Entity playerEntity = player.getPlayerEntity();
|
||||||
if(playerEntity != null){
|
if(playerEntity != null){
|
||||||
Vector3f position = EntityUtils.getPosition(playerEntity);
|
Vector3d position = EntityUtils.getPosition(playerEntity);
|
||||||
int currentWorldX = Globals.serverWorldData.convertRealToChunkSpace(position.x);
|
int currentWorldX = Globals.serverWorldData.convertRealToChunkSpace(position.x);
|
||||||
int currentWorldY = Globals.serverWorldData.convertRealToChunkSpace(position.z);
|
int currentWorldY = Globals.serverWorldData.convertRealToChunkSpace(position.z);
|
||||||
if(currentWorldX != player.getWorldX() || currentWorldY != player.getWorldY()){
|
if(currentWorldX != player.getWorldX() || currentWorldY != player.getWorldY()){
|
||||||
|
|||||||
@ -23,9 +23,9 @@ public class EnvironmentGenerator {
|
|||||||
for(int i = 0; i < targetNum; i++){
|
for(int i = 0; i < targetNum; i++){
|
||||||
Entity newTree = FoliageUtils.spawnBasicFoliage("FallOak1");
|
Entity newTree = FoliageUtils.spawnBasicFoliage("FallOak1");
|
||||||
entityList.add(newTree);
|
entityList.add(newTree);
|
||||||
float posX = worldX * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
double posX = worldX * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
||||||
float posZ = worldY * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
double posZ = worldY * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
||||||
float posY = Globals.serverTerrainManager.getHeightAtPosition(posX, posZ);
|
double posY = Globals.serverTerrainManager.getHeightAtPosition(posX, posZ);
|
||||||
// System.out.println("Spawning tree at: " + posX + "," + posY + "," + posZ);
|
// System.out.println("Spawning tree at: " + posX + "," + posY + "," + posZ);
|
||||||
// CollisionObjUtils.positionCharacter(newTree, new Vector3f(posX,posY,posZ));
|
// CollisionObjUtils.positionCharacter(newTree, new Vector3f(posX,posY,posZ));
|
||||||
EntityUtils.getPosition(newTree).set(posX,posY,posZ);
|
EntityUtils.getPosition(newTree).set(posX,posY,posZ);
|
||||||
|
|||||||
@ -40,6 +40,7 @@ import java.nio.file.StandardOpenOption;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -135,7 +136,8 @@ public class Main {
|
|||||||
///
|
///
|
||||||
Vector3f cameraRotationVector = new Vector3f();
|
Vector3f cameraRotationVector = new Vector3f();
|
||||||
|
|
||||||
|
double posX = -1;
|
||||||
|
double posZ = 0;
|
||||||
|
|
||||||
//main loop
|
//main loop
|
||||||
while (running) {
|
while (running) {
|
||||||
@ -175,11 +177,11 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//cell tracking values
|
//cell tracking values
|
||||||
Vector3f oldPlayerCharacterPosition = new Vector3f();
|
Vector3d oldPlayerCharacterPosition = new Vector3d();
|
||||||
if(Globals.playerCharacter != null){
|
if(Globals.playerCharacter != null){
|
||||||
oldPlayerCharacterPosition = new Vector3f(EntityUtils.getPosition(Globals.playerCharacter));
|
oldPlayerCharacterPosition = new Vector3d(EntityUtils.getPosition(Globals.playerCharacter));
|
||||||
}
|
}
|
||||||
Vector3f newPlayerCharacterPosition = oldPlayerCharacterPosition;
|
Vector3d newPlayerCharacterPosition = oldPlayerCharacterPosition;
|
||||||
|
|
||||||
|
|
||||||
//Poll controls
|
//Poll controls
|
||||||
@ -223,8 +225,12 @@ public class Main {
|
|||||||
|
|
||||||
updateMouseVariables();
|
updateMouseVariables();
|
||||||
|
|
||||||
|
CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch);
|
||||||
|
CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw);
|
||||||
|
|
||||||
if(Globals.playerCharacter != null){
|
if(Globals.playerCharacter != null){
|
||||||
CameraEntityUtils.setCameraCenter(Globals.playerCamera, EntityUtils.getPosition(Globals.playerCharacter));
|
Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter);
|
||||||
|
CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
float cam_Player_Orbit_Magnitude = 5f;
|
float cam_Player_Orbit_Magnitude = 5f;
|
||||||
@ -235,6 +241,20 @@ public class Main {
|
|||||||
|
|
||||||
CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
|
CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
|
||||||
|
|
||||||
|
// if(Globals.playerCharacter != null){
|
||||||
|
// Vector3f playerPos = EntityUtils.getPosition(Globals.playerCharacter);
|
||||||
|
// if(posX == -1 && playerPos.x > 100){
|
||||||
|
// posX = playerPos.x;
|
||||||
|
// posZ = playerPos.z;
|
||||||
|
// }
|
||||||
|
// posX = posX - (cameraRotationVector.x * 0.01);
|
||||||
|
// posZ = posZ - (cameraRotationVector.z * 0.01);
|
||||||
|
// Vector3f moveVec = new Vector3f(-cameraRotationVector.x,0,-cameraRotationVector.z);
|
||||||
|
// Quaternionf playerRot = new Quaternionf().rotationTo(new Vector3f(0,0,1), moveVec);
|
||||||
|
// EntityUtils.getRotation(Globals.playerCharacter).set(playerRot);
|
||||||
|
// EntityUtils.getPosition(Globals.playerCharacter).set((float)posX,playerPos.y,(float)posZ);
|
||||||
|
// }
|
||||||
|
|
||||||
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
|
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package electrosphere.renderer.light;
|
|||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +17,7 @@ public class LightEntityUtils {
|
|||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
Globals.entityManager.registerLightEntity(rVal);
|
Globals.entityManager.registerLightEntity(rVal);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
||||||
@ -28,7 +29,7 @@ public class LightEntityUtils {
|
|||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
Globals.entityManager.registerLightEntity(rVal);
|
Globals.entityManager.registerLightEntity(rVal);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import electrosphere.renderer.texture.Texture;
|
|||||||
import electrosphere.renderer.ui.Widget;
|
import electrosphere.renderer.ui.Widget;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
|
import static org.lwjgl.glfw.GLFW.GLFW_CONTEXT_VERSION_MAJOR;
|
||||||
@ -292,13 +293,15 @@ public class RenderingEngine {
|
|||||||
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
||||||
modelTransformMatrix = new Matrix4f();
|
modelTransformMatrix = new Matrix4f();
|
||||||
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
||||||
Vector3f position = EntityUtils.getPosition(currentEntity);
|
Vector3d position = EntityUtils.getPosition(currentEntity);
|
||||||
if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && drawPoint(cameraPos,position)){
|
if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z))){
|
||||||
//fetch actor
|
//fetch actor
|
||||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
//calculate and apply model transform
|
//calculate and apply model transform
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
||||||
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
||||||
currentActor.applyModelMatrix(modelTransformMatrix);
|
currentActor.applyModelMatrix(modelTransformMatrix);
|
||||||
@ -343,8 +346,8 @@ public class RenderingEngine {
|
|||||||
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
|
||||||
modelTransformMatrix = new Matrix4f();
|
modelTransformMatrix = new Matrix4f();
|
||||||
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
for(Entity currentEntity : Globals.entityManager.getDrawable()){
|
||||||
Vector3f position = EntityUtils.getPosition(currentEntity);
|
Vector3d position = EntityUtils.getPosition(currentEntity);
|
||||||
if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && drawPoint(cameraPos,position)){
|
if((boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z))){
|
||||||
//fetch actor
|
//fetch actor
|
||||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||||
currentActor.incrementAnimationTime(0.001);
|
currentActor.incrementAnimationTime(0.001);
|
||||||
@ -353,9 +356,11 @@ public class RenderingEngine {
|
|||||||
// if(currentActor.getCurrentAnimation() != null){
|
// if(currentActor.getCurrentAnimation() != null){
|
||||||
// currentActor.incrementAnimationTime(deltaTime * 500);
|
// currentActor.incrementAnimationTime(deltaTime * 500);
|
||||||
// }
|
// }
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
//calculate and apply model transform
|
//calculate and apply model transform
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
|
||||||
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
||||||
currentActor.applyModelMatrix(modelTransformMatrix);
|
currentActor.applyModelMatrix(modelTransformMatrix);
|
||||||
@ -384,9 +389,11 @@ public class RenderingEngine {
|
|||||||
if(data.isActive()){
|
if(data.isActive()){
|
||||||
if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){
|
if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HURT)){
|
||||||
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
|
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(currentHitbox);
|
Vector3d position = EntityUtils.getPosition(currentHitbox);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
||||||
modelTransformMatrix.scale(data.getRadius() * 2);
|
modelTransformMatrix.scale(data.getRadius() * 2);
|
||||||
hitboxModel.modelMatrix = modelTransformMatrix;
|
hitboxModel.modelMatrix = modelTransformMatrix;
|
||||||
@ -394,9 +401,11 @@ public class RenderingEngine {
|
|||||||
}
|
}
|
||||||
} else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
|
} else if(data.getType().equals(EntityDataStrings.COLLISION_ENTITY_DATA_TYPE_HIT)){
|
||||||
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
|
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(currentHitbox);
|
Vector3d position = EntityUtils.getPosition(currentHitbox);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
||||||
modelTransformMatrix.scale(data.getRadius() * 2);
|
modelTransformMatrix.scale(data.getRadius() * 2);
|
||||||
hitboxModel.modelMatrix = modelTransformMatrix;
|
hitboxModel.modelMatrix = modelTransformMatrix;
|
||||||
@ -405,9 +414,9 @@ public class RenderingEngine {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
|
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(currentHitbox);
|
Vector3d position = EntityUtils.getPosition(currentHitbox);
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
||||||
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
|
||||||
modelTransformMatrix.scale(data.getRadius() * 2);
|
modelTransformMatrix.scale(data.getRadius() * 2);
|
||||||
hitboxModel.modelMatrix = modelTransformMatrix;
|
hitboxModel.modelMatrix = modelTransformMatrix;
|
||||||
@ -426,9 +435,11 @@ public class RenderingEngine {
|
|||||||
switch(template.getType()){
|
switch(template.getType()){
|
||||||
case "CYLINDER":
|
case "CYLINDER":
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(physicsEntity);
|
Vector3d position = EntityUtils.getPosition(physicsEntity);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
||||||
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
|
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
|
||||||
physicsGraphicsModel.modelMatrix = modelTransformMatrix;
|
physicsGraphicsModel.modelMatrix = modelTransformMatrix;
|
||||||
@ -442,11 +453,13 @@ public class RenderingEngine {
|
|||||||
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
|
if((boolean)physicsEntity.getData(EntityDataStrings.DATA_STRING_DRAW)){
|
||||||
if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){
|
if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_PLANE)){
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitplane.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(physicsEntity);
|
Vector3d position = EntityUtils.getPosition(physicsEntity);
|
||||||
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
||||||
Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
|
Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
modelTransformMatrix.rotate(rotation);
|
modelTransformMatrix.rotate(rotation);
|
||||||
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
||||||
modelTransformMatrix.scale(scale);
|
modelTransformMatrix.scale(scale);
|
||||||
@ -455,11 +468,13 @@ public class RenderingEngine {
|
|||||||
}
|
}
|
||||||
} else if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE)){
|
} else if(physicsEntity.getDataKeys().contains(EntityDataStrings.COLLISION_ENTITY_TYPE_CUBE)){
|
||||||
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){
|
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcube.fbx")) != null){
|
||||||
Vector3f position = EntityUtils.getPosition(physicsEntity);
|
Vector3d position = EntityUtils.getPosition(physicsEntity);
|
||||||
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
Vector3f scale = EntityUtils.getScale(physicsEntity);
|
||||||
Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
|
Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
|
||||||
|
//calculate camera-modified vector3f
|
||||||
|
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
modelTransformMatrix.identity();
|
modelTransformMatrix.identity();
|
||||||
modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
|
modelTransformMatrix.translate(cameraModifiedPosition);
|
||||||
modelTransformMatrix.rotate(rotation);
|
modelTransformMatrix.rotate(rotation);
|
||||||
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
|
||||||
modelTransformMatrix.scale(scale);
|
modelTransformMatrix.scale(scale);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package electrosphere.renderer.light;
|
|||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +17,7 @@ public class LightEntityUtils {
|
|||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
Globals.entityManager.registerLightEntity(rVal);
|
Globals.entityManager.registerLightEntity(rVal);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
||||||
@ -28,7 +29,7 @@ public class LightEntityUtils {
|
|||||||
Globals.entityManager.registerEntity(rVal);
|
Globals.entityManager.registerEntity(rVal);
|
||||||
Globals.entityManager.registerLightEntity(rVal);
|
Globals.entityManager.registerLightEntity(rVal);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_DIFFUSE, diffuse);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_SPECULAR, specular);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user