This commit is contained in:
parent
3bfcc4c5d1
commit
d9e0b2a9e5
@ -239,6 +239,8 @@ More Debug menus
|
||||
Another pass at grass
|
||||
- Fix shader being camera position independent (if you move the wind moves with you lol)
|
||||
|
||||
Make cursor less jittery (ie always up to date with where the camera is facing)
|
||||
|
||||
|
||||
# TODO
|
||||
|
||||
|
||||
@ -5,7 +5,9 @@ import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import electrosphere.client.targeting.crosshair.Crosshair;
|
||||
import electrosphere.collision.CollisionEngine;
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.camera.CameraEntityUtils;
|
||||
import electrosphere.renderer.ui.events.MouseEvent;
|
||||
@ -106,10 +108,34 @@ public class CameraHandler {
|
||||
CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector);
|
||||
|
||||
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
|
||||
|
||||
updatePlayerCursor();
|
||||
}
|
||||
Globals.profiler.endCpuSample();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position of the player's in world cursor
|
||||
*/
|
||||
private void updatePlayerCursor(){
|
||||
CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine();
|
||||
Entity camera = Globals.playerCamera;
|
||||
if(
|
||||
collisionEngine != null &&
|
||||
camera != null &&
|
||||
Globals.playerCursor != null
|
||||
){
|
||||
Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera));
|
||||
Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera));
|
||||
Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1.0), 5.0);
|
||||
if(cursorPos != null){
|
||||
EntityUtils.getPosition(Globals.playerCursor).set(cursorPos);
|
||||
} else {
|
||||
EntityUtils.getPosition(Globals.playerCursor).set(new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-5.0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float getYaw(){
|
||||
return yaw;
|
||||
}
|
||||
|
||||
@ -360,6 +360,9 @@ public class Globals {
|
||||
|
||||
//the player camera entity
|
||||
public static Entity playerCamera;
|
||||
|
||||
//the player in world cursor
|
||||
public static Entity playerCursor;
|
||||
|
||||
//the creature the player camera will orbit and will receive controlHandler movementTree updates
|
||||
public static Entity playerEntity;
|
||||
|
||||
@ -224,29 +224,9 @@ public class ClientLoading {
|
||||
Globals.clientScene.registerBehaviorTree(new ApplyRotationTree(cloudRing,new Quaterniond().rotationZ(0.0001)));
|
||||
Globals.assetManager.queueOverrideMeshShader("Models/environment/cloudRing.fbx", "Sphere", "Shaders/skysphere/skysphere.vs", "Shaders/skysphere/skysphere.fs");
|
||||
|
||||
Entity cursorTracker = EntityCreationUtils.createClientSpatialEntity();
|
||||
EntityCreationUtils.makeEntityDrawable(cursorTracker, "Models/basic/geometry/unitsphere_1.fbx");
|
||||
EntityUtils.getScale(cursorTracker).set(30f);
|
||||
Globals.clientSceneWrapper.getScene().registerBehaviorTree(new BehaviorTree() {
|
||||
@Override
|
||||
public void simulate(float deltaTime) {
|
||||
CollisionEngine collisionEngine = Globals.clientSceneWrapper.getCollisionEngine();
|
||||
Entity camera = Globals.playerCamera;
|
||||
if(
|
||||
collisionEngine != null &&
|
||||
camera != null
|
||||
){
|
||||
Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera));
|
||||
Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera));
|
||||
Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1.0), 5.0);
|
||||
if(cursorPos != null){
|
||||
EntityUtils.getPosition(cursorTracker).set(cursorPos);
|
||||
} else {
|
||||
EntityUtils.getPosition(cursorTracker).set(new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-5.0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Globals.playerCursor = EntityCreationUtils.createClientSpatialEntity();
|
||||
EntityCreationUtils.makeEntityDrawable(Globals.playerCursor, "Models/basic/geometry/unitsphere_1.fbx");
|
||||
EntityUtils.getScale(Globals.playerCursor).set(30f);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user