camera data definitions in entity files
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-10-16 15:23:46 -04:00
parent a68e56285a
commit 11fdc690da
6 changed files with 102 additions and 24 deletions

View File

@ -578,6 +578,13 @@
"attackRange" : 0.8
}
],
"cameraData" : {
"thirdPersonCameraOffset": {
"x": 0.0,
"y": 1.5,
"z": 0.0
}
},
"boneGroups" : [
{
"id" : "torso",

View File

@ -462,6 +462,13 @@
"attackRange" : 0.8
}
],
"cameraData" : {
"thirdPersonCameraOffset": {
"x": 0.0,
"y": 1.5,
"z": 0.0
}
},
"boneGroups" : [
{
"id" : "torso",

View File

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

View File

@ -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){
/**
* <p>
* Spawns a camera that tracks the player entity.
* </p>
* <p>
* This uses more intelligent logic to automatically set offset based on the type of entity the player is.
* </p>
* @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());
}

View File

@ -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<AITreeData> getAiTrees() {
return aiTrees;
}
}

View File

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