spring fix: initial bone axis is in local space;

editor: added missing spring icon;
This commit is contained in:
Turánszki János
2022-09-14 11:03:50 +02:00
parent e44770aca0
commit a585fa8eb3
7 changed files with 19 additions and 15 deletions
+1
View File
@@ -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
+6 -1
View File
@@ -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)
{
+1
View File
@@ -55,6 +55,7 @@ public:
Script = 1 << 17,
Expression = 1 << 18,
Terrain = 1 << 19,
Spring = 1 << 20,
All = ~0ull,
} filter = Filter::All;
+1 -1
View File
@@ -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");
+9 -11
View File
@@ -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);
-1
View File
@@ -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; } }
+1 -1
View File
@@ -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);