mirror of
https://github.com/4sval/FModel.git
synced 2026-03-30 05:35:36 -05:00
dynamic camera speed
This commit is contained in:
parent
2cf40a022c
commit
4edfdabcd0
|
|
@ -1 +1 @@
|
|||
Subproject commit aa5c9a485e236b1788cc484e4bb22ab8ff202573
|
||||
Subproject commit c3db95ebc3800207eb3fc7dc66470178c037ff51
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user