2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-07-01 04:46:12 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-07-01 04:46:12 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-07-01 04:46:12 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file visual_tool_rotatexy.cpp
|
|
|
|
/// @brief 3D rotation in X/Y axes visual typesetting tool
|
|
|
|
/// @ingroup visual_ts
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatexy.h"
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "compat.h"
|
2014-06-29 20:39:51 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "options.h"
|
2014-06-29 20:39:51 +02:00
|
|
|
#include "selection_controller.h"
|
|
|
|
|
2014-05-29 00:19:05 +02:00
|
|
|
#include <libaegisub/format.h>
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <cmath>
|
2014-05-23 00:40:16 +02:00
|
|
|
#include <wx/colour.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualTool<VisualDraggableFeature>(parent, context)
|
2007-07-01 04:46:12 +02:00
|
|
|
{
|
2013-09-17 20:13:52 +02:00
|
|
|
org = new Feature;
|
2010-06-30 08:29:14 +02:00
|
|
|
org->type = DRAG_BIG_TRIANGLE;
|
2013-09-17 20:13:52 +02:00
|
|
|
features.push_back(*org);
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateXY::Draw() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!active_line) return;
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2007-07-04 23:47:26 +02:00
|
|
|
DrawAllFeatures();
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2018-04-15 23:59:32 +02:00
|
|
|
// Load colors from options
|
|
|
|
wxColour line_color_primary = to_wx(line_color_primary_opt->GetColor());
|
|
|
|
wxColour line_color_secondary = to_wx(line_color_secondary_opt->GetColor());
|
|
|
|
|
2007-07-01 04:46:12 +02:00
|
|
|
// Transform grid
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetOrigin(org->pos);
|
|
|
|
gl.SetRotation(angle_x, angle_y, angle_z);
|
2013-12-14 16:45:26 +01:00
|
|
|
gl.SetShear(fax, fay);
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Draw grid
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_secondary, 0.5f, 2);
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetModeLine();
|
2018-04-15 23:59:32 +02:00
|
|
|
float r = line_color_secondary.Red() / 255.f;
|
|
|
|
float g = line_color_secondary.Green() / 255.f;
|
|
|
|
float b = line_color_secondary.Blue() / 255.f;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2013-12-14 04:13:35 +01:00
|
|
|
// Number of lines on each side of each axis
|
2013-12-14 04:51:43 +01:00
|
|
|
static const int radius = 15;
|
2013-12-14 04:13:35 +01:00
|
|
|
// Total number of lines, including center axis line
|
|
|
|
static const int line_count = radius * 2 + 1;
|
|
|
|
// Distance between each line in pixels
|
|
|
|
static const int spacing = 20;
|
|
|
|
// Length of each grid line in pixels from axis to one end
|
|
|
|
static const int half_line_length = spacing * (radius + 1);
|
|
|
|
static const float fade_factor = 0.9f / radius;
|
|
|
|
|
|
|
|
std::vector<float> colors(line_count * 8 * 4);
|
|
|
|
for (int i = 0; i < line_count * 8; ++i) {
|
2011-11-06 18:18:20 +01:00
|
|
|
colors[i * 4 + 0] = r;
|
|
|
|
colors[i * 4 + 1] = g;
|
|
|
|
colors[i * 4 + 2] = b;
|
2013-12-14 04:13:35 +01:00
|
|
|
colors[i * 4 + 3] = (i + 3) % 4 > 1 ? 0 : (1.f - abs(i / 8 - radius) * fade_factor);
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
2013-12-14 04:13:35 +01:00
|
|
|
std::vector<float> points(line_count * 8 * 2);
|
|
|
|
for (int i = 0; i < line_count; ++i) {
|
|
|
|
int pos = spacing * (i - radius);
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
points[i * 16 + 0] = pos;
|
2013-12-14 04:13:35 +01:00
|
|
|
points[i * 16 + 1] = half_line_length;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
points[i * 16 + 2] = pos;
|
|
|
|
points[i * 16 + 3] = 0;
|
|
|
|
|
|
|
|
points[i * 16 + 4] = pos;
|
|
|
|
points[i * 16 + 5] = 0;
|
|
|
|
|
|
|
|
points[i * 16 + 6] = pos;
|
2013-12-14 04:13:35 +01:00
|
|
|
points[i * 16 + 7] = -half_line_length;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2013-12-14 04:13:35 +01:00
|
|
|
points[i * 16 + 8] = half_line_length;
|
2011-11-06 18:18:20 +01:00
|
|
|
points[i * 16 + 9] = pos;
|
|
|
|
|
|
|
|
points[i * 16 + 10] = 0;
|
|
|
|
points[i * 16 + 11] = pos;
|
|
|
|
|
|
|
|
points[i * 16 + 12] = 0;
|
|
|
|
points[i * 16 + 13] = pos;
|
|
|
|
|
2013-12-14 04:13:35 +01:00
|
|
|
points[i * 16 + 14] = -half_line_length;
|
2011-11-06 18:18:20 +01:00
|
|
|
points[i * 16 + 15] = pos;
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
gl.DrawLines(2, points, 4, colors);
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Draw vectors
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_primary, 1.f, 2);
|
2011-11-06 18:18:20 +01:00
|
|
|
float vectors[] = {
|
|
|
|
0.f, 0.f, 0.f,
|
|
|
|
50.f, 0.f, 0.f,
|
|
|
|
0.f, 0.f, 0.f,
|
|
|
|
0.f, 50.f, 0.f,
|
|
|
|
0.f, 0.f, 0.f,
|
|
|
|
0.f, 0.f, 50.f,
|
|
|
|
};
|
|
|
|
gl.DrawLines(3, vectors, 6);
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Draw arrow tops
|
2011-11-06 18:18:20 +01:00
|
|
|
float arrows[] = {
|
|
|
|
60.f, 0.f, 0.f,
|
|
|
|
50.f, -3.f, -3.f,
|
|
|
|
50.f, 3.f, -3.f,
|
|
|
|
50.f, 3.f, 3.f,
|
|
|
|
50.f, -3.f, 3.f,
|
|
|
|
50.f, -3.f, -3.f,
|
|
|
|
|
|
|
|
0.f, 60.f, 0.f,
|
|
|
|
-3.f, 50.f, -3.f,
|
|
|
|
3.f, 50.f, -3.f,
|
|
|
|
3.f, 50.f, 3.f,
|
|
|
|
-3.f, 50.f, 3.f,
|
|
|
|
-3.f, 50.f, -3.f,
|
|
|
|
|
|
|
|
0.f, 0.f, 60.f,
|
|
|
|
-3.f, -3.f, 50.f,
|
|
|
|
3.f, -3.f, 50.f,
|
|
|
|
3.f, 3.f, 50.f,
|
|
|
|
-3.f, 3.f, 50.f,
|
|
|
|
-3.f, -3.f, 50.f,
|
|
|
|
};
|
|
|
|
|
|
|
|
gl.DrawLines(3, arrows, 18);
|
|
|
|
|
|
|
|
gl.ResetTransform();
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolRotateXY::InitializeHold() {
|
2011-11-06 18:18:20 +01:00
|
|
|
orig_x = angle_x;
|
|
|
|
orig_y = angle_y;
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
return true;
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateXY::UpdateHold() {
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D delta = (mouse_pos - drag_start) * 2;
|
|
|
|
if (shift_down)
|
|
|
|
delta = delta.SingleAxis();
|
2007-07-04 22:45:01 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
angle_x = orig_x - delta.Y();
|
|
|
|
angle_y = orig_y + delta.X();
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (ctrl_down) {
|
|
|
|
angle_x = floorf(angle_x / 30.f + .5f) * 30.f;
|
|
|
|
angle_y = floorf(angle_y / 30.f + .5f) * 30.f;
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
angle_x = fmodf(angle_x + 360.f, 360.f);
|
|
|
|
angle_y = fmodf(angle_y + 360.f, 360.f);
|
|
|
|
|
2014-05-29 00:19:05 +02:00
|
|
|
SetSelectedOverride("\\frx", agi::format("%.4g", angle_x));
|
|
|
|
SetSelectedOverride("\\fry", agi::format("%.4g", angle_y));
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
2013-09-17 20:13:52 +02:00
|
|
|
void VisualToolRotateXY::UpdateDrag(Feature *feature) {
|
2014-06-29 20:39:51 +02:00
|
|
|
auto org = GetLineOrigin(active_line);
|
|
|
|
if (!org) org = GetLinePosition(active_line);
|
|
|
|
auto d = ToScriptCoords(feature->pos) - org;
|
|
|
|
|
|
|
|
for (auto line : c->selectionController->GetSelectedSet()) {
|
|
|
|
org = GetLineOrigin(line);
|
|
|
|
if (!org) org = GetLinePosition(line);
|
|
|
|
SetOverride(line, "\\org", (d + org).PStr());
|
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
}
|
2007-07-27 06:50:15 +02:00
|
|
|
|
|
|
|
void VisualToolRotateXY::DoRefresh() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!active_line) return;
|
|
|
|
|
|
|
|
if (!(org->pos = GetLineOrigin(active_line)))
|
|
|
|
org->pos = GetLinePosition(active_line);
|
|
|
|
org->pos = FromScriptCoords(org->pos);
|
|
|
|
|
|
|
|
GetLineRotation(active_line, angle_x, angle_y, angle_z);
|
2013-12-14 16:45:26 +01:00
|
|
|
GetLineShear(active_line, fax, fay);
|
2007-07-27 06:50:15 +02:00
|
|
|
}
|