From 11fdc690dabb66286e22954d840ec14770df2ab0 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 16 Oct 2024 15:23:46 -0400 Subject: [PATCH] camera data definitions in entity files --- assets/Data/entity/creatures/human.json | 7 +++ assets/Data/entity/creatures/skeleton.json | 7 +++ docs/src/progress/renderertodo.md | 4 ++ .../entity/camera/CameraEntityUtils.java | 51 ++++++++++--------- .../game/data/common/CommonEntityType.java | 23 +++++++++ .../game/data/common/camera/CameraData.java | 34 +++++++++++++ 6 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 src/main/java/electrosphere/game/data/common/camera/CameraData.java diff --git a/assets/Data/entity/creatures/human.json b/assets/Data/entity/creatures/human.json index e6568662..250c42e4 100644 --- a/assets/Data/entity/creatures/human.json +++ b/assets/Data/entity/creatures/human.json @@ -578,6 +578,13 @@ "attackRange" : 0.8 } ], + "cameraData" : { + "thirdPersonCameraOffset": { + "x": 0.0, + "y": 1.5, + "z": 0.0 + } + }, "boneGroups" : [ { "id" : "torso", diff --git a/assets/Data/entity/creatures/skeleton.json b/assets/Data/entity/creatures/skeleton.json index 5d59e106..b6ec70b7 100644 --- a/assets/Data/entity/creatures/skeleton.json +++ b/assets/Data/entity/creatures/skeleton.json @@ -462,6 +462,13 @@ "attackRange" : 0.8 } ], + "cameraData" : { + "thirdPersonCameraOffset": { + "x": 0.0, + "y": 1.5, + "z": 0.0 + } + }, "boneGroups" : [ { "id" : "torso", diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 93660892..9c6de091 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -864,6 +864,10 @@ Entity spawning palette item actually working via hooks Model fix for shovel, shuffling item models Work on separating procedural tree generation steps + +(10/16/2024) +Camera offset definitions in entity files + # TODO diff --git a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java index 40f2dcd5..7c91b047 100644 --- a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java +++ b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java @@ -6,6 +6,8 @@ import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.types.common.CommonEntityUtils; +import electrosphere.game.data.common.CommonEntityType; import electrosphere.util.math.MathUtils; import org.joml.Matrix4d; @@ -56,7 +58,19 @@ public class CameraEntityUtils { return rVal; } - public static Entity spawnPlayerEntityTrackingCameraEntity(Vector3f center, Vector3f eye){ + + /** + *

+ * Spawns a camera that tracks the player entity. + *

+ *

+ * This uses more intelligent logic to automatically set offset based on the type of entity the player is. + *

+ * @return The camera entity + */ + public static Entity spawnPlayerEntityTrackingCameraEntity(){ + Vector3f center = new Vector3f(0,0,0); + Vector3f eye = MathUtils.getOriginVectorf(); Entity rVal = EntityCreationUtils.createClientSpatialEntity(); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); @@ -66,6 +80,17 @@ public class CameraEntityUtils { rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); Globals.cameraHandler.setTrackPlayerEntity(true); + //if camera data is defined, use the camera data third person offset instead of the default offset + if(Globals.playerEntity != null && CommonEntityUtils.getCommonData(Globals.playerEntity) != null){ + CommonEntityType type = CommonEntityUtils.getCommonData(Globals.playerEntity); + if(type.getCameraData() != null && type.getCameraData().getThirdPersonCameraOffset() != null){ + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f( + (float)type.getCameraData().getThirdPersonCameraOffset().x, + (float)type.getCameraData().getThirdPersonCameraOffset().y, + (float)type.getCameraData().getThirdPersonCameraOffset().z + )); + } + } return rVal; } @@ -88,28 +113,6 @@ public class CameraEntityUtils { return rVal; } - public static Entity spawnPlayerEntityAirplaneTrackingCameraEntity(Vector3f center, Vector3f eye){ - Entity rVal = EntityCreationUtils.createClientSpatialEntity(); - 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_EYE, eye); - rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 2.0f); - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,0.45f,0)); - rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); - rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); - BehaviorTree entityTrackingTree = new BehaviorTree() { - @Override - public void simulate(float deltaTime) { - if(Globals.playerEntity != null){ - Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity); - CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(getOrbitalCameraRadialOffset(rVal))); - } - } - }; - Globals.clientScene.registerBehaviorTree(entityTrackingTree); - return rVal; - } - /** * Initializes the camera */ @@ -120,7 +123,7 @@ public class CameraEntityUtils { } //create if(Globals.controlHandler.cameraIsThirdPerson()){ - Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraEntity(new Vector3f(0,0,0), MathUtils.getOriginVectorf()); + Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraEntity(); } else { Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraFirstPersonEntity(new Vector3f(0,0,0), MathUtils.getOriginVectorf()); } diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityType.java b/src/main/java/electrosphere/game/data/common/CommonEntityType.java index 207377b2..087309a4 100644 --- a/src/main/java/electrosphere/game/data/common/CommonEntityType.java +++ b/src/main/java/electrosphere/game/data/common/CommonEntityType.java @@ -4,6 +4,7 @@ import java.util.List; import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.game.data.collidable.HitboxData; +import electrosphere.game.data.common.camera.CameraData; import electrosphere.game.data.common.light.PointLightDescription; import electrosphere.game.data.creature.type.HealthSystem; import electrosphere.game.data.creature.type.LookAtSystem; @@ -132,6 +133,11 @@ public class CommonEntityType { */ ParticleEmitter particleEmitter; + /** + * Data determining how cameras interact with this type of entity + */ + CameraData cameraData; + /** * Gets the id for this creature type * @return The id @@ -308,4 +314,21 @@ public class CommonEntityType { return particleEmitter; } + /** + * Gets the camera data for this entity + * @return The camera data + */ + public CameraData getCameraData() { + return cameraData; + } + + /** + * Gets the ai tree data for this entity + * @return The ai tree data + */ + public List getAiTrees() { + return aiTrees; + } + + } diff --git a/src/main/java/electrosphere/game/data/common/camera/CameraData.java b/src/main/java/electrosphere/game/data/common/camera/CameraData.java new file mode 100644 index 00000000..0e073d14 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/camera/CameraData.java @@ -0,0 +1,34 @@ +package electrosphere.game.data.common.camera; + +import org.joml.Vector3d; + +/** + * Data about how the camera should interact with this entity + */ +public class CameraData { + + /** + * The offset applied to the camera that tracks this entity when in third person + */ + Vector3d thirdPersonCameraOffset; + + /** + * Gets the offset applied to the camera that tracks this entity when in third person + * @return + */ + public Vector3d getThirdPersonCameraOffset() { + return thirdPersonCameraOffset; + } + + /** + * Sets the offset applied to the camera that tracks this entity when in third person + * @param thirdPersonCameraOffset + */ + public void setThirdPersonCameraOffset(Vector3d thirdPersonCameraOffset) { + this.thirdPersonCameraOffset = thirdPersonCameraOffset; + } + + + + +}