2007-07-01 04:46:12 +02:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-07-01 04:46:12 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @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"
|
|
|
|
|
2010-05-19 05:24:01 +02:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <math.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-01 04:46:12 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2011-01-16 08:17:36 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2007-07-01 04:46:12 +02:00
|
|
|
#include "utils.h"
|
2010-06-18 09:14:00 +02:00
|
|
|
#include "video_context.h"
|
2009-09-10 03:41:34 +02:00
|
|
|
#include "video_display.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatexy.h"
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2011-01-16 08:17:08 +01:00
|
|
|
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *parent, agi::Context *context, VideoState const& video, wxToolBar *)
|
|
|
|
: VisualTool<VisualDraggableFeature>(parent, context, video)
|
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-27 06:50:15 +02:00
|
|
|
DoRefresh();
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateXY::Draw() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Pivot coordinates
|
|
|
|
int dx=0,dy=0;
|
2010-06-28 09:13:15 +02:00
|
|
|
if (dragging) GetLinePosition(curDiag,dx,dy);
|
2010-06-30 08:29:14 +02:00
|
|
|
else GetLinePosition(curDiag,dx,dy,org->x,org->y);
|
|
|
|
dx = org->x;
|
|
|
|
dy = org->y;
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
SetLineColour(colour[0]);
|
|
|
|
SetFillColour(colour[1],0.3f);
|
|
|
|
|
|
|
|
// Draw pivot
|
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
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2010-06-28 09:13:15 +02:00
|
|
|
glTranslatef(dx,dy,0.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
|
|
|
|
glMultMatrixf(matrix);
|
2010-06-28 09:13:15 +02:00
|
|
|
glScalef(1.f,1.f,8.f);
|
|
|
|
if (curAngleY != 0.f) glRotatef(curAngleY,0.f,-1.f,0.f);
|
|
|
|
if (curAngleX != 0.f) glRotatef(curAngleX,-1.f,0.f,0.f);
|
|
|
|
if (curAngleZ != 0.f) glRotatef(curAngleZ,0.f,0.f,-1.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Draw grid
|
|
|
|
glShadeModel(GL_SMOOTH);
|
2007-07-04 22:25:24 +02:00
|
|
|
SetLineColour(colour[0],0.5f,2);
|
2007-07-01 04:46:12 +02:00
|
|
|
SetModeLine();
|
2010-06-28 09:13:15 +02:00
|
|
|
float r = colour[0].Red()/255.f;
|
|
|
|
float g = colour[0].Green()/255.f;
|
|
|
|
float b = colour[0].Blue()/255.f;
|
2007-07-01 04:46:12 +02:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
for (int i=0;i<11;i++) {
|
2010-06-28 09:13:15 +02:00
|
|
|
float a = 1.f - abs(i-5)*0.18f;
|
2007-07-01 04:46:12 +02:00
|
|
|
int pos = 20*(i-5);
|
2010-06-28 09:13:15 +02:00
|
|
|
glColor4f(r,g,b,0.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glVertex2i(pos,120);
|
|
|
|
glColor4f(r,g,b,a);
|
|
|
|
glVertex2i(pos,0);
|
|
|
|
glVertex2i(pos,0);
|
2010-06-28 09:13:15 +02:00
|
|
|
glColor4f(r,g,b,0.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glVertex2i(pos,-120);
|
|
|
|
glVertex2i(120,pos);
|
|
|
|
glColor4f(r,g,b,a);
|
|
|
|
glVertex2i(0,pos);
|
|
|
|
glVertex2i(0,pos);
|
2010-06-28 09:13:15 +02:00
|
|
|
glColor4f(r,g,b,0.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glVertex2i(-120,pos);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Draw vectors
|
2010-06-28 09:13:15 +02:00
|
|
|
SetLineColour(colour[3],1.f,2);
|
2007-07-01 04:46:12 +02:00
|
|
|
SetModeLine();
|
|
|
|
glBegin(GL_LINES);
|
2010-06-28 09:13:15 +02:00
|
|
|
glVertex3f(0.f,0.f,0.f);
|
|
|
|
glVertex3f(50.f,0.f,0.f);
|
|
|
|
glVertex3f(0.f,0.f,0.f);
|
|
|
|
glVertex3f(0.f,50.f,0.f);
|
|
|
|
glVertex3f(0.f,0.f,0.f);
|
|
|
|
glVertex3f(0.f,0.f,50.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Draw arrow tops
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
2010-06-28 09:13:15 +02:00
|
|
|
glVertex3f(60.f,0.f,0.f);
|
|
|
|
glVertex3f(50.f,-3.f,-3.f);
|
|
|
|
glVertex3f(50.f,3.f,-3.f);
|
|
|
|
glVertex3f(50.f,3.f,3.f);
|
|
|
|
glVertex3f(50.f,-3.f,3.f);
|
|
|
|
glVertex3f(50.f,-3.f,-3.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glEnd();
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
2010-06-28 09:13:15 +02:00
|
|
|
glVertex3f(0.f,60.f,0.f);
|
|
|
|
glVertex3f(-3.f,50.f,-3.f);
|
|
|
|
glVertex3f(3.f,50.f,-3.f);
|
|
|
|
glVertex3f(3.f,50.f,3.f);
|
|
|
|
glVertex3f(-3.f,50.f,3.f);
|
|
|
|
glVertex3f(-3.f,50.f,-3.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glEnd();
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
2010-06-28 09:13:15 +02:00
|
|
|
glVertex3f(0.f,0.f,60.f);
|
|
|
|
glVertex3f(-3.f,-3.f,50.f);
|
|
|
|
glVertex3f(3.f,-3.f,50.f);
|
|
|
|
glVertex3f(3.f,3.f,50.f);
|
|
|
|
glVertex3f(-3.f,3.f,50.f);
|
|
|
|
glVertex3f(-3.f,-3.f,50.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolRotateXY::InitializeHold() {
|
2010-06-30 08:29:14 +02:00
|
|
|
startAngleX = (org->y-video.y)*2.f;
|
|
|
|
startAngleY = (video.x-org->x)*2.f;
|
2010-06-28 09:13:15 +02:00
|
|
|
origAngleX = curAngleX;
|
|
|
|
origAngleY = curAngleY;
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
return true;
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateXY::UpdateHold() {
|
2010-06-30 08:29:14 +02:00
|
|
|
float screenAngleX = (org->y-video.y)*2.f;
|
|
|
|
float screenAngleY = (video.x-org->x)*2.f;
|
2007-07-01 04:46:12 +02:00
|
|
|
|
2007-07-04 22:45:01 +02:00
|
|
|
// Deltas
|
|
|
|
float deltaX = screenAngleX - startAngleX;
|
|
|
|
float deltaY = screenAngleY - startAngleY;
|
2010-05-19 05:24:01 +02:00
|
|
|
if (shiftDown) {
|
2010-06-01 05:21:14 +02:00
|
|
|
if (fabs(deltaX) >= fabs(deltaY)) deltaY = 0.f;
|
|
|
|
else deltaX = 0.f;
|
2007-07-04 22:45:01 +02:00
|
|
|
}
|
|
|
|
|
2007-07-01 04:46:12 +02:00
|
|
|
// Calculate
|
2010-06-01 05:21:14 +02:00
|
|
|
curAngleX = fmodf(deltaX + origAngleX + 360.f, 360.f);
|
|
|
|
curAngleY = fmodf(deltaY + origAngleY + 360.f, 360.f);
|
2007-07-01 04:46:12 +02:00
|
|
|
|
|
|
|
// Oh Snap
|
2010-05-19 05:24:01 +02:00
|
|
|
if (ctrlDown) {
|
2010-06-01 05:21:14 +02:00
|
|
|
curAngleX = floorf(curAngleX/30.f+.5f)*30.f;
|
|
|
|
curAngleY = floorf(curAngleY/30.f+.5f)*30.f;
|
|
|
|
if (curAngleX > 359.f) curAngleX = 0.f;
|
|
|
|
if (curAngleY > 359.f) curAngleY = 0.f;
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateXY::CommitHold() {
|
2011-01-16 08:17:36 +01:00
|
|
|
Selection sel = c->selectionController->GetSelectedSet();
|
2010-06-28 09:39:36 +02:00
|
|
|
for (Selection::const_iterator cur = sel.begin(); cur != sel.end(); ++cur) {
|
2011-09-28 21:43:11 +02:00
|
|
|
SetOverride(*cur, "\\frx",wxString::Format("(%0.3g)",curAngleX));
|
|
|
|
SetOverride(*cur, "\\fry",wxString::Format("(%0.3g)",curAngleY));
|
2010-06-18 09:14:00 +02:00
|
|
|
}
|
2007-07-01 04:46:12 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolRotateXY::CommitDrag(feature_iterator feature) {
|
2010-05-20 10:55:58 +02:00
|
|
|
int x = feature->x;
|
|
|
|
int y = feature->y;
|
2010-05-16 08:39:11 +02:00
|
|
|
parent->ToScriptCoords(&x, &y);
|
2011-09-28 21:43:11 +02:00
|
|
|
SetOverride(curDiag, "\\org",wxString::Format("(%i,%i)",x,y));
|
2007-07-04 23:47:26 +02:00
|
|
|
}
|
2007-07-27 06:50:15 +02:00
|
|
|
|
|
|
|
void VisualToolRotateXY::DoRefresh() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
|
|
|
int posx, posy;
|
2010-06-30 08:29:14 +02:00
|
|
|
GetLinePosition(curDiag,posx,posy,org->x,org->y);
|
2010-06-28 09:13:15 +02:00
|
|
|
GetLineRotation(curDiag,curAngleX,curAngleY,curAngleZ);
|
2007-07-27 06:50:15 +02:00
|
|
|
}
|