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-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatexy.h"
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
#include <cmath>
|
|
|
|
|
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
|
|
|
|
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
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[0], 0.5f, 2);
|
|
|
|
gl.SetModeLine();
|
|
|
|
float r = colour[0].Red() / 255.f;
|
|
|
|
float g = colour[0].Green() / 255.f;
|
|
|
|
float b = colour[0].Blue() / 255.f;
|
|
|
|
|
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
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[3], 1.f, 2);
|
|
|
|
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);
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
SetSelectedOverride("\\frx", str(boost::format("%.4g") % angle_x));
|
|
|
|
SetSelectedOverride("\\fry", str(boost::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) {
|
2011-11-06 18:18:20 +01:00
|
|
|
SetOverride(active_line, "\\org", ToScriptCoords(feature->pos).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
|
|
|
}
|