From f1d17a27a33def760489da4882f6ac6939104640 Mon Sep 17 00:00:00 2001 From: freezy Date: Mon, 6 Jan 2025 13:39:49 +0100 Subject: [PATCH] doc: Update changelog. --- CHANGELOG.md | 1 + .../VisualPinball.Unity/Physics/README.md | 8 +- .../VPT/ISurfaceComponent.cs | 18 +- .../MetalWireGuideColliderComponent.cs | 1 - .../VPT/Trigger/TriggerAnimation.cs | 164 +++++++++--------- 5 files changed, 103 insertions(+), 89 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 684744feb..65d9ba82d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Built with Unity 2022.3.x ### Added +- Free transformation ([#500](https://github.com/freezy/VisualPinball.Engine/pull/500)) - Kinematic collisions ([#460](https://github.com/freezy/VisualPinball.Engine/pull/460)) - Flipper tricks by nFozzy ([#436](https://github.com/freezy/VisualPinball.Engine/pull/436)) - Asset Library now has thumbnails. diff --git a/VisualPinball.Unity/VisualPinball.Unity/Physics/README.md b/VisualPinball.Unity/VisualPinball.Unity/Physics/README.md index 2520216ab..d53f60534 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/Physics/README.md +++ b/VisualPinball.Unity/VisualPinball.Unity/Physics/README.md @@ -178,10 +178,8 @@ approach is the following: result in a rectangle parallel and orthogonal to the playfield, which wouldn't be desired. - But more on that problem later. What's important is that for transformations - *supported by the VPX physics code*, we have a method that allows to transform - each collider, based on a matrix. -- Additionally, colliders are instantiated without a transformation matrix. That means - by default, they are placed at the origin and have no rotation or scale. + *supported by the VPX physics code*, we have a method that allows to transform each collider, based on a matrix. +- Additionally, colliders are always instantiated without any transformation. That means by default, they are placed at the origin and have no rotation or scale. - Finally, each collider gets a `TransformAABBs(float4x4)` method that only transforms the collider's axis-aligned bounding boxes. @@ -193,7 +191,7 @@ So, with all of the above, we do the following when the game starts: 3. We check which kind of transformation the VPX physics code supports for the type of collider and compare it to the transformation of playfield-to-local matrix. - If all transformations are supported, we simply transform the collider with the item's - transformation matrix. + transformation matrix. - If not, we check whether this collider might be replaceable by another type of collider that supports the transformation. For example, a line collider can be replaced by two triangle colliders, which then are 100% transformable. diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs index 67c31d768..85820fc59 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/ISurfaceComponent.cs @@ -1,4 +1,20 @@ -using UnityEngine; +// Visual Pinball Engine +// Copyright (C) 2023 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using UnityEngine; namespace VisualPinball.Unity { diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideColliderComponent.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideColliderComponent.cs index 284d20121..d1cce7147 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideColliderComponent.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/MetalWireGuide/MetalWireGuideColliderComponent.cs @@ -16,7 +16,6 @@ // ReSharper disable InconsistentNaming -using Unity.Mathematics; using UnityEngine; using VisualPinball.Engine.VPT.MetalWireGuide; diff --git a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerAnimation.cs b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerAnimation.cs index 1a60991e3..ad52cc461 100644 --- a/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerAnimation.cs +++ b/VisualPinball.Unity/VisualPinball.Unity/VPT/Trigger/TriggerAnimation.cs @@ -1,82 +1,82 @@ -// Visual Pinball Engine -// Copyright (C) 2023 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using VisualPinball.Engine.VPT; - -namespace VisualPinball.Unity -{ - internal static class TriggerAnimation - { - internal static void Update(ref TriggerAnimationState animation, ref TriggerMovementState movement, in TriggerStaticState staticState, - float dTimeMs) - { - // var oldTimeMsec = animation.TimeMsec < dTimeMs ? animation.TimeMsec : dTimeMs; - // animation.TimeMsec = dTimeMs; - // var diffTimeMsec = dTimeMs - oldTimeMsec; - - var animLimit = staticState.Shape == TriggerShape.TriggerStar ? staticState.Radius * (float)(1.0 / 5.0) : 32.0f; - if (staticState.Shape == TriggerShape.TriggerButton) { - animLimit = staticState.Radius * (float)(1.0 / 10.0); - } - if (staticState.Shape == TriggerShape.TriggerWireC) { - animLimit = 60.0f; - } - if (staticState.Shape == TriggerShape.TriggerWireD) { - animLimit = 25.0f; - } - - var limit = animLimit * staticState.TableScaleZ; - - if (animation.HitEvent) { - animation.DoAnimation = true; - animation.HitEvent = false; - // unhitEvent = false; // Bugfix: If HitEvent and unhitEvent happen at the same time, you want to favor the unhit, otherwise the switch gets stuck down. - movement.HeightOffset = 0.0f; - animation.MoveDown = true; - } - if (animation.UnHitEvent) { - animation.DoAnimation = true; - animation.UnHitEvent = false; - animation.HitEvent = false; - //movement.HeightOffset = limit; - animation.MoveDown = false; - } - - if (animation.DoAnimation) { - var step = dTimeMs * staticState.AnimSpeed * staticState.TableScaleZ; - if (animation.MoveDown) { - step = -step; - } - movement.HeightOffset += step; - - if (animation.MoveDown) { - if (movement.HeightOffset <= -limit) { - movement.HeightOffset = -limit; - animation.DoAnimation = false; - animation.MoveDown = false; - } - - } else { - if (movement.HeightOffset >= 0.0f) { - movement.HeightOffset = 0.0f; - animation.DoAnimation = false; - animation.MoveDown = true; - } - } - } - } - } -} +// Visual Pinball Engine +// Copyright (C) 2023 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using VisualPinball.Engine.VPT; + +namespace VisualPinball.Unity +{ + internal static class TriggerAnimation + { + internal static void Update(ref TriggerAnimationState animation, ref TriggerMovementState movement, in TriggerStaticState staticState, + float dTimeMs) + { + // var oldTimeMsec = animation.TimeMsec < dTimeMs ? animation.TimeMsec : dTimeMs; + // animation.TimeMsec = dTimeMs; + // var diffTimeMsec = dTimeMs - oldTimeMsec; + + var animLimit = staticState.Shape == TriggerShape.TriggerStar ? staticState.Radius * (float)(1.0 / 5.0) : 32.0f; + if (staticState.Shape == TriggerShape.TriggerButton) { + animLimit = staticState.Radius * (float)(1.0 / 10.0); + } + if (staticState.Shape == TriggerShape.TriggerWireC) { + animLimit = 60.0f; + } + if (staticState.Shape == TriggerShape.TriggerWireD) { + animLimit = 25.0f; + } + + var limit = animLimit * staticState.TableScaleZ; + + if (animation.HitEvent) { + animation.DoAnimation = true; + animation.HitEvent = false; + // unhitEvent = false; // Bugfix: If HitEvent and unhitEvent happen at the same time, you want to favor the unhit, otherwise the switch gets stuck down. + movement.HeightOffset = 0.0f; + animation.MoveDown = true; + } + if (animation.UnHitEvent) { + animation.DoAnimation = true; + animation.UnHitEvent = false; + animation.HitEvent = false; + //movement.HeightOffset = limit; + animation.MoveDown = false; + } + + if (animation.DoAnimation) { + var step = dTimeMs * staticState.AnimSpeed * staticState.TableScaleZ; + if (animation.MoveDown) { + step = -step; + } + movement.HeightOffset += step; + + if (animation.MoveDown) { + if (movement.HeightOffset <= -limit) { + movement.HeightOffset = -limit; + animation.DoAnimation = false; + animation.MoveDown = false; + } + + } else { + if (movement.HeightOffset >= 0.0f) { + movement.HeightOffset = 0.0f; + animation.DoAnimation = false; + animation.MoveDown = true; + } + } + } + } + } +}