Skip to content

Commit

Permalink
spring: always must be limited, and added gravity slider
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed May 3, 2024
1 parent 81adeaa commit 43da86d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
22 changes: 11 additions & 11 deletions Editor/SpringWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ void SpringWindow::Create(EditorComponent* _editor)
});
AddWidget(&disabledCheckBox);

stretchCheckBox.Create("Stretch enabled: ");
stretchCheckBox.SetTooltip("Stretch means that length from parent transform won't be preserved.");
stretchCheckBox.SetPos(XMFLOAT2(x, y += step));
stretchCheckBox.SetSize(XMFLOAT2(hei, hei));
stretchCheckBox.OnClick([=](wi::gui::EventArgs args) {
editor->GetCurrentScene().springs.GetComponent(entity)->SetStretchEnabled(args.bValue);
});
AddWidget(&stretchCheckBox);

gravityCheckBox.Create("Gravity enabled: ");
gravityCheckBox.SetTooltip("Whether global gravity should affect the spring");
gravityCheckBox.SetPos(XMFLOAT2(x, y += step));
Expand Down Expand Up @@ -103,6 +94,15 @@ void SpringWindow::Create(EditorComponent* _editor)
});
AddWidget(&windSlider);

gravitySlider.Create(0, 1, 0, 100000, "Gravity affection: ");
gravitySlider.SetTooltip("How much the global gravity effect affects the spring");
gravitySlider.SetPos(XMFLOAT2(x, y += step));
gravitySlider.SetSize(XMFLOAT2(siz, hei));
gravitySlider.OnSlide([&](wi::gui::EventArgs args) {
editor->GetCurrentScene().springs.GetComponent(entity)->gravityPower = args.fValue;
});
AddWidget(&gravitySlider);


SetMinimized(true);
SetVisible(false);
Expand All @@ -121,11 +121,11 @@ void SpringWindow::SetEntity(Entity entity)
SetEnabled(true);

disabledCheckBox.SetCheck(spring->IsDisabled());
stretchCheckBox.SetCheck(spring->IsStretchEnabled());
gravityCheckBox.SetCheck(spring->IsGravityEnabled());
stiffnessSlider.SetValue(spring->stiffnessForce);
dragSlider.SetValue(spring->dragForce);
windSlider.SetValue(spring->windForce);
gravitySlider.SetValue(spring->gravityPower);
}
else
{
Expand Down Expand Up @@ -175,10 +175,10 @@ void SpringWindow::ResizeLayout()
add_fullwidth(resetAllButton);
add_right(debugCheckBox);
add_right(disabledCheckBox);
add_right(stretchCheckBox);
add_right(gravityCheckBox);
add(stiffnessSlider);
add(dragSlider);
add(windSlider);
add(gravitySlider);

}
2 changes: 1 addition & 1 deletion Editor/SpringWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class SpringWindow : public wi::gui::Window
wi::gui::Button resetAllButton;
wi::gui::CheckBox debugCheckBox;
wi::gui::CheckBox disabledCheckBox;
wi::gui::CheckBox stretchCheckBox;
wi::gui::CheckBox gravityCheckBox;
wi::gui::Slider stiffnessSlider;
wi::gui::Slider dragSlider;
wi::gui::Slider windSlider;
wi::gui::Slider gravitySlider;

void ResizeLayout() override;
};
Expand Down
14 changes: 4 additions & 10 deletions WickedEngine/wiScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3528,11 +3528,8 @@ namespace wi::scene
XMVECTOR tail_next = tail_current + inertia + dt * (stiffness + external);
XMVECTOR to_tail = XMVector3Normalize(tail_next - position_root);

if (!spring.IsStretchEnabled())
{
// Limit offset to keep distance from parent:
tail_next = position_root + to_tail * boneLength;
}
// Limit offset to keep distance from parent:
tail_next = position_root + to_tail * boneLength;

#if 1
// Collider checks:
Expand Down Expand Up @@ -3569,11 +3566,8 @@ namespace wi::scene
tail_next = tail_next - XMLoadFloat3(&direction) * dist;
to_tail = XMVector3Normalize(tail_next - position_root);

if (!spring.IsStretchEnabled())
{
// Limit offset to keep distance from parent:
tail_next = position_root + to_tail * boneLength;
}
// Limit offset to keep distance from parent:
tail_next = position_root + to_tail * boneLength;

XMStoreFloat3(&tail_sphere.center, tail_next);
tail_sphere.radius = hitRadius;
Expand Down
4 changes: 1 addition & 3 deletions WickedEngine/wiScene_Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ namespace wi::scene
EMPTY = 0,
RESET = 1 << 0,
DISABLED = 1 << 1,
STRETCH_ENABLED = 1 << 2,
_DEPRECATED_STRETCH_ENABLED = 1 << 2,
GRAVITY_ENABLED = 1 << 3,
};
uint32_t _flags = RESET | GRAVITY_ENABLED;
Expand All @@ -1642,12 +1642,10 @@ namespace wi::scene

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; } }
inline void SetStretchEnabled(bool value) { if (value) { _flags |= STRETCH_ENABLED; } else { _flags &= ~STRETCH_ENABLED; } }
inline void SetGravityEnabled(bool value) { if (value) { _flags |= GRAVITY_ENABLED; } else { _flags &= ~GRAVITY_ENABLED; } }

inline bool IsResetting() const { return _flags & RESET; }
inline bool IsDisabled() const { return _flags & DISABLED; }
inline bool IsStretchEnabled() const { return _flags & STRETCH_ENABLED; }
inline bool IsGravityEnabled() const { return _flags & GRAVITY_ENABLED; }

void Serialize(wi::Archive& archive, wi::ecs::EntitySerializer& seri);
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 446;
const int revision = 447;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit 43da86d

Please sign in to comment.