diff --git a/SMCode/SM.Base/Controls/Keyboard.cs b/SMCode/SM.Base/Controls/Keyboard.cs index c002692..5411d89 100644 --- a/SMCode/SM.Base/Controls/Keyboard.cs +++ b/SMCode/SM.Base/Controls/Keyboard.cs @@ -82,7 +82,7 @@ namespace SM.Base.Controls throw new ArgumentException("The startIndex is greater than the endIndex.", nameof(startIndex)); int length = endIndex - startIndex; - for (int i = 0; i < length; i++) + for (int i = 0; i < length + 1; i++) { int actualIndex = i + startIndex; Key key = (Key) actualIndex; @@ -136,7 +136,7 @@ namespace SM.Base.Controls bool success = false; List keys = new List(); - for (int i = 0; i < length; i++) + for (int i = 0; i < length + 1; i++) { int actualIndex = i + startIndex; Key key = (Key) actualIndex; diff --git a/SMCode/SM.Base/Drawing/GenericTransformation.cs b/SMCode/SM.Base/Drawing/GenericTransformation.cs index 5ddac89..3d3325a 100644 --- a/SMCode/SM.Base/Drawing/GenericTransformation.cs +++ b/SMCode/SM.Base/Drawing/GenericTransformation.cs @@ -19,7 +19,7 @@ namespace SM.Base.Drawing /// /// The last matrix that was used to calculate the real world matrix. /// - public Matrix4 LastMaster { get; internal set; } + public Matrix4 LastMaster { get; set; } /// /// The transformation in world space. diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/SMCode/SM.Base/Window/GLWindow.cs index 6f93b9c..7123993 100644 --- a/SMCode/SM.Base/Window/GLWindow.cs +++ b/SMCode/SM.Base/Window/GLWindow.cs @@ -121,12 +121,6 @@ namespace SM.Base.Window Mouse.MouseMoveEvent(e, this); } - protected override void OnClosing(CancelEventArgs e) - { - base.OnClosing(e); - _fixedUpdateThread?.Abort(); - } - public void Update(UpdateContext context) { @@ -201,7 +195,7 @@ namespace SM.Base.Window private void ExecuteFixedUpdate() { Stopwatch deltaStop = new Stopwatch(); - while (Thread.CurrentThread.ThreadState != System.Threading.ThreadState.AbortRequested) + while (!IsExiting) { deltaStop.Restart(); @@ -210,7 +204,8 @@ namespace SM.Base.Window CurrentScene?.FixedUpdate(context); long delta = deltaStop.ElapsedMilliseconds; - Thread.Sleep(Math.Max((int)(Deltatime.FixedUpdateDelta * 1000) - (int)delta, 0)); + int waitTime = Math.Max((int)(Deltatime.FixedUpdateDelta * 1000) - (int)delta, 0); + Thread.Sleep(waitTime); } } } diff --git a/SMCode/SM.Base/Window/RenderPipeline.cs b/SMCode/SM.Base/Window/RenderPipeline.cs index 31767aa..7365cb5 100644 --- a/SMCode/SM.Base/Window/RenderPipeline.cs +++ b/SMCode/SM.Base/Window/RenderPipeline.cs @@ -36,7 +36,7 @@ namespace SM.Base.Window /// This contains the default shader. /// Default: /// - public virtual MaterialShader DefaultShader { get; protected set; } = SMRenderer.DefaultMaterialShader; + public virtual MaterialShader DefaultShader { get; protected set; } /// /// Here you can set a default material. /// @@ -53,6 +53,8 @@ namespace SM.Base.Window /// public virtual void Initialization() { + MainFramebuffer.Name = GetType().Name + ".MainFramebuffer"; + if (MainFramebuffer != null) Framebuffers.Add(MainFramebuffer); DefaultShader ??= SMRenderer.DefaultMaterialShader; } diff --git a/SMCode/SM2D/Controls/Mouse2D.cs b/SMCode/SM2D/Controls/Mouse2D.cs index 64d37f7..8bf2c10 100644 --- a/SMCode/SM2D/Controls/Mouse2D.cs +++ b/SMCode/SM2D/Controls/Mouse2D.cs @@ -2,6 +2,7 @@ using OpenTK; using SM.Base.Controls; using SM.Base.Scene; +using SM.OGL.Mesh; using SM2D.Scene; using SM2D.Types; @@ -48,12 +49,11 @@ namespace SM2D.Controls foreach (TObject item in checkingObjects) { - Matrix4 worldPos = item.Transform.InWorldSpace; - item.Mesh.BoundingBox.GetBounds(worldPos, out Vector3 min, out Vector3 max); - - if (mousePos.X > min.X && mousePos.X < max.X && - mousePos.Y > min.Y && mousePos.Y < max.Y) + + if (MouseOver(mousePos, item.Mesh.BoundingBox, item.Transform)) { + Matrix4 worldPos = item.Transform.InWorldSpace; + // if z is greater than distance if (worldPos[3, 2] > distance) { @@ -63,9 +63,24 @@ namespace SM2D.Controls success = true; } + } + return success; } + + public static bool MouseOver(Vector2 mousePos, BoundingBox boundingBox, Transformation transform) + { + Matrix4 worldPos = transform.InWorldSpace; + boundingBox.GetBounds(worldPos, out Vector3 min, out Vector3 max); + + if (mousePos.X > min.X && mousePos.X < max.X && + mousePos.Y > min.Y && mousePos.Y < max.Y) + { + return true; + } + return false; + } } } \ No newline at end of file diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs index 0ec8175..892c992 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -30,6 +30,7 @@ namespace SM_TEST window.ApplySetup(new Window2DSetup() {WorldScale = new Vector2(0,1000)}); window.SetRenderPipeline(new TestRenderPipeline()); window.SetScene(scene = new Scene()); + window.RunFixedUpdate(60); window.Load += WindowOnLoad; window.RenderFrame += WindowOnUpdateFrame; window.Run(); diff --git a/SM_TEST/TestRenderPipeline.cs b/SM_TEST/TestRenderPipeline.cs index 4e907ce..fe53e1c 100644 --- a/SM_TEST/TestRenderPipeline.cs +++ b/SM_TEST/TestRenderPipeline.cs @@ -13,7 +13,7 @@ namespace SM_TEST public override void Initialization() { - MainFramebuffer = CreateWindowFramebuffer(0); + MainFramebuffer = CreateWindowFramebuffer(16); _postBuffer = CreateWindowFramebuffer(); Framebuffers.Add(_postBuffer);