From 4edfdabcd089b663cde384807d552f55b393f0ba Mon Sep 17 00:00:00 2001 From: 4sval Date: Sat, 27 Aug 2022 18:37:33 +0200 Subject: [PATCH] dynamic camera speed --- CUE4Parse | 2 +- FModel/Views/Snooper/Camera.cs | 4 +++- FModel/Views/Snooper/Section.cs | 15 +++++++++------ FModel/Views/Snooper/Snooper.cs | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index aa5c9a48..c3db95eb 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit aa5c9a485e236b1788cc484e4bb22ab8ff202573 +Subproject commit c3db95ebc3800207eb3fc7dc66470178c037ff51 diff --git a/FModel/Views/Snooper/Camera.cs b/FModel/Views/Snooper/Camera.cs index 9dbaf5d8..0409ff1b 100644 --- a/FModel/Views/Snooper/Camera.cs +++ b/FModel/Views/Snooper/Camera.cs @@ -13,12 +13,14 @@ public class Camera public float Yaw { get; set; } = -90f; public float Pitch { get; set; } = 0f; public float Zoom { get; set; } = 45f; + public float Speed { get; set; } = 1f; public float AspectRatio => 16f / 9f; - public Camera(Vector3 position, Vector3 direction) + public Camera(Vector3 position, Vector3 direction, float speed) { Position = position; Direction = direction; + Speed = speed; // trigonometric math to calculate the cam's yaw/pitch based on position and direction to look var yaw = MathF.Atan((-Position.X - Direction.X) / (Position.Z - Direction.Z)); diff --git a/FModel/Views/Snooper/Section.cs b/FModel/Views/Snooper/Section.cs index 95200a34..c3624ffc 100644 --- a/FModel/Views/Snooper/Section.cs +++ b/FModel/Views/Snooper/Section.cs @@ -17,16 +17,16 @@ public class Section : IDisposable public uint FacesCount; public int FirstFaceIndex; - public CMaterialParams Params; + public CMaterialParams Parameters; public Section(uint facesCount, int firstFaceIndex, CMeshSection section) { FacesCount = facesCount; FirstFaceIndex = firstFaceIndex; - Params = new CMaterialParams(); + Parameters = new CMaterialParams(); if (section.Material != null && section.Material.TryLoad(out var material) && material is UMaterialInterface unrealMaterial) { - unrealMaterial.GetParams(Params); + unrealMaterial.GetParams(Parameters); } } @@ -36,7 +36,7 @@ public class Section : IDisposable _handle = _gl.CreateProgram(); - if (Params.Diffuse is UTexture2D { IsVirtual: false } diffuse && diffuse.GetFirstMip() is { } mip) + if (Parameters.Diffuse is UTexture2D { IsVirtual: false } diffuse && diffuse.GetFirstMip() is { } mip) { TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, out var data, out _); _albedoMap = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY); @@ -45,13 +45,16 @@ public class Section : IDisposable public void Bind(Shader shader) { + if (Parameters.IsNull) + return; + shader.SetUniform("material.albedo", 0); - _albedoMap.Bind(TextureUnit.Texture0); + _albedoMap?.Bind(TextureUnit.Texture0); } public void Dispose() { - _albedoMap.Dispose(); + _albedoMap?.Dispose(); _gl.DeleteProgram(_handle); } } diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index c8bf7f60..dc4483c6 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -72,7 +72,7 @@ public class Snooper { var center = box.GetCenter(); var position = new Vector3(0f, center.Z, box.Max.Y * 3); - _camera = new Camera(position, center); + _camera = new Camera(position, center, box.Max.Max() / 2f); } private void OnLoad() @@ -109,8 +109,8 @@ public class Snooper private void OnUpdate(double deltaTime) { - var speed = _keyboard.IsKeyPressed(Key.ShiftLeft) ? 2.5f : 1f; - var moveSpeed = speed * (float) deltaTime; + var multiplier = _keyboard.IsKeyPressed(Key.ShiftLeft) ? 2f : 1f; + var moveSpeed = _camera.Speed * multiplier * (float) deltaTime; if (_keyboard.IsKeyPressed(Key.W)) { _camera.Position += moveSpeed * _camera.Direction;