Skip to content

Commit

Permalink
fixed sine build when 2 points are at the same location.
Browse files Browse the repository at this point in the history
  • Loading branch information
pryvyd9 committed May 9, 2021
1 parent 01c02fb commit cecef1d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CHANGE_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ Added Publish configuration that cleans output before build and copies only nece
- property/event overhaul;
# 0.14
- introduced independent cross movement and rotation;
- isolated main math in separate static classes;
- isolated main math in separate static classes;
- fixed sine building when 2 points are at the same location;
14 changes: 10 additions & 4 deletions StereoPlus2/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ class Build {
auto ab = vertices[1] - vertices[0];
auto bc = vertices[2] - vertices[1];

auto acLength = glm::length(ac);
auto abLength = glm::length(ab);
auto bcLength = glm::length(bc);

static const auto E = glm::epsilon<float>();

// Draw straight line if 2 vertices are at the same location.
if (bcLength < E || abLength < E || acLength < E)
return { vertices[0], vertices[1], vertices[2] };

auto acUnit = glm::normalize(ac);
auto abadScalarProjection = glm::dot(ab, acUnit);
auto dbUnit = glm::normalize(ab - acUnit * abadScalarProjection);
Expand All @@ -317,16 +327,12 @@ class Build {
if (isnan(r.x) || isnan(r.y) || isnan(r.z) || isnan(r.w))
return { vertices[0], vertices[1], vertices[2] };

auto acLength = glm::length(ac);
auto abLength = glm::length(ab);
auto bdLength = abdbScalarProjection;
auto adLength = abadScalarProjection;
auto dcLength = acLength - adLength;

static const auto hpi = glm::half_pi<float>();

auto bcLength = glm::length(bc);

int abNumber = abLength / 5 + 1;
int bcNumber = bcLength / 5 + 1;

Expand Down
2 changes: 2 additions & 0 deletions StereoPlus2/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Settings {
StaticProperty(::MoveCoordinateAction, MoveCoordinateAction)
StaticProperty(bool, ShouldDetectPosition)

StaticProperty(bool, ShouldRestrictTargetModeToPivot)

// Settings
StaticProperty(std::string, Language)
StaticProperty(int, StateBufferLength)
Expand Down
22 changes: 15 additions & 7 deletions StereoPlus2/Tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ class PenTool : public EditingTool {
StateBuffer::Commit();
wasCommitDone = true;
};
Settings::ShouldRestrictTargetModeToPivot() = true;

}

Expand Down Expand Up @@ -470,12 +471,15 @@ class PenTool : public EditingTool {
StateBuffer::Commit();
wasCommitDone = true;
};
Settings::ShouldRestrictTargetModeToPivot() = true;

return true;
}
virtual bool UnbindSceneObjects() {
if (!lockCreateNewObjectHandlerId)
Input::RemoveHandler(createNewObjectHandlerId);

Settings::ShouldRestrictTargetModeToPivot() = false;

if (!target.HasValue())
return true;
Expand Down Expand Up @@ -866,9 +870,13 @@ class ExtrusionEditingTool : public EditingToolConfigured<ExtrusionEditingToolMo

cross->SetWorldPosition(pos);
};
Settings::ShouldRestrictTargetModeToPivot() = true;

return true;
}
virtual bool UnbindSceneObjects() {
Settings::ShouldRestrictTargetModeToPivot() = true;

switch (mode)
{
case Mode::Immediate:
Expand Down Expand Up @@ -1372,7 +1380,7 @@ class SinePenTool : public EditingTool {
if (Settings::ShouldMoveCrossOnSinePenModeChange().Get())
moveCrossToVertice(currentVertice);
};

Settings::ShouldRestrictTargetModeToPivot() = true;
}

public:
Expand Down Expand Up @@ -1422,13 +1430,19 @@ class SinePenTool : public EditingTool {
StateBuffer::Commit();
wasCommitDone = true;
};
Settings::ShouldRestrictTargetModeToPivot() = true;

return true;
}
virtual bool UnbindSceneObjects() {
// On unbinding objects the tool goes to
// creating new object awaiting state.
// But if the tool is unbind then it should be cancelled.
if (!lockCreateNewObjectHandlerId)
Input::RemoveHandler(createNewObjectHandlerId);

Settings::ShouldRestrictTargetModeToPivot() = false;

if (!target.HasValue())
return true;

Expand All @@ -1449,12 +1463,6 @@ class SinePenTool : public EditingTool {
}
virtual void UnbindTool() override {
UnbindSceneObjects();

// On unbinding objects the tool goes to
// creating new object awaiting state.
// But if the tool is unbind then it should be cancelled.
if (!lockCreateNewObjectHandlerId)
Input::RemoveHandler(createNewObjectHandlerId);
}

SceneObject* GetTarget() {
Expand Down
27 changes: 16 additions & 11 deletions StereoPlus2/Windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,6 @@ class ToolWindow : Window {
};
}

/*void Unbind() {
attributesWindow->UnbindTarget();
attributesWindow->UnbindTool();
}*/


virtual bool Init() {
if (!AttributesWindow().IsAssigned())
{
Expand Down Expand Up @@ -1360,11 +1354,22 @@ class ToolWindow : Window {
}
{
ImGui::Separator();
auto v = (int)Settings::TargetMode().Get();
if (ImGui::RadioButton(LocaleProvider::GetC("object"), &v, (int)TargetMode::Object))
Settings::TargetMode() = TargetMode::Object;
if (ImGui::RadioButton(LocaleProvider::GetC("pivot"), &v, (int)TargetMode::Pivot))
Settings::TargetMode() = TargetMode::Pivot;
if (Settings::ShouldRestrictTargetModeToPivot().Get()) {
auto v = (int)TargetMode::Pivot;
ImGui::Extensions::PushActive(false);
if (ImGui::RadioButton(LocaleProvider::GetC("object"), &v, (int)TargetMode::Object))
Settings::TargetMode() = TargetMode::Object;
if (ImGui::RadioButton(LocaleProvider::GetC("pivot"), &v, (int)TargetMode::Pivot))
Settings::TargetMode() = TargetMode::Pivot;
ImGui::Extensions::PopActive();
}
else {
auto v = (int)Settings::TargetMode().Get();
if (ImGui::RadioButton(LocaleProvider::GetC("object"), &v, (int)TargetMode::Object))
Settings::TargetMode() = TargetMode::Object;
if (ImGui::RadioButton(LocaleProvider::GetC("pivot"), &v, (int)TargetMode::Pivot))
Settings::TargetMode() = TargetMode::Pivot;
}
}

ImGui::Separator();
Expand Down

0 comments on commit cecef1d

Please sign in to comment.