LibreOffice Module slideshow (master) 1
Operation.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2015 by Collabora, Ltd.
7 *
8 * OpenOffice.org - a multi-platform office productivity suite
9 *
10 * This file is part of OpenOffice.org.
11 *
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
15 *
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
26 *
27 ************************************************************************/
28
29#include <sal/config.h>
30
31#include "Operation.hxx"
32
34
35#include <glm/gtc/matrix_transform.hpp>
36#include <glm/gtc/type_ptr.hpp>
37
38SRotate::SRotate(const glm::vec3& Axis, const glm::vec3& Origin,
39 double Angle, bool bInter, double T0, double T1):
40 Operation(bInter, T0, T1),
41 axis(Axis),
42 origin(Origin),
43 angle(basegfx::deg2rad(Angle))
44{
45}
46
47SScale::SScale(const glm::vec3& Scale, const glm::vec3& Origin,
48 bool bInter, double T0, double T1):
49 Operation(bInter, T0, T1),
50 scale(Scale),
51 origin(Origin)
52{
53}
54
56 const glm::vec3& Origin, double Angle, bool bScale, bool bInter, double T0, double T1):
57 Operation(bInter, T0, T1),
58 axis(Axis),
59 origin(Origin),
60 angle(basegfx::deg2rad(Angle)),
61 scale(bScale)
62{
63}
64
66 const glm::vec3& Origin, double Angle, bool bScale, bool bInter, double T0, double T1):
67 Operation(bInter, T0, T1),
68 axis(Axis),
69 origin(Origin),
70 angle(basegfx::deg2rad(Angle)),
71 scale(bScale)
72{
73}
74
75
76STranslate::STranslate(const glm::vec3& Vector, bool bInter, double T0, double T1):
77 Operation(bInter, T0, T1),
78 vector(Vector)
79{
80}
81
82std::shared_ptr<SRotate>
83makeSRotate(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1)
84{
85 return std::make_shared<SRotate>(Axis, Origin, Angle, bInter, T0, T1);
86}
87
88std::shared_ptr<SScale>
89makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1)
90{
91 return std::make_shared<SScale>(Scale, Origin, bInter, T0, T1);
92}
93
94std::shared_ptr<STranslate>
95makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1)
96{
97 return std::make_shared<STranslate>(Vector, bInter, T0, T1);
98}
99
100std::shared_ptr<SEllipseTranslate>
101makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1)
102{
103 return std::make_shared<SEllipseTranslate>(dWidth, dHeight, dStartPosition, dEndPosition, bInter, T0, T1);
104}
105
106std::shared_ptr<RotateAndScaleDepthByWidth>
107makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1)
108{
109 return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bScale, bInter, T0, T1);
110}
111
112std::shared_ptr<RotateAndScaleDepthByHeight>
113makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bScale, bool bInter, double T0, double T1)
114{
115 return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bScale, bInter, T0, T1);
116}
117
118static double intervalInter(double t, double T0, double T1)
119{
120 return ( t - T0 ) / ( T1 - T0 );
121}
122
123void STranslate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
124{
125 if(t <= mnT0)
126 return;
127 if(!mbInterpolate || t > mnT1)
128 t = mnT1;
130 matrix = glm::translate(matrix, glm::vec3(SlideWidthScale*t*vector.x, SlideHeightScale*t*vector.y, t*vector.z));
131}
132
133void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
134{
135 if(t <= mnT0)
136 return;
137 if(!mbInterpolate || t > mnT1)
138 t = mnT1;
140 glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, origin.z);
141 glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1);
142 matrix = glm::translate(matrix, translation_vector);
143 matrix = glm::scale(matrix, scale_vector);
144 matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
145 matrix = glm::scale(matrix, 1.f / scale_vector);
146 matrix = glm::translate(matrix, -translation_vector);
147}
148
149void SScale::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
150{
151 if(t <= mnT0)
152 return;
153 if(!mbInterpolate || t > mnT1)
154 t = mnT1;
156 glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, origin.z);
157 matrix = glm::translate(matrix, translation_vector);
158 matrix = glm::scale(matrix, static_cast<float>(1 - t) + static_cast<float>(t) * scale);
159 matrix = glm::translate(matrix, -translation_vector);
160}
161
162void RotateAndScaleDepthByWidth::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
163{
164 if(t <= mnT0)
165 return;
166 if(!mbInterpolate || t > mnT1)
167 t = mnT1;
169 glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideWidthScale*origin.z);
170 glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1);
171 matrix = glm::translate(matrix, translation_vector);
172 if (scale)
173 matrix = glm::scale(matrix, scale_vector);
174 matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
175 if (scale)
176 matrix = glm::scale(matrix, 1.f / scale_vector);
177 matrix = glm::translate(matrix, -translation_vector);
178}
179
180void RotateAndScaleDepthByHeight::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
181{
182 if(t <= mnT0)
183 return;
184 if(!mbInterpolate || t > mnT1)
185 t = mnT1;
187 glm::vec3 translation_vector(SlideWidthScale*origin.x, SlideHeightScale*origin.y, SlideHeightScale*origin.z);
188 glm::vec3 scale_vector(SlideWidthScale * SlideWidthScale, SlideHeightScale * SlideHeightScale, 1);
189 matrix = glm::translate(matrix, translation_vector);
190 if (scale)
191 matrix = glm::scale(matrix, scale_vector);
192 matrix = glm::rotate(matrix, static_cast<float>(t*angle), axis);
193 if (scale)
194 matrix = glm::scale(matrix, 1.f / scale_vector);
195 matrix = glm::translate(matrix, -translation_vector);
196}
197
198SEllipseTranslate::SEllipseTranslate(double dWidth, double dHeight, double dStartPosition,
199 double dEndPosition, bool bInter, double T0, double T1):
200 Operation(bInter, T0, T1)
201{
202 width = dWidth;
203 height = dHeight;
204 startPosition = dStartPosition;
205 endPosition = dEndPosition;
206}
207
208void SEllipseTranslate::interpolate(glm::mat4& matrix, double t, double /* SlideWidthScale */, double /* SlideHeightScale */) const
209{
210 if(t <= mnT0)
211 return;
212 if(!mbInterpolate || t > mnT1)
213 t = mnT1;
215
216 double a1, a2, x, y;
217 a1 = startPosition*2*M_PI;
218 a2 = (startPosition + t*(endPosition - startPosition))*2*M_PI;
219 x = width*(cos (a2) - cos (a1))/2;
220 y = height*(sin (a2) - sin (a1))/2;
221
222 matrix = glm::translate(matrix, glm::vec3(x, 0, y));
223}
224
225/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< RotateAndScaleDepthByWidth > makeRotateAndScaleDepthByWidth(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bScale, bool bInter, double T0, double T1)
Definition: Operation.cxx:107
std::shared_ptr< SRotate > makeSRotate(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bInter, double T0, double T1)
Definition: Operation.cxx:83
std::shared_ptr< SScale > makeSScale(const glm::vec3 &Scale, const glm::vec3 &Origin, bool bInter, double T0, double T1)
Definition: Operation.cxx:89
std::shared_ptr< SEllipseTranslate > makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1)
Definition: Operation.cxx:101
std::shared_ptr< RotateAndScaleDepthByHeight > makeRotateAndScaleDepthByHeight(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bScale, bool bInter, double T0, double T1)
Definition: Operation.cxx:113
static double intervalInter(double t, double T0, double T1)
Definition: Operation.cxx:118
std::shared_ptr< STranslate > makeSTranslate(const glm::vec3 &Vector, bool bInter, double T0, double T1)
Definition: Operation.cxx:95
XPropertyListType t
This class is to be derived to make any operation (transform) you may need in order to construct your...
Definition: Operation.hxx:39
double mnT0
time to begin the transformation
Definition: Operation.hxx:52
bool mbInterpolate
Should this operation be interpolated .
Definition: Operation.hxx:48
double mnT1
time to finish the transformation
Definition: Operation.hxx:56
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:180
RotateAndScaleDepthByHeight(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bScale, bool bInter, double T0, double T1)
Definition: Operation.cxx:65
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:162
RotateAndScaleDepthByWidth(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bScale, bool bInter, double T0, double T1)
Definition: Operation.cxx:55
double width
width and length of the ellipse
Definition: Operation.hxx:217
double startPosition
start and end position on the ellipse <0,1>
Definition: Operation.hxx:221
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:208
SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1)
Constructor.
Definition: Operation.cxx:198
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:133
glm::vec3 origin
position that rotation axis runs through
Definition: Operation.hxx:114
glm::vec3 axis
axis to rotate CCW about
Definition: Operation.hxx:110
double angle
angle in degrees of CCW rotation
Definition: Operation.hxx:118
SRotate(const glm::vec3 &Axis, const glm::vec3 &Origin, double Angle, bool bInter, double T0, double T1)
Constructor.
Definition: Operation.cxx:38
glm::vec3 scale
Definition: Operation.hxx:152
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:149
SScale(const glm::vec3 &Scale, const glm::vec3 &Origin, bool bInter, double T0, double T1)
Constructor.
Definition: Operation.cxx:47
glm::vec3 origin
Definition: Operation.hxx:153
virtual void interpolate(glm::mat4 &matrix, double t, double SlideWidthScale, double SlideHeightScale) const override
this is the function that is called to give the Operation to OpenGL.
Definition: Operation.cxx:123
glm::vec3 vector
vector to translate by
Definition: Operation.hxx:185
STranslate(const glm::vec3 &Vector, bool bInter, double T0, double T1)
Constructor.
Definition: Operation.cxx:76
float y
float x
constexpr double deg2rad(double v)
double matrix[4][4]
sal_Int32 scale