math class refactoring start
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
b1b0ef0708
commit
9958a6c5d4
@ -16,7 +16,6 @@ Things that feel bad:
|
|||||||
Can't instantly start/stop blocking
|
Can't instantly start/stop blocking
|
||||||
Attack animation feels slow
|
Attack animation feels slow
|
||||||
Hands don't align with blade
|
Hands don't align with blade
|
||||||
Need to be able to visualize bones
|
|
||||||
No audio
|
No audio
|
||||||
Short movement bursts feel jittery
|
Short movement bursts feel jittery
|
||||||
Part of this may be cylinder collidable instead of capsule
|
Part of this may be cylinder collidable instead of capsule
|
||||||
|
|||||||
@ -495,6 +495,7 @@ Fix jump bugginess
|
|||||||
(08/01/2024)
|
(08/01/2024)
|
||||||
Fix server entity camera rotation
|
Fix server entity camera rotation
|
||||||
Fix world bounds application
|
Fix world bounds application
|
||||||
|
Bone debug rendering
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package electrosphere.audio;
|
|||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import static org.lwjgl.openal.AL10.*;
|
import static org.lwjgl.openal.AL10.*;
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import electrosphere.entity.EntityUtils;
|
|||||||
import electrosphere.entity.types.camera.CameraEntityUtils;
|
import electrosphere.entity.types.camera.CameraEntityUtils;
|
||||||
import electrosphere.net.parser.net.message.EntityMessage;
|
import electrosphere.net.parser.net.message.EntityMessage;
|
||||||
import electrosphere.renderer.ui.events.MouseEvent;
|
import electrosphere.renderer.ui.events.MouseEvent;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for camera-related events and controls
|
* Handler for camera-related events and controls
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import electrosphere.server.datacell.ServerDataCell;
|
|||||||
import electrosphere.server.datacell.utils.EntityLookupUtils;
|
import electrosphere.server.datacell.utils.EntityLookupUtils;
|
||||||
import electrosphere.server.poseactor.PoseActor;
|
import electrosphere.server.poseactor.PoseActor;
|
||||||
import electrosphere.server.poseactor.PoseActorUtils;
|
import electrosphere.server.poseactor.PoseActorUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import org.joml.Quaterniond;
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
|
|||||||
import electrosphere.renderer.actor.Actor;
|
import electrosphere.renderer.actor.Actor;
|
||||||
import electrosphere.server.datacell.Realm;
|
import electrosphere.server.datacell.Realm;
|
||||||
import electrosphere.server.poseactor.PoseActor;
|
import electrosphere.server.poseactor.PoseActor;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import electrosphere.entity.EntityDataStrings;
|
|||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState.HitboxShapeType;
|
import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState.HitboxShapeType;
|
||||||
import electrosphere.game.data.collidable.HitboxData;
|
import electrosphere.game.data.collidable.HitboxData;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of the collection of all hitboxes on this entity
|
* The state of the collection of all hitboxes on this entity
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import electrosphere.net.synchronization.annotation.SyncedField;
|
|||||||
import electrosphere.net.synchronization.annotation.SynchronizableEnum;
|
import electrosphere.net.synchronization.annotation.SynchronizableEnum;
|
||||||
import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
|
import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
|
||||||
import electrosphere.renderer.anim.Animation;
|
import electrosphere.renderer.anim.Animation;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
import electrosphere.renderer.actor.Actor;
|
import electrosphere.renderer.actor.Actor;
|
||||||
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import electrosphere.script.utils.AccessTransforms;
|
|||||||
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
||||||
import electrosphere.server.poseactor.PoseActor;
|
import electrosphere.server.poseactor.PoseActor;
|
||||||
import electrosphere.server.utils.ServerScriptUtils;
|
import electrosphere.server.utils.ServerScriptUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import electrosphere.renderer.actor.Actor;
|
|||||||
import electrosphere.server.datacell.ServerDataCell;
|
import electrosphere.server.datacell.ServerDataCell;
|
||||||
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
|
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
|
||||||
import electrosphere.server.poseactor.PoseActor;
|
import electrosphere.server.poseactor.PoseActor;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import electrosphere.entity.EntityCreationUtils;
|
|||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.btree.BehaviorTree;
|
import electrosphere.entity.btree.BehaviorTree;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import org.joml.Matrix4d;
|
import org.joml.Matrix4d;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
|||||||
@ -73,8 +73,8 @@ import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
|
|||||||
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
|
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
|
||||||
import electrosphere.server.poseactor.PoseActor;
|
import electrosphere.server.poseactor.PoseActor;
|
||||||
import electrosphere.server.poseactor.PoseActorUtils;
|
import electrosphere.server.poseactor.PoseActorUtils;
|
||||||
import electrosphere.util.MathUtils;
|
|
||||||
import electrosphere.util.Utilities;
|
import electrosphere.util.Utilities;
|
||||||
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for creating creatures on the client and server
|
* Utilities for creating creatures on the client and server
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import electrosphere.game.data.collidable.HitboxData;
|
|||||||
import electrosphere.game.data.projectile.ProjectileType;
|
import electrosphere.game.data.projectile.ProjectileType;
|
||||||
import electrosphere.server.datacell.Realm;
|
import electrosphere.server.datacell.Realm;
|
||||||
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
|
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
public class ProjectileUtils {
|
public class ProjectileUtils {
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,8 @@
|
|||||||
package electrosphere.renderer.actor;
|
package electrosphere.renderer.actor;
|
||||||
|
|
||||||
import org.joml.Quaterniond;
|
|
||||||
import org.joml.Vector3d;
|
|
||||||
|
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
|
||||||
import electrosphere.util.MathUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utils for dealing with actors
|
* Utils for dealing with actors
|
||||||
@ -44,46 +39,6 @@ public class ActorUtils {
|
|||||||
Actor entityActor = EntityUtils.getActor(actorEntity);
|
Actor entityActor = EntityUtils.getActor(actorEntity);
|
||||||
return entityActor.getStaticMorph();
|
return entityActor.getStaticMorph();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the world position of a bone
|
|
||||||
* @param actorEntity The entity that has a bone
|
|
||||||
* @param boneName The name of the bone
|
|
||||||
*/
|
|
||||||
public static Vector3d getBoneWorldPosition(Entity actorEntity, String boneName){
|
|
||||||
Actor actor = EntityUtils.getActor(actorEntity);
|
|
||||||
Vector3d localPos = new Vector3d(actor.getBonePosition(boneName));
|
|
||||||
|
|
||||||
//transform bone space
|
|
||||||
Vector3d position = new Vector3d(localPos);
|
|
||||||
position = position.mul(EntityUtils.getScale(actorEntity));
|
|
||||||
position = position.rotate(new Quaterniond(EntityUtils.getRotation(actorEntity)));
|
|
||||||
//transform worldspace
|
|
||||||
position.add(new Vector3d(EntityUtils.getPosition(actorEntity)));
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the global rotation of the bone
|
|
||||||
* @param actorEntity The entity with the bone
|
|
||||||
* @param boneName The name of the bone
|
|
||||||
* @return The global rotation of the bone
|
|
||||||
*/
|
|
||||||
public static Quaterniond getBoneWorldRotation(Entity actorEntity, String boneName){
|
|
||||||
Actor actor = EntityUtils.getActor(actorEntity);
|
|
||||||
Quaterniond localRot = actor.getBoneRotation(boneName);
|
|
||||||
|
|
||||||
Vector3d facingAngle = CreatureUtils.getFacingVector(actorEntity);
|
|
||||||
if(facingAngle == null){
|
|
||||||
facingAngle = MathUtils.getOriginVector();
|
|
||||||
}
|
|
||||||
//calculate rotation of model
|
|
||||||
return new Quaterniond()
|
|
||||||
.rotationTo(MathUtils.getOriginVector(), new Vector3d(facingAngle.x,facingAngle.y,facingAngle.z))
|
|
||||||
.mul(localRot)
|
|
||||||
.normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,10 @@ import electrosphere.renderer.OpenGLState;
|
|||||||
import electrosphere.renderer.RenderPipelineState;
|
import electrosphere.renderer.RenderPipelineState;
|
||||||
import electrosphere.renderer.RenderingEngine;
|
import electrosphere.renderer.RenderingEngine;
|
||||||
import electrosphere.renderer.actor.Actor;
|
import electrosphere.renderer.actor.Actor;
|
||||||
import electrosphere.renderer.actor.ActorUtils;
|
|
||||||
import electrosphere.renderer.model.Bone;
|
import electrosphere.renderer.model.Bone;
|
||||||
import electrosphere.renderer.model.Model;
|
import electrosphere.renderer.model.Model;
|
||||||
import electrosphere.renderer.pipelines.RenderPipeline;
|
import electrosphere.renderer.pipelines.RenderPipeline;
|
||||||
|
import electrosphere.util.math.MathBones;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the bones for a given mesh
|
* Renders the bones for a given mesh
|
||||||
@ -71,8 +71,8 @@ public class DebugBonesPipeline implements RenderPipeline {
|
|||||||
Model boneModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcylinder.fbx");
|
Model boneModel = Globals.assetManager.fetchModel("Models/basic/geometry/unitcylinder.fbx");
|
||||||
boneModel.getMaterials().get(0).set_diffuse(Globals.textureDiffuseDefault);
|
boneModel.getMaterials().get(0).set_diffuse(Globals.textureDiffuseDefault);
|
||||||
for(Bone bone : targetActor.getBoneValues()){
|
for(Bone bone : targetActor.getBoneValues()){
|
||||||
Vector3d bonePos = ActorUtils.getBoneWorldPosition(targetEntity, bone.boneID);
|
Vector3d bonePos = MathBones.getBoneWorldPosition(targetEntity, bone.boneID);
|
||||||
Quaterniond boneRot = ActorUtils.getBoneWorldRotation(targetEntity, bone.boneID);
|
Quaterniond boneRot = MathBones.getBoneWorldRotation(targetEntity, bone.boneID);
|
||||||
|
|
||||||
//put pos + rot into model
|
//put pos + rot into model
|
||||||
Vector3f cameraModifiedPosition = new Vector3f((float)bonePos.x,(float)bonePos.y,(float)bonePos.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
Vector3f cameraModifiedPosition = new Vector3f((float)bonePos.x,(float)bonePos.y,(float)bonePos.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import electrosphere.engine.Main;
|
|||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.menu.tutorial.TutorialMenus;
|
import electrosphere.menu.tutorial.TutorialMenus;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for executing scripts in the game engine
|
* Interface for executing scripts in the game engine
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import electrosphere.entity.types.item.ItemUtils;
|
|||||||
import electrosphere.server.ai.AITree;
|
import electrosphere.server.ai.AITree;
|
||||||
import electrosphere.server.datacell.Realm;
|
import electrosphere.server.datacell.Realm;
|
||||||
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
||||||
import electrosphere.util.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
import org.joml.Quaterniond;
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
|
|||||||
58
src/main/java/electrosphere/util/math/MathBones.java
Normal file
58
src/main/java/electrosphere/util/math/MathBones.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package electrosphere.util.math;
|
||||||
|
|
||||||
|
import org.joml.Quaterniond;
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
|
import electrosphere.renderer.actor.Actor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Math functions related to bones
|
||||||
|
*/
|
||||||
|
public class MathBones {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the world position of a bone
|
||||||
|
* @param actorEntity The entity that has a bone
|
||||||
|
* @param boneName The name of the bone
|
||||||
|
*/
|
||||||
|
public static Vector3d getBoneWorldPosition(Entity actorEntity, String boneName){
|
||||||
|
Actor actor = EntityUtils.getActor(actorEntity);
|
||||||
|
Vector3d localPos = new Vector3d(actor.getBonePosition(boneName));
|
||||||
|
|
||||||
|
//transform bone space
|
||||||
|
Vector3d position = new Vector3d(localPos);
|
||||||
|
position = position.mul(EntityUtils.getScale(actorEntity));
|
||||||
|
position = position.rotate(new Quaterniond(EntityUtils.getRotation(actorEntity)));
|
||||||
|
//transform worldspace
|
||||||
|
position.add(new Vector3d(EntityUtils.getPosition(actorEntity)));
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the global rotation of the bone
|
||||||
|
* @param actorEntity The entity with the bone
|
||||||
|
* @param boneName The name of the bone
|
||||||
|
* @return The global rotation of the bone
|
||||||
|
*/
|
||||||
|
public static Quaterniond getBoneWorldRotation(Entity actorEntity, String boneName){
|
||||||
|
Actor actor = EntityUtils.getActor(actorEntity);
|
||||||
|
Quaterniond localRot = actor.getBoneRotation(boneName);
|
||||||
|
|
||||||
|
Vector3d facingAngle = CreatureUtils.getFacingVector(actorEntity);
|
||||||
|
if(facingAngle == null){
|
||||||
|
facingAngle = MathUtils.getOriginVector();
|
||||||
|
}
|
||||||
|
//calculate rotation of model
|
||||||
|
return new Quaterniond()
|
||||||
|
.rotationTo(MathUtils.getOriginVector(), new Vector3d(facingAngle.x,facingAngle.y,facingAngle.z))
|
||||||
|
.mul(localRot)
|
||||||
|
.normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package electrosphere.util;
|
package electrosphere.util.math;
|
||||||
|
|
||||||
import org.joml.Quaterniond;
|
import org.joml.Quaterniond;
|
||||||
import org.joml.Vector3d;
|
import org.joml.Vector3d;
|
||||||
Loading…
Reference in New Issue
Block a user