Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/borf/BrowEdit3
Browse files Browse the repository at this point in the history
  • Loading branch information
Borf committed Dec 17, 2023
2 parents 03071dd + 1bf9c1b commit 5f15bef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
16 changes: 12 additions & 4 deletions browedit/MapView.Objectmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void MapView::postRenderObjectMode(BrowEdit* browEdit)
gridSize = gridSizeRotate;
gridOffset = gridOffsetRotate;
}
else if (gadget.mode == Gadget::Mode::Scale)
{
gridSize = gridSizeScale;
gridOffset = gridOffsetScale;
}
simpleShader->use();
simpleShader->setUniform(SimpleShader::Uniforms::projectionMatrix, nodeRenderContext.projectionMatrix);
simpleShader->setUniform(SimpleShader::Uniforms::viewMatrix, nodeRenderContext.viewMatrix);
Expand Down Expand Up @@ -545,7 +550,10 @@ void MapView::postRenderObjectMode(BrowEdit* browEdit)
if (pivotPoint == PivotPoint::GroupCenter)
{
if (gadget.selectedAxis == Gadget::Axis::XYZ) {
n.first->getComponent<RswObject>()->position = groupCenter + (n.second.pos - groupCenter) * (1 + pos * glm::length(0.01f * mouseOffset));
float scale = 1 + pos * glm::length(0.01f * mouseOffset);
if (snap)
scale = glm::round(scale / (float)gridSize) * (float)gridSize;
n.first->getComponent<RswObject>()->position = groupCenter + (n.second.pos - groupCenter) * scale;
}
else {
int axis = gadget.selectedAxisIndex();
Expand All @@ -556,7 +564,7 @@ void MapView::postRenderObjectMode(BrowEdit* browEdit)
if (gadget.mode == Gadget::Mode::Rotate)
{
if (snap && pivotPoint == PivotPoint::GroupCenter && map->selectedNodes.size() > 1) {
angle = glm::radians(glm::round((glm::degrees(angle) - gridOffset) / (float)gridSizeRotate) * (float)gridSizeRotate + gridOffset);
angle = glm::radians(glm::round((glm::degrees(angle) - gridOffset) / (float)gridSize) * (float)gridSize + gridOffset);
}

if (!lockedGizmo) {
Expand All @@ -572,7 +580,7 @@ void MapView::postRenderObjectMode(BrowEdit* browEdit)
glm::mat4 newRot = glm::mat4(1);

if (snap && !(pivotPoint == PivotPoint::GroupCenter && map->selectedNodes.size() > 1)) {
angle = glm::radians(glm::round((glm::degrees(angle) - gridOffset) / (float)gridSizeRotate) * (float)gridSizeRotate + gridOffset);
angle = glm::radians(glm::round((glm::degrees(angle) - gridOffset) / (float)gridSize) * (float)gridSize + gridOffset);
}

if (gadget.selectedAxis == Gadget::Axis::X) {
Expand Down Expand Up @@ -616,7 +624,7 @@ void MapView::postRenderObjectMode(BrowEdit* browEdit)

if (!lockedGizmo) {
if (snap && !(pivotPoint == PivotPoint::GroupCenter && map->selectedNodes.size() > 1)) {
n.first->getComponent<RswObject>()->rotation[gadget.selectedAxisIndex()] = glm::round((n.first->getComponent<RswObject>()->rotation[gadget.selectedAxisIndex()] - gridOffset) / (float)gridSizeRotate) * (float)gridSizeRotate + gridOffset;
n.first->getComponent<RswObject>()->rotation[gadget.selectedAxisIndex()] = glm::round((n.first->getComponent<RswObject>()->rotation[gadget.selectedAxisIndex()] - gridOffset) / (float)gridSize) * (float)gridSize + gridOffset;
}
}

Expand Down
24 changes: 18 additions & 6 deletions browedit/MapView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,19 @@ void MapView::toolbar(BrowEdit* browEdit)
{
ImGui::SameLine();
ImGui::SetNextItemWidth(50);
if (ImGui::DragFloat("##gridSize", (gadget.mode == Gadget::Mode::Translate || gadget.mode == Gadget::Mode::Scale || browEdit->editMode == BrowEdit::EditMode::Height) ? &gridSizeTranslate : &gridSizeRotate, 1.0f, 0.1f, 100.0f, "%.3f")) {
if (gadget.mode == Gadget::Mode::Rotate)
rebuildObjectRotateModeGrid();
else
rebuildObjectModeGrid();
switch (gadget.mode) {
case Gadget::Mode::Scale:
if (ImGui::DragFloat("##gridSize", &gridSizeScale, 1.0f, 0.1f, 100.0f, "%.3f"))
rebuildObjectModeGrid();
break;
case Gadget::Mode::Rotate:
if (ImGui::DragFloat("##gridSize", &gridSizeRotate, 1.0f, 0.1f, 100.0f, "%.3f"))
rebuildObjectRotateModeGrid();
break;
default:
if (ImGui::DragFloat("##gridSize", &gridSizeTranslate, 1.0f, 0.1f, 100.0f, "%.3f"))
rebuildObjectModeGrid();
break;
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Grid size. Doubleclick or ctrl+click to type a number");
Expand All @@ -231,6 +239,8 @@ void MapView::toolbar(BrowEdit* browEdit)
{
if (gadget.mode == Gadget::Mode::Translate)
gridSizeTranslate = f;
else if (gadget.mode == Gadget::Mode::Scale)
gridSizeScale = f;
else
gridSizeRotate = f;
ImGui::CloseCurrentPopup();
Expand All @@ -246,7 +256,9 @@ void MapView::toolbar(BrowEdit* browEdit)
{
ImGui::SameLine();
ImGui::SetNextItemWidth(50);
if (gadget.mode == Gadget::Mode::Translate || gadget.mode == Gadget::Mode::Scale)
if (gadget.mode == Gadget::Mode::Scale)
ImGui::DragFloat("##gridOffset", &gridOffsetScale, 1.0f, 0, gridSizeScale, "%.2f");
else if (gadget.mode == Gadget::Mode::Translate)
ImGui::DragFloat("##gridOffset", &gridOffsetTranslate, 1.0f, 0, gridSizeTranslate, "%.2f");
else
if (ImGui::DragFloat("##gridOffset", &gridOffsetRotate, 1.0f, 0, gridSizeRotate, "%.2f"))
Expand Down
2 changes: 2 additions & 0 deletions browedit/MapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class MapView
bool gridLocal = true;
float gridSizeTranslate = 5;
float gridSizeRotate = 45;
float gridSizeScale = 0.5f;
float gridOffsetTranslate = 0;
float gridOffsetRotate = 0;
float gridOffsetScale = 0;

bool showAllLights = false;
bool showLightSphere = false;
Expand Down

0 comments on commit 5f15bef

Please sign in to comment.