tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / slideshow / source / engine / opengl / Operation.cxx
blobec83d6b74c3271ebe06f3b06db49f90d6f3b5aee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2015 by Collabora, Ltd.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <sal/config.h>
31 #include "Operation.hxx"
33 #include <basegfx/numeric/ftools.hxx>
35 #include <glm/gtc/matrix_transform.hpp>
36 #include <glm/gtc/type_ptr.hpp>
38 SRotate::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))
47 SScale::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)
55 RotateAndScaleDepthByWidth::RotateAndScaleDepthByWidth(const glm::vec3& Axis,
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)
65 RotateAndScaleDepthByHeight::RotateAndScaleDepthByHeight(const glm::vec3& Axis,
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)
76 STranslate::STranslate(const glm::vec3& Vector, bool bInter, double T0, double T1):
77 Operation(bInter, T0, T1),
78 vector(Vector)
82 std::shared_ptr<SRotate>
83 makeSRotate(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1)
85 return std::make_shared<SRotate>(Axis, Origin, Angle, bInter, T0, T1);
88 std::shared_ptr<SScale>
89 makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1)
91 return std::make_shared<SScale>(Scale, Origin, bInter, T0, T1);
94 std::shared_ptr<STranslate>
95 makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1)
97 return std::make_shared<STranslate>(Vector, bInter, T0, T1);
100 std::shared_ptr<SEllipseTranslate>
101 makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1)
103 return std::make_shared<SEllipseTranslate>(dWidth, dHeight, dStartPosition, dEndPosition, bInter, T0, T1);
106 std::shared_ptr<RotateAndScaleDepthByWidth>
107 makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle, bool bScale, bool bInter, double T0, double T1)
109 return std::make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bScale, bInter, T0, T1);
112 std::shared_ptr<RotateAndScaleDepthByHeight>
113 makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bScale, bool bInter, double T0, double T1)
115 return std::make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bScale, bInter, T0, T1);
118 static double intervalInter(double t, double T0, double T1)
120 return ( t - T0 ) / ( T1 - T0 );
123 void STranslate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
125 if(t <= mnT0)
126 return;
127 if(!mbInterpolate || t > mnT1)
128 t = mnT1;
129 t = intervalInter(t,mnT0,mnT1);
130 matrix = glm::translate(matrix, glm::vec3(SlideWidthScale*t*vector.x, SlideHeightScale*t*vector.y, t*vector.z));
133 void SRotate::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
135 if(t <= mnT0)
136 return;
137 if(!mbInterpolate || t > mnT1)
138 t = mnT1;
139 t = intervalInter(t,mnT0,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);
149 void SScale::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
151 if(t <= mnT0)
152 return;
153 if(!mbInterpolate || t > mnT1)
154 t = mnT1;
155 t = intervalInter(t,mnT0,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);
162 void RotateAndScaleDepthByWidth::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
164 if(t <= mnT0)
165 return;
166 if(!mbInterpolate || t > mnT1)
167 t = mnT1;
168 t = intervalInter(t,mnT0,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);
180 void RotateAndScaleDepthByHeight::interpolate(glm::mat4& matrix, double t, double SlideWidthScale, double SlideHeightScale) const
182 if(t <= mnT0)
183 return;
184 if(!mbInterpolate || t > mnT1)
185 t = mnT1;
186 t = intervalInter(t,mnT0,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);
198 SEllipseTranslate::SEllipseTranslate(double dWidth, double dHeight, double dStartPosition,
199 double dEndPosition, bool bInter, double T0, double T1):
200 Operation(bInter, T0, T1)
202 width = dWidth;
203 height = dHeight;
204 startPosition = dStartPosition;
205 endPosition = dEndPosition;
208 void SEllipseTranslate::interpolate(glm::mat4& matrix, double t, double /* SlideWidthScale */, double /* SlideHeightScale */) const
210 if(t <= mnT0)
211 return;
212 if(!mbInterpolate || t > mnT1)
213 t = mnT1;
214 t = intervalInter(t,mnT0,mnT1);
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;
222 matrix = glm::translate(matrix, glm::vec3(x, 0, y));
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */