diff --git a/Editor/IconDefinitions.h b/Editor/IconDefinitions.h index 4bac5eb07..ae108ef27 100644 --- a/Editor/IconDefinitions.h +++ b/Editor/IconDefinitions.h @@ -26,6 +26,7 @@ #define ICON_BONE ICON_FA_BONE #define ICON_IK ICON_FA_HAND_FIST #define ICON_NAME ICON_FA_COMMENT_DOTS +#define ICON_SPRING ICON_FA_PAPERCLIP #define ICON_COLLIDER ICON_FA_CAPSULES #define ICON_SCRIPT ICON_FA_SCROLL #define ICON_HIERARCHY ICON_FA_ARROWS_DOWN_TO_PEOPLE diff --git a/Editor/OptionsWindow.cpp b/Editor/OptionsWindow.cpp index 928a0dda9..8b62c89b3 100644 --- a/Editor/OptionsWindow.cpp +++ b/Editor/OptionsWindow.cpp @@ -315,6 +315,7 @@ void OptionsWindow::Create(EditorComponent* _editor) filterCombo.AddItem("Inverse Kinematics " ICON_IK, (uint64_t)Filter::IK); filterCombo.AddItem("Camera " ICON_CAMERA, (uint64_t)Filter::Camera); filterCombo.AddItem("Armature " ICON_ARMATURE, (uint64_t)Filter::Armature); + filterCombo.AddItem("Spring " ICON_SPRING, (uint64_t)Filter::Spring); filterCombo.AddItem("Collider " ICON_COLLIDER, (uint64_t)Filter::Collider); filterCombo.AddItem("Script " ICON_SCRIPT, (uint64_t)Filter::Script); filterCombo.AddItem("Expression " ICON_EXPRESSION, (uint64_t)Filter::Expression); @@ -749,6 +750,10 @@ void OptionsWindow::PushToEntityTree(wi::ecs::Entity entity, int level) { item.name += ICON_IK " "; } + if (scene.springs.Contains(entity)) + { + item.name += ICON_SPRING " "; + } if (scene.colliders.Contains(entity)) { item.name += ICON_COLLIDER " "; @@ -976,7 +981,7 @@ void OptionsWindow::RefreshEntityTree() } } - if (has_flag(filter, Filter::All)) + if (has_flag(filter, Filter::Spring)) { for (size_t i = 0; i < scene.springs.GetCount(); ++i) { diff --git a/Editor/OptionsWindow.h b/Editor/OptionsWindow.h index a3018d306..c38ee6b41 100644 --- a/Editor/OptionsWindow.h +++ b/Editor/OptionsWindow.h @@ -55,6 +55,7 @@ public: Script = 1 << 17, Expression = 1 << 18, Terrain = 1 << 19, + Spring = 1 << 20, All = ~0ull, } filter = Filter::All; diff --git a/Editor/SpringWindow.cpp b/Editor/SpringWindow.cpp index 0e912a44c..9eb874a9a 100644 --- a/Editor/SpringWindow.cpp +++ b/Editor/SpringWindow.cpp @@ -9,7 +9,7 @@ using namespace wi::scene; void SpringWindow::Create(EditorComponent* _editor) { editor = _editor; - wi::gui::Window::Create("Spring", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); + wi::gui::Window::Create(ICON_SPRING " Spring", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); SetSize(XMFLOAT2(460, 220)); closeButton.SetTooltip("Delete SpringComponent"); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 0839d19f4..826dd598c 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -2219,6 +2219,8 @@ namespace wi::scene } void Scene::RunSpringUpdateSystem(wi::jobsystem::context& ctx) { + if (dt <= 0) + return; static float time = 0; time += dt; const XMVECTOR windDir = XMLoadFloat3(&weather.windDirection); @@ -2238,8 +2240,6 @@ namespace wi::scene } TransformComponent& transform = transforms[transform_index]; - //XMVECTOR rotation_local = XMLoadFloat4(&transform.rotation_local); - XMVECTOR rotation_parent_world = XMQuaternionIdentity(); XMMATRIX parentWorldMatrix = XMMatrixIdentity(); const HierarchyComponent* hier = hierarchy.GetComponent(entity); @@ -2251,14 +2251,12 @@ namespace wi::scene // It will work the other way, but results will be less convincing const TransformComponent& parent_transform = transforms[parent_index]; transform.UpdateTransform_Parented(parent_transform); - rotation_parent_world = parent_transform.GetRotationV(); parentWorldMatrix = XMLoadFloat4x4(&parent_transform.world); } XMVECTOR position_root = transform.GetPositionV(); - //XMVECTOR rotation_combined = XMQuaternionNormalize(XMQuaternionMultiply(rotation_parent_world, rotation_local)); - if (spring.IsResetting() && dt > 0) + if (spring.IsResetting()) { spring.Reset(false); @@ -2288,20 +2286,20 @@ namespace wi::scene tail = position_root + ab; } } + XMVECTOR axis = tail - position_root; - XMVECTOR length = XMVector3Length(axis); - //axis = XMVector3Rotate(axis, XMQuaternionNormalize(XMQuaternionInverse(rotation_combined))); - axis /= length; + XMMATRIX parentWorldMatrixInverse = XMMatrixInverse(nullptr, parentWorldMatrix); + axis = XMVector3TransformNormal(axis, parentWorldMatrixInverse); XMStoreFloat3(&spring.boneAxis, axis); XMStoreFloat3(&spring.currentTail, tail); spring.prevTail = spring.currentTail; - spring.boneLength = XMVectorGetX(length); } XMVECTOR boneAxis = XMLoadFloat3(&spring.boneAxis); - //boneAxis = XMVector3Normalize(XMVector3Rotate(boneAxis, rotation_combined)); + boneAxis = XMVector3TransformNormal(boneAxis, parentWorldMatrix); - const float boneLength = spring.boneLength; + const float boneLength = XMVectorGetX(XMVector3Length(boneAxis)); + boneAxis /= boneLength; const float dragForce = spring.dragForce; const float stiffnessForce = spring.stiffnessForce; const XMVECTOR gravityDir = XMLoadFloat3(&spring.gravityDir); diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 28c9930ab..b654786b6 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1348,7 +1348,6 @@ namespace wi::scene XMFLOAT3 prevTail = {}; XMFLOAT3 currentTail = {}; XMFLOAT3 boneAxis = {}; - float boneLength = 0; inline void Reset(bool value = true) { if (value) { _flags |= RESET; } else { _flags &= ~RESET; } } inline void SetDisabled(bool value = true) { if (value) { _flags |= DISABLED; } else { _flags &= ~DISABLED; } } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 5d10907d4..7c9c68aa3 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 42; + const int revision = 43; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);