Fixed rotate z and re-implemented rotate xy.

Originally committed to SVN as r1327.
This commit is contained in:
Rodrigo Braz Monteiro 2007-07-01 02:46:12 +00:00
parent a1050db3f3
commit d06fdfda65
5 changed files with 292 additions and 3 deletions

View File

@ -216,6 +216,7 @@ aegisub_SOURCES = \
visual_feature.cpp \
visual_tool.cpp \
visual_tool_cross.cpp \
visual_tool_rotatexy.cpp \
visual_tool_rotatez.cpp \
MatroskaParser.c

View File

@ -70,6 +70,7 @@
#include "visual_tool.h"
#include "visual_tool_cross.h"
#include "visual_tool_rotatez.h"
#include "visual_tool_rotatexy.h"
///////
@ -648,7 +649,7 @@ void VideoDisplay::SetVisualMode(int mode) {
case 0: visual = new VisualToolCross(this); break;
//case 1: visual = new VisualToolDrag(this); break;
case 2: visual = new VisualToolRotateZ(this); break;
//case 3: visual = new VisualToolRotateXY(this); break;
case 3: visual = new VisualToolRotateXY(this); break;
//case 4: visual = new VisualToolScale(this); break;
//case 5: visual = new VisualToolClip(this); break;
default: visual = NULL;

View File

@ -0,0 +1,224 @@
// 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.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include "visual_tool_rotatexy.h"
#include "subs_grid.h"
#include "subs_edit_box.h"
#include "ass_file.h"
#include "ass_dialogue.h"
#include "utils.h"
///////////////
// Constructor
VisualToolRotateXY::VisualToolRotateXY(VideoDisplay *_parent)
: VisualTool(_parent)
{
_parent->ShowCursor(false);
}
//////////
// Update
void VisualToolRotateXY::Update() {
// Render parent
GetParent()->Render();
}
////////
// Draw
void VisualToolRotateXY::Draw() {
// Get line to draw
AssDialogue *line = GetActiveDialogueLine();
if (!line) return;
// Pivot coordinates
int dx=0,dy=0;
GetLinePosition(line,dx,dy,orgx,orgy);
dx = orgx;
dy = orgy;
// Rotation
float rx,ry;
GetLineRotation(line,rx,ry,rz);
if (line == curDiag) {
rx = curAngleX;
ry = curAngleY;
}
// Set colours
SetLineColour(colour[0]);
SetFillColour(colour[1],0.3f);
// Draw pivot
DrawCircle(dx,dy,7);
DrawLine(dx,dy-16,dx,dy+16);
DrawLine(dx-16,dy,dx+16,dy);
// Transform grid
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(dx,dy,0.0f);
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
glMultMatrixf(matrix);
glScalef(1.0f,1.0f,8.0f);
if (ry != 0.0f) glRotatef(ry,0.0f,-1.0f,0.0f);
if (rx != 0.0f) glRotatef(rx,-1.0f,0.0f,0.0f);
if (rz != 0.0f) glRotatef(rz,0.0f,0.0f,-1.0f);
// Draw grid
glShadeModel(GL_SMOOTH);
SetLineColour(colour[0],0.5f,1);
SetModeLine();
float r = colour[0].Red()/255.0f;
float g = colour[0].Green()/255.0f;
float b = colour[0].Blue()/255.0f;
glBegin(GL_LINES);
for (int i=0;i<11;i++) {
float a = 1.0f - abs(i-5)*0.18f;
int pos = 20*(i-5);
glColor4f(r,g,b,0.0f);
glVertex2i(pos,120);
glColor4f(r,g,b,a);
glVertex2i(pos,0);
glVertex2i(pos,0);
glColor4f(r,g,b,0.0f);
glVertex2i(pos,-120);
glVertex2i(120,pos);
glColor4f(r,g,b,a);
glVertex2i(0,pos);
glVertex2i(0,pos);
glColor4f(r,g,b,0.0f);
glVertex2i(-120,pos);
}
glEnd();
// Draw vectors
SetLineColour(colour[3],1.0f,2);
SetModeLine();
glBegin(GL_LINES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(50.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,-50.0f,0.0f);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,-50.0f);
glEnd();
// Draw arrow tops
glBegin(GL_TRIANGLE_FAN);
glVertex3f(60.0f,0.0f,0.0f);
glVertex3f(50.0f,-3.0f,-3.0f);
glVertex3f(50.0f,3.0f,-3.0f);
glVertex3f(50.0f,3.0f,3.0f);
glVertex3f(50.0f,-3.0f,3.0f);
glVertex3f(50.0f,-3.0f,-3.0f);
glEnd();
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f,-60.0f,0.0f);
glVertex3f(-3.0f,-50.0f,-3.0f);
glVertex3f(3.0f,-50.0f,-3.0f);
glVertex3f(3.0f,-50.0f,3.0f);
glVertex3f(-3.0f,-50.0f,3.0f);
glVertex3f(-3.0f,-50.0f,-3.0f);
glEnd();
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0f,0.0f,-60.0f);
glVertex3f(-3.0f,-3.0f,-50.0f);
glVertex3f(3.0f,-3.0f,-50.0f);
glVertex3f(3.0f,3.0f,-50.0f);
glVertex3f(-3.0f,3.0f,-50.0f);
glVertex3f(-3.0f,-3.0f,-50.0f);
glEnd();
// Restore gl's state
glPopMatrix();
glShadeModel(GL_FLAT);
}
/////////////////
// Start holding
void VisualToolRotateXY::InitializeHold() {
GetLinePosition(curDiag,odx,ody,orgx,orgy);
GetLineRotation(curDiag,origAngleX,origAngleY,rz);
startAngleX = (orgy-mouseY*sh/h)*2.0;
startAngleY = (mouseX*sw/w-orgx)*2.0;
curAngleX = origAngleX;
curAngleY = origAngleY;
curDiag->StripTag(_T("\\frx"));
curDiag->StripTag(_T("\\fry"));
}
///////////////
// Update hold
void VisualToolRotateXY::UpdateHold() {
// Find screen angles
float screenAngleX = (orgy-mouseY*sh/h)*2.0;
float screenAngleY = (mouseX*sw/w-orgx)*2.0;
// Calculate
curAngleX = screenAngleX - startAngleX + origAngleX;
curAngleY = screenAngleY - startAngleY + origAngleY;
while (curAngleX < 0.0) curAngleX += 360.0;
while (curAngleX >= 360.0) curAngleX -= 360.0;
while (curAngleY < 0.0) curAngleY += 360.0;
while (curAngleY >= 360.0) curAngleY -= 360.0;
// Oh Snap
if (shiftDown) {
curAngleX = (float)((int)((curAngleX+15.0f)/30.0f))*30.0f;
curAngleY = (float)((int)((curAngleY+15.0f)/30.0f))*30.0f;
if (curAngleX == 360.0f) curAngleX = 0.0f;
if (curAngleY == 360.0f) curAngleX = 0.0f;
}
}
///////////////
// Commit hold
void VisualToolRotateXY::CommitHold() {
VideoContext::Get()->grid->editBox->SetOverride(_T("\\frx"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curAngleX)),0,false);
VideoContext::Get()->grid->editBox->SetOverride(_T("\\fry"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curAngleY)),0,false);
}

View File

@ -0,0 +1,64 @@
// 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.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#pragma once
///////////
// Headers
#include "visual_tool.h"
//////////////////////////
// XY Rotation tool class
class VisualToolRotateXY : public VisualTool {
private:
float curAngleX,startAngleX,origAngleX;
float curAngleY,startAngleY,origAngleY;
int orgx,orgy,odx,ody;
float rz;
bool CanHold() { return true; }
void InitializeHold();
void UpdateHold();
void CommitHold();
public:
VisualToolRotateXY(VideoDisplay *parent);
void Update();
void Draw();
};

View File

@ -40,7 +40,6 @@
///////////
// Headers
#include "visual_tool_rotatez.h"
#include "gl_text.h"
#include "subs_grid.h"
#include "subs_edit_box.h"
#include "ass_file.h"
@ -144,7 +143,7 @@ void VisualToolRotateZ::Draw() {
DrawLine(0,0,fx,fy);
int mdx = int(cos(rz*3.1415926536/180.0)*20);
int mdy = int(-sin(rz*3.1415926536/180.0)*20);
DrawLine(-mdx,-mdy,mdx,mdy);
DrawLine(fx-mdx,fy-mdy,fx+mdx,fy+mdy);
}
// Draw the rotation line