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"
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#include <cmath>
|
2010-05-19 05:24:01 +02:00
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatexy.h"
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualTool<VisualDraggableFeature>(parent, context)
|
2012-10-15 06:37:14 +02:00
|
|
|
, angle_x(0)
|
|
|
|
, angle_y(0)
|
|
|
|
, angle_z(0)
|
|
|
|
, orig_x(0)
|
|
|
|
, orig_y(0)
|
2007-07-01 04:46:12 +02:00
|
|
|
{
|
2010-06-30 08:29:14 +02:00
|
|
|
features.resize(1);
|
|
|
|
org = &features.back();
|
|
|
|
org->type = DRAG_BIG_TRIANGLE;
|
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);
|
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;
|
|
|
|
|
|
|
|
std::vector<float> colors(11 * 8 * 4);
|
|
|
|
for (int i = 0; i < 88; ++i) {
|
|
|
|
colors[i * 4 + 0] = r;
|
|
|
|
colors[i * 4 + 1] = g;
|
|
|
|
colors[i * 4 + 2] = b;
|
|
|
|
colors[i * 4 + 3] = (i + 3) % 4 > 1 ? 0 : (1.f - abs(i / 8 - 5) * 0.18f);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<float> points(11 * 8 * 2);
|
|
|
|
for (int i = 0; i < 11; ++i) {
|
|
|
|
int pos = 20 * (i - 5);
|
|
|
|
|
|
|
|
points[i * 16 + 0] = pos;
|
|
|
|
points[i * 16 + 1] = 120;
|
|
|
|
|
|
|
|
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;
|
|
|
|
points[i * 16 + 7] = -120;
|
|
|
|
|
|
|
|
points[i * 16 + 8] = 120;
|
|
|
|
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;
|
|
|
|
|
|
|
|
points[i * 16 + 14] = -120;
|
|
|
|
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);
|
|
|
|
|
2011-12-22 22:23:26 +01:00
|
|
|
SetSelectedOverride("\\frx", wxString::Format("%.4g", angle_x));
|
|
|
|
SetSelectedOverride("\\fry", wxString::Format("%.4g", angle_y));
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolRotateXY::UpdateDrag(feature_iterator feature) {
|
|
|
|
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);
|
2007-07-27 06:50:15 +02:00
|
|
|
}
|