summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2023-01-24 21:52:25 -0500
committerFox Caminiti <fox@foxcam.net>2023-01-24 21:52:25 -0500
commit5e0d4df53d9b657423ba59fd75b6476c8eca8be0 (patch)
tree2cfac2eaf2d1d69ebcfd8a02d4459696e8721f52
parent4261c7342d92ab259d563fcf96180905c112ec96 (diff)
rotation success!
-rw-r--r--src/imgui_ui_viewport.cpp208
-rw-r--r--src/prenderer.cpp10
2 files changed, 39 insertions, 179 deletions
diff --git a/src/imgui_ui_viewport.cpp b/src/imgui_ui_viewport.cpp
index 2604991..601b0f4 100644
--- a/src/imgui_ui_viewport.cpp
+++ b/src/imgui_ui_viewport.cpp
@@ -446,8 +446,6 @@ T_FindBestFit(int PointCount, v2 *PointData, v2 *Center, v2 *NewCenter, v2 *Best
return 0;
}
-static real32 bbb = 0;
-
static void
ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Memory, ui *UI, ImGuiIO &io, ImDrawList *draw_list,
int *PointCount, v2 *PointData, ImVec2 ViewportMin, uint32 CompWidth, uint32 CompHeight, uint16 *SortedKeyframeArray)
@@ -457,9 +455,10 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
v2 InteractMin = {};
v2 InteractMax = {};
real32 Rad = 0;
- real32 Rad2 = bbb;
+ real32 Rad2 = 0;
real32 Scale = 1;
+ aaa += 0.02;
if (Interact->Min.x == 0.0f) {
T_FindBestFit(*PointCount, PointData, &Interact->OGCenter, &Interact->NewCenter, &Interact->Min, &Interact->Max, &Interact->RadianOffset);
// Interact->RadianOffset +=
@@ -469,8 +468,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
if (Interact->Min.x != 0.0f) {
InteractMin = Interact->Min + Interact->Position;
InteractMax = Interact->Max + Interact->Position;
- Rad = Interact->RadianOffset; // + (aaa * (PI / 180));
- bbb += 0.08;
+ Rad = Interact->RadianOffset;
+ Rad2 = Interact->Radians;
Scale = Interact->Scale;
}
@@ -479,102 +478,23 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
DebugWatchVar("bestangle", &Angle, d_float);
v2 BoxLength = InteractMax - InteractMin;
- // v2 Center = (Interact->OGCenter.x != 0) ? Interact->OGCenter : InteractMax - (BoxLength/2);
- // v2 Center = (Interact->OGCenter.x != 0) ? Interact->OGCenter : InteractMax - (BoxLength/2);
- // v2 Center = InteractMax - (BoxLength/2) + V2(aaa, aaa);
-
-#if 0
- v2 Center = Interact->OGCenter;
-
- real32 Point0X = Center.x - InteractMin.x;
- real32 Point0Y = Center.y - InteractMin.y;
-
- v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
-
- // Points are clockwise starting from the top left.
- real32 X0 = -XAxis.x - YAxis.x + Center.x;
- real32 Y0 = -XAxis.y - YAxis.y + Center.y;
- real32 X1 = X0 + XAxis.x*2;
- real32 Y1 = Y0 + XAxis.y*2;
- real32 X2 = X1 + YAxis.x*2;
- real32 Y2 = Y1 + YAxis.y*2;
- real32 X3 = X2 - XAxis.x*2;
- real32 Y3 = Y2 - XAxis.y*2;
- // Midway points.
- real32 Mid_X0 = X0 + XAxis.x;
- real32 Mid_Y0 = Y0 + XAxis.y;
- real32 Mid_X1 = X1 + YAxis.x;
- real32 Mid_Y1 = Y1 + YAxis.y;
- real32 Mid_X2 = X2 - XAxis.x;
- real32 Mid_Y2 = Y2 - XAxis.y;
- real32 Mid_X3 = X3 - YAxis.x;
- real32 Mid_Y3 = Y3 - YAxis.y;
-#elif 0
v2 Center = Interact->OGCenter;
- v2 NewCenter = Interact->NewCenter;
- real32 X0 = Center.x;
- real32 Y0 = Center.y;
- real32 X1 = Center.x;
- real32 Y1 = Center.y;
- real32 X2 = Center.x;
- real32 Y2 = Center.y;
- real32 X3 = Center.x;
- real32 Y3 = Center.y;
+ v2 PosL[4] = {};
+ v2 PosS[4] = { InteractMin, V2(InteractMax.x, InteractMin.y), InteractMax, V2(InteractMin.x, InteractMax.y) };
+ v2 LocalCenter = InteractMax - (BoxLength/2);
+ v2 NewCenter = {};
{
- real32 Point0X = InteractMin.x - Center.x;
- real32 Point0Y = InteractMin.y - Center.y;
- v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
- v2 Pos = XAxis + YAxis;
- X0 += Pos.x;
- Y0 += Pos.y;
- }
- {
- real32 Point0X = InteractMax.x - Center.x;
- real32 Point0Y = InteractMin.y - Center.y;
- v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
- v2 Pos = XAxis + YAxis;
- X1 += Pos.x;
- Y1 += Pos.y;
- }
- {
- real32 Point0X = InteractMax.x - Center.x;
- real32 Point0Y = InteractMax.y - Center.y;
- v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
- v2 Pos = XAxis + YAxis;
- X2 += Pos.x;
- Y2 += Pos.y;
- }
- {
- real32 Point0X = InteractMin.x - Center.x;
- real32 Point0Y = InteractMax.y - Center.y;
+ real32 Point0X = LocalCenter.x - Center.x;
+ real32 Point0Y = LocalCenter.y - Center.y;
v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
v2 Pos = XAxis + YAxis;
- X3 += Pos.x;
- Y3 += Pos.y;
+ NewCenter.x = Center.x + Pos.x;
+ NewCenter.y = Center.y + Pos.y;
}
-#else
- v2 Center = Interact->OGCenter;
-
- v2 PosL[4] = {};
- v2 PosS[4] = { InteractMin, V2(InteractMax.x, InteractMin.y), InteractMax, V2(InteractMin.x, InteractMax.y) };
-
- v2 LocalCenter = InteractMax - (BoxLength/2);
- v2 NewCenter = {};
- real32 Point0X = LocalCenter.x - Center.x;
- real32 Point0Y = LocalCenter.y - Center.y;
- v2 XAxis = (Point0X * Scale)*V2(cos(Rad), sin(Rad));
- v2 YAxis = (Point0Y * Scale)*V2(sin(Rad), -cos(Rad));
- v2 Pos = XAxis + YAxis;
- NewCenter.x = Center.x + Pos.x;
- NewCenter.y = Center.y + Pos.y;
for (int i = 0; i < 4; i++) {
real32 Point0X = PosS[i].x - Center.x;
@@ -584,13 +504,15 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
v2 Pos = XAxis + YAxis;
PosL[i].x = Center.x + Pos.x;
PosL[i].y = Center.y + Pos.y;
- Point0X = PosL[i].x - NewCenter.x;
- Point0Y = PosL[i].y - NewCenter.y;
- XAxis = (Point0X * Scale)*V2(cos(Rad2), sin(Rad2));
- YAxis = (Point0Y * Scale)*V2(sin(Rad2), -cos(Rad2));
- v2 NewPos = XAxis + YAxis;
- PosL[i].x = NewCenter.x + NewPos.x;
- PosL[i].y = NewCenter.y + NewPos.y;
+ {
+ Point0X = PosL[i].x - NewCenter.x;
+ Point0Y = PosL[i].y - NewCenter.y;
+ XAxis = (Point0X * Scale)*V2(cos(Rad2), sin(Rad2));
+ YAxis = (Point0Y * -Scale)*V2(sin(Rad2), -cos(Rad2));
+ v2 NewPos = XAxis + YAxis;
+ PosL[i].x = NewCenter.x + NewPos.x;
+ PosL[i].y = NewCenter.y + NewPos.y;
+ }
}
ImVec2 CompScale = UI->CompZoom / ImVec2(CompWidth, CompHeight);
@@ -609,25 +531,8 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
draw_list->AddLine(P[0], P[2], wcol, 1.0f);
draw_list->AddLine(P[1], P[3], wcol, 1.0f);
-}
-
-#endif
#if 0
- ImVec2 CompScale = UI->CompZoom / ImVec2(CompWidth, CompHeight);
-
- ImVec2 P[4];
- P[0] = ImVec2(X0, Y0)*CompScale + UI->CompPos;
- P[1] = ImVec2(X1, Y1)*CompScale + UI->CompPos;
- P[2] = ImVec2(X2, Y2)*CompScale + UI->CompPos;
- P[3] = ImVec2(X3, Y3)*CompScale + UI->CompPos;
-
- // ImVec2 Mid_P[4];
- // Mid_P[0] = ImVec2(Mid_X0, Mid_Y0)*CompScale + UI->CompPos;
- // Mid_P[1] = ImVec2(Mid_X1, Mid_Y1)*CompScale + UI->CompPos;
- // Mid_P[2] = ImVec2(Mid_X2, Mid_Y2)*CompScale + UI->CompPos;
- // Mid_P[3] = ImVec2(Mid_X3, Mid_Y3)*CompScale + UI->CompPos;
-
{
ImU32 wcol = IM_COL32(0, 0, 255, 255);
v2 Min = V2(10000, 10000), Max = V2(-10000, -10000);
@@ -676,15 +581,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
draw_list->AddLine(P[2], P[3], wcol, 2.0f);
draw_list->AddLine(P[3], P[0], wcol, 2.0f);
}
-
- ImU32 wcol = ImGui::GetColorU32(ImGuiCol_Text);
- draw_list->AddLine(P[0], P[1], wcol, 2.0f);
- draw_list->AddLine(P[1], P[2], wcol, 2.0f);
- draw_list->AddLine(P[2], P[3], wcol, 2.0f);
- draw_list->AddLine(P[3], P[0], wcol, 2.0f);
-
- draw_list->AddLine(P[0], P[2], wcol, 1.0f);
- draw_list->AddLine(P[1], P[3], wcol, 1.0f);
+#endif
v2 XAxis2 = (BoxLength*CompScale.x)*V2(cos(Rad), sin(Rad));
v2 YAxis2 = (BoxLength*CompScale.y)*V2(sin(Rad), -cos(Rad));
@@ -753,10 +650,11 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
ImGui::Button("##ScaleRotateCorners", ScaleHandleSize);
if (ImGui::IsItemActivated() && !OtherActions) {
- if (InBounds)
- State->InteractTransformMode = 1;
- else
- State->InteractTransformMode = 2;
+ State->InteractTransformMode = 2;
+ // if (InBounds)
+ // State->InteractTransformMode = 1;
+ // else
+ // State->InteractTransformMode = 2;
State->Interact_Active = interact_type_viewport_transform_gizmo;
}
@@ -805,58 +703,10 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
Interact->Radians = Direction * MouseRadians;
}
-#endif
-
-#if 0
- real32 Slope_Mouse = LocalY/LocalX;
- real32 Slope_Corner = 0;
- real32 Slope_Flipped = 0;
- real32 Dot = 0;
-
- // TODO(fox) learn basic geometry to do this properly
-
- // We find the angle between the direction of whichever corner the
- // mouse is grabbing (Slope_Corner) and the mouse's current
- // position (Slope_Mouse) to get ExtraRadians. The calculation only
- // works between -90 and 90, so I take the dot product of the
- // opposite edge of the corner and add the extra degrees when it's negative.
-
- v2 SlopeDot = V2(BoxLength.x, BoxLength.y);
- // top left clockwise
- uint32 side = i;
- if (side == 0) {
- Slope_Corner = BoxLength.y / BoxLength.x;
- Slope_Flipped = -BoxLength.x / BoxLength.y;
- Dot = LocalX * -SlopeDot.x + LocalY * -SlopeDot.y;
- } else if (side == 1) {
- Slope_Corner = -BoxLength.y / BoxLength.x;
- Slope_Flipped = BoxLength.x / BoxLength.y;
- Dot = LocalX * SlopeDot.x + LocalY * -SlopeDot.y;
- } else if (side == 2) {
- Slope_Corner = BoxLength.y / BoxLength.x;
- Slope_Flipped = -BoxLength.x / BoxLength.y;
- Dot = LocalX * SlopeDot.x + LocalY * SlopeDot.y;
- } else if (side == 3) {
- Slope_Corner = -BoxLength.y / BoxLength.x;
- Slope_Flipped = BoxLength.x / BoxLength.y;
- Dot = LocalX * -SlopeDot.x + LocalY * SlopeDot.y;
- }
-
- Interact->Radians = atan((Slope_Mouse - Slope_Corner) / (1 + Slope_Mouse * Slope_Corner));
- real32 ExtraRadians2 = atan((Slope_Mouse - Slope_Flipped) / (1 + Slope_Mouse * Slope_Flipped));
-
- if (Dot < 0) {
- if (Interact->Radians < 0) {
- Interact->Radians = (90 * (PI / 180)) + ExtraRadians2;
- } else {
- Interact->Radians = (-90 * (PI / 180)) + ExtraRadians2;
- }
- }
- }
-
ImGui::PopID();
}
+
if (InBounds && !io.KeyAlt) {
ImGui::SetCursorScreenPos(io.MousePos - ScaleHandleSize/2);
ImGui::Button("##mover", ScaleHandleSize);
@@ -904,7 +754,7 @@ ImGui_Viewport_TransformUI2(project_data *File, project_state *State, memory *Me
if (InBounds == true) {
ImGui::PopStyleColor();
}
-#endif
+}
static void
diff --git a/src/prenderer.cpp b/src/prenderer.cpp
index 1d8f512..37fb113 100644
--- a/src/prenderer.cpp
+++ b/src/prenderer.cpp
@@ -67,6 +67,16 @@ Transform_ApplyInteractive(interact_transform Interact, real32 *OutputX, real32
{
v2 BoxLength = Interact.Max - Interact.Min;
v2 Center = Interact.Max - (BoxLength/2);
+ if (Interact.RadianOffset != 0.0f && Interact.Radians != 0.0f) {
+ v2 LocalCenter = Interact.NewCenter;
+ real32 Rad = Interact.RadianOffset;
+ real32 Point0X = Center.x - Interact.OGCenter.x;
+ real32 Point0Y = Center.y - Interact.OGCenter.y;
+ v2 XAxis = (Point0X * Interact.Scale)*V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point0Y * Interact.Scale)*V2(sin(Rad), -cos(Rad));
+ Center = Interact.OGCenter + XAxis + YAxis;
+ }
+
real32 Point0X = Center.x - *OutputX;
real32 Point0Y = Center.y - *OutputY;