Line data Source code
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 2008 by Sun Microsystems, Inc.
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 <GL/glew.h>
30 : #include <vcl/opengl/OpenGLHelper.hxx>
31 :
32 : #include <utility>
33 :
34 : #include <boost/make_shared.hpp>
35 : #include <boost/math/special_functions/next.hpp>
36 : #include <comphelper/random.hxx>
37 :
38 : #include "OGLTrans_TransitionImpl.hxx"
39 : #include <math.h>
40 :
41 : using boost::make_shared;
42 : using boost::shared_ptr;
43 :
44 : using std::max;
45 : using std::min;
46 : using std::vector;
47 :
48 0 : TransitionScene::TransitionScene(TransitionScene const& rOther)
49 : : maLeavingSlidePrimitives(rOther.maLeavingSlidePrimitives)
50 : , maEnteringSlidePrimitives(rOther.maEnteringSlidePrimitives)
51 : , maOverallOperations(rOther.maOverallOperations)
52 0 : , maSceneObjects(rOther.maSceneObjects)
53 : {
54 0 : }
55 :
56 0 : TransitionScene& TransitionScene::operator=(const TransitionScene& rOther)
57 : {
58 0 : TransitionScene aTmp(rOther);
59 0 : swap(aTmp);
60 0 : return *this;
61 : }
62 :
63 0 : void TransitionScene::swap(TransitionScene& rOther)
64 : {
65 : using std::swap;
66 :
67 0 : swap(maLeavingSlidePrimitives, rOther.maLeavingSlidePrimitives);
68 0 : swap(maEnteringSlidePrimitives, rOther.maEnteringSlidePrimitives);
69 0 : swap(maOverallOperations, rOther.maOverallOperations);
70 0 : swap(maSceneObjects, rOther.maSceneObjects);
71 0 : }
72 :
73 0 : OGLTransitionImpl::~OGLTransitionImpl()
74 : {
75 0 : }
76 :
77 0 : void OGLTransitionImpl::setScene(TransitionScene const& rScene)
78 : {
79 0 : maScene = rScene;
80 0 : }
81 :
82 0 : void OGLTransitionImpl::prepare( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex )
83 : {
84 0 : const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
85 0 : for(size_t i(0); i != rSceneObjects.size(); ++i) {
86 0 : rSceneObjects[i]->prepare();
87 : }
88 :
89 0 : prepareTransition( glLeavingSlideTex, glEnteringSlideTex );
90 0 : }
91 :
92 0 : void OGLTransitionImpl::finish()
93 : {
94 0 : const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
95 0 : for(size_t i(0); i != rSceneObjects.size(); ++i) {
96 0 : rSceneObjects[i]->finish();
97 : }
98 :
99 0 : finishTransition();
100 0 : }
101 :
102 0 : static void blendSlide( double depth )
103 : {
104 0 : CHECK_GL_ERROR();
105 0 : double showHeight = -1 + depth*2;
106 0 : GLfloat reflectionColor[] = {0, 0, 0, 0.25};
107 :
108 0 : glDisable( GL_DEPTH_TEST );
109 0 : glBegin( GL_QUADS );
110 0 : glColor4fv( reflectionColor );
111 0 : glVertex3f( -1, -1, 0 );
112 0 : glColor4f( 0, 0, 0, 1 );
113 0 : glVertex3f(-1, showHeight, 0 );
114 0 : glVertex3f( 1, showHeight, 0 );
115 0 : glColor4fv( reflectionColor );
116 0 : glVertex3f( 1, -1, 0 );
117 0 : glEnd();
118 :
119 0 : glBegin( GL_QUADS );
120 0 : glColor4f( 0, 0, 0, 1 );
121 0 : glVertex3f( -1, showHeight, 0 );
122 0 : glVertex3f( -1, 1, 0 );
123 0 : glVertex3f( 1, 1, 0 );
124 0 : glVertex3f( 1, showHeight, 0 );
125 0 : glEnd();
126 0 : glEnable( GL_DEPTH_TEST );
127 0 : CHECK_GL_ERROR();
128 0 : }
129 :
130 0 : static void slideShadow( double nTime, const Primitive& primitive, double sw, double sh )
131 : {
132 0 : CHECK_GL_ERROR();
133 0 : double reflectionDepth = 0.3;
134 :
135 0 : glEnable(GL_BLEND);
136 0 : glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
137 0 : glDisable(GL_LIGHTING);
138 :
139 0 : glPushMatrix();
140 0 : primitive.applyOperations( nTime, sw, sh );
141 0 : blendSlide( reflectionDepth );
142 0 : glPopMatrix();
143 :
144 0 : glDisable(GL_BLEND);
145 0 : glEnable(GL_LIGHTING);
146 0 : CHECK_GL_ERROR();
147 0 : }
148 :
149 0 : void OGLTransitionImpl::prepare( double, double, double, double, double )
150 : {
151 0 : }
152 :
153 0 : void OGLTransitionImpl::prepareTransition( ::sal_Int32, ::sal_Int32 )
154 : {
155 0 : }
156 :
157 0 : void OGLTransitionImpl::finishTransition()
158 : {
159 0 : }
160 :
161 0 : void OGLTransitionImpl::displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale )
162 : {
163 0 : CHECK_GL_ERROR();
164 0 : applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
165 :
166 0 : glEnable(GL_TEXTURE_2D);
167 0 : displaySlide( nTime, glLeavingSlideTex, maScene.getLeavingSlide(), SlideWidthScale, SlideHeightScale );
168 0 : displaySlide( nTime, glEnteringSlideTex, maScene.getEnteringSlide(), SlideWidthScale, SlideHeightScale );
169 0 : }
170 :
171 0 : void OGLTransitionImpl::display( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex,
172 : double SlideWidth, double SlideHeight, double DispWidth, double DispHeight )
173 : {
174 0 : const double SlideWidthScale = SlideWidth/DispWidth;
175 0 : const double SlideHeightScale = SlideHeight/DispHeight;
176 :
177 0 : CHECK_GL_ERROR();
178 0 : prepare( nTime, SlideWidth, SlideHeight, DispWidth, DispHeight );
179 :
180 0 : CHECK_GL_ERROR();
181 0 : glPushMatrix();
182 0 : CHECK_GL_ERROR();
183 0 : displaySlides_( nTime, glLeavingSlideTex, glEnteringSlideTex, SlideWidthScale, SlideHeightScale );
184 0 : CHECK_GL_ERROR();
185 0 : displayScene( nTime, SlideWidth, SlideHeight, DispWidth, DispHeight );
186 0 : CHECK_GL_ERROR();
187 0 : glPopMatrix();
188 0 : CHECK_GL_ERROR();
189 0 : }
190 :
191 0 : void OGLTransitionImpl::applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale )
192 : {
193 0 : const Operations_t& rOverallOperations(maScene.getOperations());
194 0 : for(size_t i(0); i != rOverallOperations.size(); ++i)
195 0 : rOverallOperations[i]->interpolate(nTime,SlideWidthScale,SlideHeightScale);
196 0 : }
197 :
198 : void
199 0 : OGLTransitionImpl::displaySlide(
200 : const double nTime,
201 : const ::sal_Int32 glSlideTex, const Primitives_t& primitives,
202 : double SlideWidthScale, double SlideHeightScale )
203 : {
204 0 : CHECK_GL_ERROR();
205 : //TODO change to foreach
206 0 : glBindTexture(GL_TEXTURE_2D, glSlideTex);
207 0 : CHECK_GL_ERROR();
208 :
209 : // display slide reflection
210 : // note that depth test is turned off while blending the shadow
211 : // so the slides has to be rendered in right order, see rochade as example
212 0 : if( maSettings.mbReflectSlides ) {
213 0 : double surfaceLevel = -0.04;
214 :
215 : /* reflected slides */
216 0 : glPushMatrix();
217 :
218 0 : glScaled( 1, -1, 1 );
219 0 : glTranslated( 0, 2 - surfaceLevel, 0 );
220 :
221 0 : glCullFace(GL_FRONT);
222 0 : for(size_t i(0); i < primitives.size(); ++i)
223 0 : primitives[i].display(nTime, SlideWidthScale, SlideHeightScale);
224 0 : glCullFace(GL_BACK);
225 :
226 0 : slideShadow( nTime, primitives[0], SlideWidthScale, SlideHeightScale );
227 :
228 0 : glPopMatrix();
229 : }
230 :
231 0 : for(size_t i(0); i < primitives.size(); ++i)
232 0 : primitives[i].display(nTime, SlideWidthScale, SlideHeightScale);
233 0 : CHECK_GL_ERROR();
234 0 : }
235 :
236 0 : void OGLTransitionImpl::displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight )
237 : {
238 0 : CHECK_GL_ERROR();
239 0 : const SceneObjects_t& rSceneObjects(maScene.getSceneObjects());
240 0 : glEnable(GL_TEXTURE_2D);
241 0 : for(size_t i(0); i != rSceneObjects.size(); ++i)
242 0 : rSceneObjects[i]->display(nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
243 0 : CHECK_GL_ERROR();
244 0 : }
245 :
246 0 : void Primitive::display(double nTime, double WidthScale, double HeightScale) const
247 : {
248 0 : CHECK_GL_ERROR();
249 0 : glPushMatrix();
250 :
251 0 : CHECK_GL_ERROR();
252 0 : applyOperations( nTime, WidthScale, HeightScale );
253 :
254 0 : CHECK_GL_ERROR();
255 0 : glEnableClientState( GL_VERTEX_ARRAY );
256 0 : CHECK_GL_ERROR();
257 0 : if(!Normals.empty())
258 : {
259 0 : CHECK_GL_ERROR();
260 0 : glNormalPointer( GL_FLOAT , 0 , &Normals[0] );
261 0 : CHECK_GL_ERROR();
262 0 : glEnableClientState( GL_NORMAL_ARRAY );
263 0 : CHECK_GL_ERROR();
264 : }
265 0 : CHECK_GL_ERROR();
266 0 : glEnableClientState( GL_TEXTURE_COORD_ARRAY );
267 0 : CHECK_GL_ERROR();
268 0 : glTexCoordPointer( 2, GL_FLOAT, 0, &TexCoords[0] );
269 0 : CHECK_GL_ERROR();
270 0 : glVertexPointer( 3, GL_FLOAT, 0, &Vertices[0] );
271 0 : CHECK_GL_ERROR();
272 0 : glDrawArrays( GL_TRIANGLES, 0, Vertices.size() );
273 0 : CHECK_GL_ERROR();
274 0 : glPopMatrix();
275 0 : CHECK_GL_ERROR();
276 0 : }
277 :
278 0 : void Primitive::applyOperations(double nTime, double WidthScale, double HeightScale) const
279 : {
280 0 : CHECK_GL_ERROR();
281 0 : for(size_t i(0); i < Operations.size(); ++i)
282 0 : Operations[i]->interpolate( nTime ,WidthScale,HeightScale);
283 0 : glScaled(WidthScale,HeightScale,1);
284 0 : CHECK_GL_ERROR();
285 0 : }
286 :
287 0 : void SceneObject::display(double nTime, double /* SlideWidth */, double /* SlideHeight */, double DispWidth, double DispHeight ) const
288 : {
289 0 : CHECK_GL_ERROR();
290 0 : for(size_t i(0); i < maPrimitives.size(); ++i) {
291 : // fixme: allow various model spaces, now we make it so that
292 : // it is regular -1,-1 to 1,1, where the whole display fits in
293 0 : CHECK_GL_ERROR();
294 0 : glPushMatrix();
295 0 : CHECK_GL_ERROR();
296 0 : if (DispHeight > DispWidth)
297 0 : glScaled(DispHeight/DispWidth, 1, 1);
298 : else
299 0 : glScaled(1, DispWidth/DispHeight, 1);
300 0 : maPrimitives[i].display(nTime, 1, 1);
301 0 : CHECK_GL_ERROR();
302 0 : glPopMatrix();
303 0 : CHECK_GL_ERROR();
304 : }
305 0 : CHECK_GL_ERROR();
306 0 : }
307 :
308 0 : void SceneObject::pushPrimitive(const Primitive &p)
309 : {
310 0 : maPrimitives.push_back(p);
311 0 : }
312 :
313 0 : SceneObject::SceneObject()
314 0 : : maPrimitives()
315 : {
316 0 : }
317 :
318 0 : SceneObject::~SceneObject()
319 : {
320 0 : }
321 :
322 0 : Iris::Iris()
323 : : SceneObject()
324 0 : , maTexture(0)
325 : {
326 0 : }
327 :
328 0 : void Iris::display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) const
329 : {
330 0 : glBindTexture(GL_TEXTURE_2D, maTexture);
331 0 : CHECK_GL_ERROR();
332 0 : SceneObject::display(nTime, SlideWidth, SlideHeight, DispWidth, DispHeight);
333 0 : }
334 :
335 0 : void Iris::prepare()
336 : {
337 0 : CHECK_GL_ERROR();
338 : static const GLubyte img[3] = { 80, 80, 80 };
339 :
340 0 : glGenTextures(1, &maTexture);
341 0 : glBindTexture(GL_TEXTURE_2D, maTexture);
342 0 : glTexImage2D(GL_TEXTURE_2D, 0, 3, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, img);
343 0 : glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
344 0 : glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
345 0 : glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
346 0 : glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
347 0 : CHECK_GL_ERROR();
348 0 : }
349 :
350 0 : void Iris::finish()
351 : {
352 0 : CHECK_GL_ERROR();
353 0 : glDeleteTextures(1, &maTexture);
354 0 : CHECK_GL_ERROR();
355 0 : }
356 :
357 : namespace
358 : {
359 :
360 0 : class SimpleTransition : public OGLTransitionImpl
361 : {
362 : public:
363 0 : SimpleTransition()
364 0 : : OGLTransitionImpl()
365 : {
366 0 : }
367 :
368 0 : SimpleTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
369 0 : : OGLTransitionImpl(rScene, rSettings)
370 : {
371 0 : }
372 : };
373 :
374 : shared_ptr<OGLTransitionImpl>
375 0 : makeSimpleTransition()
376 : {
377 0 : return make_shared<SimpleTransition>();
378 : }
379 :
380 : shared_ptr<OGLTransitionImpl>
381 0 : makeSimpleTransition(
382 : const Primitives_t& rLeavingSlidePrimitives,
383 : const Primitives_t& rEnteringSlidePrimitives,
384 : const Operations_t& rOverallOperations,
385 : const SceneObjects_t& rSceneObjects,
386 : const TransitionSettings& rSettings = TransitionSettings())
387 : {
388 : return make_shared<SimpleTransition>(
389 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives, rOverallOperations, rSceneObjects),
390 0 : rSettings)
391 : ;
392 : }
393 :
394 : shared_ptr<OGLTransitionImpl>
395 0 : makeSimpleTransition(
396 : const Primitives_t& rLeavingSlidePrimitives,
397 : const Primitives_t& rEnteringSlidePrimitives,
398 : const Operations_t& rOverallOperations,
399 : const TransitionSettings& rSettings = TransitionSettings())
400 : {
401 0 : return makeSimpleTransition(rLeavingSlidePrimitives, rEnteringSlidePrimitives, rOverallOperations, SceneObjects_t(), rSettings);
402 : }
403 :
404 : shared_ptr<OGLTransitionImpl>
405 0 : makeSimpleTransition(
406 : const Primitives_t& rLeavingSlidePrimitives,
407 : const Primitives_t& rEnteringSlidePrimitives,
408 : const SceneObjects_t& rSceneObjects,
409 : const TransitionSettings& rSettings = TransitionSettings())
410 : {
411 0 : return makeSimpleTransition(rLeavingSlidePrimitives, rEnteringSlidePrimitives, Operations_t(), rSceneObjects, rSettings);
412 : }
413 :
414 : shared_ptr<OGLTransitionImpl>
415 0 : makeSimpleTransition(
416 : const Primitives_t& rLeavingSlidePrimitives,
417 : const Primitives_t& rEnteringSlidePrimitives,
418 : const TransitionSettings& rSettings = TransitionSettings())
419 : {
420 0 : return makeSimpleTransition(rLeavingSlidePrimitives, rEnteringSlidePrimitives, Operations_t(), SceneObjects_t(), rSettings);
421 : }
422 :
423 : }
424 :
425 0 : boost::shared_ptr<OGLTransitionImpl> makeOutsideCubeFaceToLeft()
426 : {
427 0 : Primitive Slide;
428 :
429 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
430 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
431 :
432 0 : Primitives_t aLeavingPrimitives;
433 0 : aLeavingPrimitives.push_back(Slide);
434 :
435 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),90,false,0.0,1.0));
436 :
437 0 : Primitives_t aEnteringPrimitives;
438 0 : aEnteringPrimitives.push_back(Slide);
439 :
440 0 : Operations_t aOperations;
441 0 : aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,-1),-90,true,0.0,1.0));
442 :
443 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations);
444 : }
445 :
446 0 : boost::shared_ptr<OGLTransitionImpl> makeInsideCubeFaceToLeft()
447 : {
448 0 : Primitive Slide;
449 :
450 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
451 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
452 :
453 0 : Primitives_t aLeavingPrimitives;
454 0 : aLeavingPrimitives.push_back(Slide);
455 :
456 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),-90,false,0.0,1.0));
457 :
458 0 : Primitives_t aEnteringPrimitives;
459 0 : aEnteringPrimitives.push_back(Slide);
460 :
461 0 : Operations_t aOperations;
462 0 : aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,1),90,true,0.0,1.0));
463 :
464 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations);
465 : }
466 :
467 0 : boost::shared_ptr<OGLTransitionImpl> makeFallLeaving()
468 : {
469 0 : Primitive Slide;
470 :
471 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
472 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
473 :
474 0 : Primitives_t aEnteringPrimitives;
475 0 : aEnteringPrimitives.push_back(Slide);
476 :
477 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(1,0,0),glm::vec3(0,-1,0), 90,true,0.0,1.0));
478 0 : Primitives_t aLeavingPrimitives;
479 0 : aLeavingPrimitives.push_back(Slide);
480 :
481 0 : TransitionSettings aSettings;
482 0 : aSettings.mbUseMipMapEntering = false;
483 :
484 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aSettings);
485 : }
486 :
487 0 : boost::shared_ptr<OGLTransitionImpl> makeTurnAround()
488 : {
489 0 : Primitive Slide;
490 :
491 0 : TransitionSettings aSettings;
492 0 : aSettings.mbReflectSlides = true;
493 :
494 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
495 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
496 0 : Primitives_t aLeavingPrimitives;
497 0 : aLeavingPrimitives.push_back(Slide);
498 :
499 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0),-180,false,0.0,1.0));
500 0 : Primitives_t aEnteringPrimitives;
501 0 : aEnteringPrimitives.push_back(Slide);
502 :
503 0 : Operations_t aOperations;
504 0 : aOperations.push_back(makeSTranslate(glm::vec3(0, 0, -1.5),true, 0, 0.5));
505 0 : aOperations.push_back(makeSTranslate(glm::vec3(0, 0, 1.5), true, 0.5, 1));
506 0 : aOperations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0),glm::vec3(0, 0, 0), -180, true, 0.0, 1.0));
507 :
508 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aOperations, aSettings);
509 : }
510 :
511 0 : boost::shared_ptr<OGLTransitionImpl> makeTurnDown()
512 : {
513 0 : Primitive Slide;
514 :
515 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
516 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
517 0 : Primitives_t aLeavingPrimitives;
518 0 : aLeavingPrimitives.push_back(Slide);
519 :
520 0 : Slide.Operations.push_back(makeSTranslate(glm::vec3(0, 0, 0.0001), false, -1.0, 0.0));
521 0 : Slide.Operations.push_back(makeSRotate (glm::vec3(0, 0, 1), glm::vec3(-1, 1, 0), -90, true, 0.0, 1.0));
522 0 : Slide.Operations.push_back(makeSRotate (glm::vec3(0, 0, 1), glm::vec3(-1, 1, 0), 90, false, -1.0, 0.0));
523 0 : Primitives_t aEnteringPrimitives;
524 0 : aEnteringPrimitives.push_back(Slide);
525 :
526 0 : TransitionSettings aSettings;
527 0 : aSettings.mbUseMipMapLeaving = false;
528 :
529 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aSettings);
530 : }
531 :
532 0 : boost::shared_ptr<OGLTransitionImpl> makeIris()
533 : {
534 0 : Primitive Slide;
535 :
536 0 : Slide.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
537 0 : Slide.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
538 0 : Primitives_t aEnteringPrimitives;
539 0 : aEnteringPrimitives.push_back (Slide);
540 :
541 0 : Slide.Operations.push_back (makeSTranslate (glm::vec3 (0, 0, 0.000001), false, -1, 0));
542 0 : Slide.Operations.push_back (makeSTranslate (glm::vec3 (0, 0, -0.000002), false, 0.5, 1));
543 0 : Primitives_t aLeavingPrimitives;
544 0 : aLeavingPrimitives.push_back (Slide);
545 :
546 :
547 0 : Primitive irisPart, part;
548 0 : int i, nSteps = 24, nParts = 7;
549 0 : double t = 1.0/nSteps, cx, cy, lcx, lcy, lx = 1, ly = 0, x, y, cxo, cyo, lcxo, lcyo, of=2.2, f=1.42;
550 :
551 0 : for (i=1; i<=nSteps; i++) {
552 0 : x = cos ((3*2*M_PI*t)/nParts);
553 0 : y = -sin ((3*2*M_PI*t)/nParts);
554 0 : cx = (f*x + 1)/2;
555 0 : cy = (f*y + 1)/2;
556 0 : lcx = (f*lx + 1)/2;
557 0 : lcy = (f*ly + 1)/2;
558 0 : cxo = (of*x + 1)/2;
559 0 : cyo = (of*y + 1)/2;
560 0 : lcxo = (of*lx + 1)/2;
561 0 : lcyo = (of*ly + 1)/2;
562 : irisPart.pushTriangle (glm::vec2 (lcx, lcy),
563 : glm::vec2 (lcxo, lcyo),
564 0 : glm::vec2 (cx, cy));
565 : irisPart.pushTriangle (glm::vec2 (cx, cy),
566 : glm::vec2 (lcxo, lcyo),
567 0 : glm::vec2 (cxo, cyo));
568 0 : lx = x;
569 0 : ly = y;
570 0 : t += 1.0/nSteps;
571 : }
572 :
573 0 : shared_ptr<Iris> pIris = make_shared<Iris>();
574 0 : double angle = 87;
575 :
576 0 : for (i = 0; i < nParts; i++) {
577 0 : irisPart.Operations.clear ();
578 : double rx, ry;
579 :
580 0 : rx = cos ((2*M_PI*i)/nParts);
581 0 : ry = sin ((2*M_PI*i)/nParts);
582 0 : irisPart.Operations.push_back (makeSRotate (glm::vec3(0, 0, 1), glm::vec3(rx, ry, 0), angle, true, 0.0, 0.5));
583 0 : irisPart.Operations.push_back (makeSRotate (glm::vec3(0, 0, 1), glm::vec3(rx, ry, 0), -angle, true, 0.5, 1));
584 0 : if (i > 0) {
585 0 : irisPart.Operations.push_back (makeSTranslate (glm::vec3(rx, ry, 0), false, -1, 0));
586 0 : irisPart.Operations.push_back (makeSRotate (glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), i*360.0/nParts, false, -1, 0));
587 0 : irisPart.Operations.push_back (makeSTranslate (glm::vec3(-1, 0, 0), false, -1, 0));
588 : }
589 0 : irisPart.Operations.push_back(makeSTranslate(glm::vec3(0, 0, 1), false, -2, 0.0));
590 0 : irisPart.Operations.push_back (makeSRotate (glm::vec3(1, .5, 0), glm::vec3(1, 0, 0), -30, false, -1, 0));
591 0 : pIris->pushPrimitive (irisPart);
592 : }
593 :
594 0 : SceneObjects_t aSceneObjects;
595 0 : aSceneObjects.push_back (pIris);
596 :
597 0 : TransitionSettings aSettings;
598 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
599 :
600 0 : return makeSimpleTransition(aLeavingPrimitives, aEnteringPrimitives, aSceneObjects, aSettings);
601 : }
602 :
603 : namespace
604 : {
605 :
606 0 : class RochadeTransition : public OGLTransitionImpl
607 : {
608 : public:
609 0 : RochadeTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
610 0 : : OGLTransitionImpl(rScene, rSettings)
611 0 : {}
612 :
613 : private:
614 : virtual void displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) SAL_OVERRIDE;
615 : };
616 :
617 0 : void RochadeTransition::displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale )
618 : {
619 0 : applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
620 :
621 0 : glEnable(GL_TEXTURE_2D);
622 :
623 0 : if( nTime > .5) {
624 0 : displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
625 0 : displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
626 : } else {
627 0 : displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
628 0 : displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
629 : }
630 0 : }
631 :
632 : shared_ptr<OGLTransitionImpl>
633 0 : makeRochadeTransition(
634 : const Primitives_t& rLeavingSlidePrimitives,
635 : const Primitives_t& rEnteringSlidePrimitives,
636 : const TransitionSettings& rSettings)
637 : {
638 : return make_shared<RochadeTransition>(
639 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
640 0 : rSettings)
641 : ;
642 :
643 : }
644 : }
645 :
646 0 : boost::shared_ptr<OGLTransitionImpl> makeRochade()
647 : {
648 0 : Primitive Slide;
649 :
650 0 : TransitionSettings aSettings;
651 0 : aSettings.mbReflectSlides = true;
652 :
653 : double w, h;
654 :
655 0 : w = 2.2;
656 0 : h = 10;
657 :
658 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
659 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
660 :
661 0 : Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.25, -0.25, true, 0, 1));
662 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, 0, 1));
663 0 : Primitives_t aLeavingSlide;
664 0 : aLeavingSlide.push_back(Slide);
665 :
666 0 : Slide.Operations.clear();
667 0 : Slide.Operations.push_back(makeSEllipseTranslate(w, h, 0.75, 0.25, true, 0, 1));
668 0 : Slide.Operations.push_back(makeSTranslate(glm::vec3(0, 0, -h), false, -1, 0));
669 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), -45, true, 0, 1));
670 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0,1,0),glm::vec3(0,0,0), 45, false, -1, 0));
671 0 : Primitives_t aEnteringSlide;
672 0 : aEnteringSlide.push_back(Slide);
673 :
674 0 : return makeRochadeTransition(aLeavingSlide, aEnteringSlide, aSettings);
675 : }
676 :
677 0 : inline double randFromNeg1to1()
678 : {
679 0 : return comphelper::rng::uniform_real_distribution(-1.0, boost::math::nextafter(1.0, DBL_MAX));
680 : }
681 :
682 : // TODO(Q3): extract to basegfx
683 0 : inline glm::vec3 randNormVectorInXYPlane()
684 : {
685 0 : glm::vec3 toReturn(randFromNeg1to1(),randFromNeg1to1(),0.0);
686 0 : return glm::normalize(toReturn);
687 : }
688 :
689 : template<typename T>
690 0 : T clamp(const T& rIn)
691 : {
692 0 : return glm::clamp(rIn, T(-1.0), T(1.0));
693 : }
694 :
695 0 : boost::shared_ptr<OGLTransitionImpl> makeRevolvingCircles( ::sal_uInt16 nCircles , ::sal_uInt16 nPointsOnCircles )
696 : {
697 0 : double dAngle(2*3.1415926/static_cast<double>( nPointsOnCircles ));
698 0 : if(nCircles < 2 || nPointsOnCircles < 4)
699 : {
700 0 : makeNByMTileFlip(1,1);
701 0 : return makeSimpleTransition();
702 : }
703 0 : float Radius(1.0/static_cast<double>( nCircles ));
704 0 : float dRadius(Radius);
705 0 : float LastRadius(0.0);
706 0 : float NextRadius(2*Radius);
707 :
708 : /// now we know there is at least two circles
709 : /// the first will always be a full circle
710 : /// the last will always be the outer shell of the slide with a circle hole
711 :
712 : //add the full circle
713 0 : vector<glm::vec2> unScaledTexCoords;
714 0 : float TempAngle(0.0);
715 0 : for(unsigned int Point(0); Point < nPointsOnCircles; ++Point)
716 : {
717 0 : unScaledTexCoords.push_back( glm::vec2( cos(TempAngle - 3.1415926/2.0) , sin(TempAngle- 3.1415926/2.0) ) );
718 :
719 0 : TempAngle += dAngle;
720 : }
721 :
722 0 : Primitives_t aLeavingSlide;
723 0 : Primitives_t aEnteringSlide;
724 : {
725 0 : Primitive EnteringSlide;
726 0 : Primitive LeavingSlide;
727 0 : for(int Point(0); Point + 1 < nPointsOnCircles; ++Point)
728 : {
729 0 : EnteringSlide.pushTriangle( glm::vec2( 0.5 , 0.5 ) , Radius * unScaledTexCoords[ Point + 1 ] / 2.0f + glm::vec2( 0.5 , 0.5 ) , Radius * unScaledTexCoords[ Point ] / 2.0f + glm::vec2( 0.5 , 0.5 ) );
730 0 : LeavingSlide.pushTriangle( glm::vec2( 0.5 , 0.5 ) , Radius * unScaledTexCoords[ Point + 1 ] / 2.0f + glm::vec2( 0.5 , 0.5 ) , Radius * unScaledTexCoords[ Point ] / 2.0f + glm::vec2( 0.5, 0.5) );
731 : }
732 0 : EnteringSlide.pushTriangle( glm::vec2(0.5,0.5) , Radius * unScaledTexCoords[ 0 ] / 2.0f + glm::vec2( 0.5 , 0.5 ) , Radius * unScaledTexCoords[ nPointsOnCircles - 1 ] / 2.0f + glm::vec2( 0.5 , 0.5 ) );
733 0 : LeavingSlide.pushTriangle( glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) );
734 :
735 0 : glm::vec3 axis(randNormVectorInXYPlane());
736 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, Radius/2.0 , (NextRadius + 1)/2.0 ) );
737 0 : LeavingSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, Radius/2.0 , (NextRadius + 1)/2.0 ) );
738 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , -180, false,0.0,1.0) );
739 :
740 0 : aEnteringSlide.push_back(EnteringSlide);
741 0 : aLeavingSlide.push_back(LeavingSlide);
742 0 : LastRadius = Radius;
743 0 : Radius = NextRadius;
744 0 : NextRadius += dRadius;
745 : }
746 :
747 0 : for(int i(1); i < nCircles - 1; ++i)
748 : {
749 0 : Primitive LeavingSlide;
750 0 : Primitive EnteringSlide;
751 0 : for(int Side(0); Side < nPointsOnCircles - 1; ++Side)
752 : {
753 0 : EnteringSlide.pushTriangle(Radius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
754 0 : EnteringSlide.pushTriangle(Radius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
755 :
756 0 : LeavingSlide.pushTriangle(Radius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
757 0 : LeavingSlide.pushTriangle(Radius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
758 : }
759 :
760 0 : EnteringSlide.pushTriangle(Radius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
761 0 : EnteringSlide.pushTriangle(Radius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
762 :
763 0 : LeavingSlide.pushTriangle(Radius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
764 0 : LeavingSlide.pushTriangle(Radius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) , Radius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
765 :
766 0 : glm::vec3 axis(randNormVectorInXYPlane());
767 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, Radius/2.0 , (NextRadius + 1)/2.0 ) );
768 0 : LeavingSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, Radius/2.0 , (NextRadius + 1)/2.0 ) );
769 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , -180, false,0.0,1.0) );
770 :
771 0 : aEnteringSlide.push_back(EnteringSlide);
772 0 : aLeavingSlide.push_back(LeavingSlide);
773 :
774 0 : LastRadius = Radius;
775 0 : Radius = NextRadius;
776 0 : NextRadius += dRadius;
777 0 : }
778 : {
779 0 : Radius = sqrt(2.0);
780 0 : Primitive LeavingSlide;
781 0 : Primitive EnteringSlide;
782 0 : for(int Side(0); Side < nPointsOnCircles - 1; ++Side)
783 : {
784 :
785 0 : EnteringSlide.pushTriangle(clamp(Radius*unScaledTexCoords[Side])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
786 0 : EnteringSlide.pushTriangle(clamp(Radius*unScaledTexCoords[Side])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) , clamp(Radius*unScaledTexCoords[Side + 1])/2.0f + glm::vec2(0.5,0.5) );
787 :
788 0 : LeavingSlide.pushTriangle(clamp(Radius*unScaledTexCoords[Side])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) );
789 0 : LeavingSlide.pushTriangle(clamp(Radius*unScaledTexCoords[Side])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[Side + 1]/2.0f + glm::vec2(0.5,0.5) , clamp(Radius*unScaledTexCoords[Side + 1])/2.0f + glm::vec2(0.5,0.5) );
790 : }
791 :
792 0 : EnteringSlide.pushTriangle(clamp(Radius*unScaledTexCoords[nPointsOnCircles - 1])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
793 0 : EnteringSlide.pushTriangle(clamp(Radius*unScaledTexCoords[nPointsOnCircles - 1])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) , clamp(Radius*unScaledTexCoords[0])/2.0f + glm::vec2(0.5,0.5) );
794 :
795 0 : LeavingSlide.pushTriangle(clamp(Radius*unScaledTexCoords[nPointsOnCircles - 1])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[nPointsOnCircles - 1]/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) );
796 0 : LeavingSlide.pushTriangle(clamp(Radius*unScaledTexCoords[nPointsOnCircles - 1])/2.0f + glm::vec2(0.5,0.5) , LastRadius*unScaledTexCoords[0]/2.0f + glm::vec2(0.5,0.5) , clamp(Radius*unScaledTexCoords[0])/2.0f + glm::vec2(0.5,0.5) );
797 :
798 0 : glm::vec3 axis(randNormVectorInXYPlane());
799 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, (LastRadius + dRadius)/2.0 , 1.0 ) );
800 0 : LeavingSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , 180, true, (LastRadius + dRadius)/2.0 , 1.0 ) );
801 0 : EnteringSlide.Operations.push_back( makeSRotate( axis , glm::vec3(0,0,0) , -180, false,0.0,1.0) );
802 :
803 0 : aEnteringSlide.push_back(EnteringSlide);
804 0 : aLeavingSlide.push_back(LeavingSlide);
805 : }
806 :
807 0 : return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
808 : }
809 :
810 0 : boost::shared_ptr<OGLTransitionImpl> makeHelix( ::sal_uInt16 nRows )
811 : {
812 0 : double invN(1.0/static_cast<double>(nRows));
813 0 : double iDn = 0.0;
814 0 : double iPDn = invN;
815 0 : Primitives_t aLeavingSlide;
816 0 : Primitives_t aEnteringSlide;
817 0 : for(unsigned int i(0); i < nRows; ++i)
818 : {
819 0 : Primitive Tile;
820 :
821 0 : Tile.pushTriangle(glm::vec2( 1.0 , iDn ) , glm::vec2( 0.0 , iDn ) , glm::vec2( 0.0 , iPDn ));
822 :
823 0 : Tile.pushTriangle(glm::vec2( 1.0 , iPDn ) , glm::vec2( 1.0 , iDn ) , glm::vec2( 0.0 , iPDn ));
824 :
825 0 : Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , 180 ,
826 0 : true,min(max(static_cast<double>(i - nRows/2.0)*invN/2.0,0.0),1.0),
827 0 : min(max(static_cast<double>(i + nRows/2.0)*invN/2.0,0.0),1.0) ) );
828 :
829 0 : aLeavingSlide.push_back(Tile);
830 :
831 0 : Tile.Operations.push_back( makeSRotate( glm::vec3( 0 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , -180 , false,0.0,1.0) );
832 :
833 0 : aEnteringSlide.push_back(Tile);
834 :
835 0 : iDn += invN;
836 0 : iPDn += invN;
837 0 : }
838 :
839 0 : return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
840 : }
841 :
842 0 : boost::shared_ptr<OGLTransitionImpl> makeNByMTileFlip( ::sal_uInt16 n, ::sal_uInt16 m )
843 : {
844 0 : double invN(1.0/static_cast<double>(n));
845 0 : double invM(1.0/static_cast<double>(m));
846 0 : double iDn = 0.0;
847 0 : double iPDn = invN;
848 0 : Primitives_t aLeavingSlide;
849 0 : Primitives_t aEnteringSlide;
850 0 : for(unsigned int i(0); i < n; ++i)
851 : {
852 0 : double jDm = 0.0;
853 0 : double jPDm = invM;
854 0 : for(unsigned int j(0); j < m; ++j)
855 : {
856 0 : Primitive Tile;
857 :
858 0 : Tile.pushTriangle(glm::vec2( iPDn , jDm ) , glm::vec2( iDn , jDm ) , glm::vec2( iDn , jPDm ));
859 :
860 0 : Tile.pushTriangle(glm::vec2( iPDn , jPDm ) , glm::vec2( iPDn , jDm ) , glm::vec2( iDn , jPDm ));//bottom left corner of tile
861 :
862 0 : Tile.Operations.push_back( makeSRotate( glm::vec3( 1 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , 180 , true, iDn*jDm/2.0 , ((iPDn*jPDm)+1.0)/2.0 ) );
863 0 : aLeavingSlide.push_back(Tile);
864 0 : Tile.Operations.push_back( makeSRotate( glm::vec3( 1 , 1 , 0 ) , ( Tile.getVertices()[1] + Tile.getVertices()[3] )/2.0f , -180, false, iDn*jDm/2.0 , ((iPDn*jPDm)+1.0)/2.0 ) );
865 :
866 0 : aEnteringSlide.push_back(Tile);
867 :
868 0 : jDm += invM;
869 0 : jPDm += invM;
870 0 : }
871 0 : iDn += invN;
872 0 : iPDn += invN;
873 : }
874 :
875 0 : return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
876 : }
877 :
878 0 : SRotate::SRotate(const glm::vec3& Axis, const glm::vec3& Origin,
879 : double Angle, bool bInter, double T0, double T1):
880 : Operation(bInter, T0, T1),
881 : axis(Axis),
882 : origin(Origin),
883 0 : angle(Angle)
884 : {
885 0 : }
886 :
887 0 : SScale::SScale(const glm::vec3& Scale, const glm::vec3& Origin,
888 : bool bInter, double T0, double T1):
889 : Operation(bInter, T0, T1),
890 : scale(Scale),
891 0 : origin(Origin)
892 : {
893 0 : }
894 :
895 0 : RotateAndScaleDepthByWidth::RotateAndScaleDepthByWidth(const glm::vec3& Axis,
896 : const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1):
897 : Operation(bInter, T0, T1),
898 : axis(Axis),
899 : origin(Origin),
900 0 : angle(Angle)
901 : {
902 0 : }
903 :
904 0 : RotateAndScaleDepthByHeight::RotateAndScaleDepthByHeight(const glm::vec3& Axis,
905 : const glm::vec3& Origin, double Angle, bool bInter, double T0, double T1):
906 : Operation(bInter, T0, T1),
907 : axis(Axis),
908 : origin(Origin),
909 0 : angle(Angle)
910 : {
911 0 : }
912 :
913 :
914 0 : STranslate::STranslate(const glm::vec3& Vector, bool bInter, double T0, double T1):
915 : Operation(bInter, T0, T1),
916 0 : vector(Vector)
917 : {
918 0 : }
919 :
920 : boost::shared_ptr<SRotate>
921 0 : makeSRotate(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1)
922 : {
923 0 : return make_shared<SRotate>(Axis, Origin, Angle, bInter, T0, T1);
924 : }
925 :
926 : boost::shared_ptr<SScale>
927 0 : makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1)
928 : {
929 0 : return make_shared<SScale>(Scale, Origin, bInter, T0, T1);
930 : }
931 :
932 : boost::shared_ptr<STranslate>
933 0 : makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1)
934 : {
935 0 : return make_shared<STranslate>(Vector, bInter, T0, T1);
936 : }
937 :
938 : boost::shared_ptr<SEllipseTranslate>
939 0 : makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1)
940 : {
941 0 : return make_shared<SEllipseTranslate>(dWidth, dHeight, dStartPosition, dEndPosition, bInter, T0, T1);
942 : }
943 :
944 : boost::shared_ptr<RotateAndScaleDepthByWidth>
945 0 : makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1)
946 : {
947 0 : return make_shared<RotateAndScaleDepthByWidth>(Axis, Origin, Angle, bInter, T0, T1);
948 : }
949 :
950 : boost::shared_ptr<RotateAndScaleDepthByHeight>
951 0 : makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1)
952 : {
953 0 : return make_shared<RotateAndScaleDepthByHeight>(Axis, Origin, Angle, bInter, T0, T1);
954 : }
955 :
956 0 : inline double intervalInter(double t, double T0, double T1)
957 : {
958 0 : return ( t - T0 ) / ( T1 - T0 );
959 : }
960 :
961 0 : void STranslate::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
962 : {
963 0 : CHECK_GL_ERROR();
964 0 : if(t <= mnT0)
965 0 : return;
966 0 : if(!mbInterpolate || t > mnT1)
967 0 : t = mnT1;
968 0 : t = intervalInter(t,mnT0,mnT1);
969 0 : glTranslated(SlideWidthScale*t*vector.x,SlideHeightScale*t*vector.y,t*vector.z);
970 0 : CHECK_GL_ERROR();
971 : }
972 :
973 0 : void SRotate::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
974 : {
975 0 : CHECK_GL_ERROR();
976 0 : if(t <= mnT0)
977 0 : return;
978 0 : if(!mbInterpolate || t > mnT1)
979 0 : t = mnT1;
980 0 : t = intervalInter(t,mnT0,mnT1);
981 0 : glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,origin.z);
982 0 : glScaled(SlideWidthScale,SlideHeightScale,1);
983 0 : glRotated(t*angle,axis.x,axis.y,axis.z);
984 0 : glScaled(1/SlideWidthScale,1/SlideHeightScale,1);
985 0 : glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-origin.z);
986 0 : CHECK_GL_ERROR();
987 : }
988 :
989 0 : void SScale::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
990 : {
991 0 : CHECK_GL_ERROR();
992 0 : if(t <= mnT0)
993 0 : return;
994 0 : if(!mbInterpolate || t > mnT1)
995 0 : t = mnT1;
996 0 : t = intervalInter(t,mnT0,mnT1);
997 0 : glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,origin.z);
998 0 : glScaled((1-t) + t*scale.x,(1-t) + t*scale.y,(1-t) + t*scale.z);
999 0 : glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-origin.z);
1000 0 : CHECK_GL_ERROR();
1001 : }
1002 :
1003 0 : void RotateAndScaleDepthByWidth::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
1004 : {
1005 0 : CHECK_GL_ERROR();
1006 0 : if(t <= mnT0)
1007 0 : return;
1008 0 : if(!mbInterpolate || t > mnT1)
1009 0 : t = mnT1;
1010 0 : t = intervalInter(t,mnT0,mnT1);
1011 0 : glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,SlideWidthScale*origin.z);
1012 0 : glRotated(t*angle,axis.x,axis.y,axis.z);
1013 0 : glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-SlideWidthScale*origin.z);
1014 0 : CHECK_GL_ERROR();
1015 : }
1016 :
1017 0 : void RotateAndScaleDepthByHeight::interpolate(double t,double SlideWidthScale,double SlideHeightScale) const
1018 : {
1019 0 : CHECK_GL_ERROR();
1020 0 : if(t <= mnT0)
1021 0 : return;
1022 0 : if(!mbInterpolate || t > mnT1)
1023 0 : t = mnT1;
1024 0 : t = intervalInter(t,mnT0,mnT1);
1025 0 : glTranslated(SlideWidthScale*origin.x,SlideHeightScale*origin.y,SlideHeightScale*origin.z);
1026 0 : glRotated(t*angle,axis.x,axis.y,axis.z);
1027 0 : glTranslated(-SlideWidthScale*origin.x,-SlideHeightScale*origin.y,-SlideHeightScale*origin.z);
1028 0 : CHECK_GL_ERROR();
1029 : }
1030 :
1031 0 : SEllipseTranslate::SEllipseTranslate(double dWidth, double dHeight, double dStartPosition,
1032 : double dEndPosition, bool bInter, double T0, double T1):
1033 0 : Operation(bInter, T0, T1)
1034 : {
1035 0 : width = dWidth;
1036 0 : height = dHeight;
1037 0 : startPosition = dStartPosition;
1038 0 : endPosition = dEndPosition;
1039 0 : }
1040 :
1041 0 : void SEllipseTranslate::interpolate(double t,double /* SlideWidthScale */,double /* SlideHeightScale */) const
1042 : {
1043 0 : if(t <= mnT0)
1044 0 : return;
1045 0 : if(!mbInterpolate || t > mnT1)
1046 0 : t = mnT1;
1047 0 : t = intervalInter(t,mnT0,mnT1);
1048 :
1049 : double a1, a2, x, y;
1050 0 : a1 = startPosition*2*M_PI;
1051 0 : a2 = (startPosition + t*(endPosition - startPosition))*2*M_PI;
1052 0 : x = width*(cos (a2) - cos (a1))/2;
1053 0 : y = height*(sin (a2) - sin (a1))/2;
1054 :
1055 0 : glTranslated(x, 0, y);
1056 : }
1057 :
1058 0 : Primitive& Primitive::operator=(const Primitive& rvalue)
1059 : {
1060 0 : Primitive aTmp(rvalue);
1061 0 : swap(aTmp);
1062 0 : return *this;
1063 : }
1064 :
1065 0 : Primitive::Primitive(const Primitive& rvalue)
1066 : : Operations(rvalue.Operations)
1067 : , Vertices(rvalue.Vertices)
1068 : , Normals(rvalue.Normals)
1069 0 : , TexCoords(rvalue.TexCoords)
1070 : {
1071 0 : }
1072 :
1073 0 : void Primitive::swap(Primitive& rOther)
1074 : {
1075 : using std::swap;
1076 :
1077 0 : swap(Operations, rOther.Operations);
1078 0 : swap(Vertices, rOther.Vertices);
1079 0 : swap(Normals, rOther.Normals);
1080 0 : swap(TexCoords, rOther.TexCoords);
1081 0 : }
1082 :
1083 0 : void Primitive::pushTriangle(const glm::vec2& SlideLocation0,const glm::vec2& SlideLocation1,const glm::vec2& SlideLocation2)
1084 : {
1085 0 : vector<glm::vec3> Verts;
1086 0 : vector<glm::vec2> Texs;
1087 0 : Verts.reserve(3);
1088 0 : Texs.reserve(3);
1089 :
1090 0 : Verts.push_back(glm::vec3( 2*SlideLocation0.x - 1, -2*SlideLocation0.y + 1 , 0.0 ));
1091 0 : Verts.push_back(glm::vec3( 2*SlideLocation1.x - 1, -2*SlideLocation1.y + 1 , 0.0 ));
1092 0 : Verts.push_back(glm::vec3( 2*SlideLocation2.x - 1, -2*SlideLocation2.y + 1 , 0.0 ));
1093 :
1094 : //figure out if they're facing the correct way, and make them face the correct way.
1095 0 : glm::vec3 Normal( glm::cross( Verts[0] - Verts[1] , Verts[1] - Verts[2] ) );
1096 0 : if(Normal.z >= 0.0)//if the normal is facing us
1097 : {
1098 0 : Texs.push_back(SlideLocation0);
1099 0 : Texs.push_back(SlideLocation1);
1100 0 : Texs.push_back(SlideLocation2);
1101 : }
1102 : else // if the normal is facing away from us, make it face us
1103 : {
1104 0 : Texs.push_back(SlideLocation0);
1105 0 : Texs.push_back(SlideLocation2);
1106 0 : Texs.push_back(SlideLocation1);
1107 0 : Verts.clear();
1108 0 : Verts.push_back(glm::vec3( 2*SlideLocation0.x - 1, -2*SlideLocation0.y + 1 , 0.0 ));
1109 0 : Verts.push_back(glm::vec3( 2*SlideLocation2.x - 1, -2*SlideLocation2.y + 1 , 0.0 ));
1110 0 : Verts.push_back(glm::vec3( 2*SlideLocation1.x - 1, -2*SlideLocation1.y + 1 , 0.0 ));
1111 : }
1112 :
1113 0 : Vertices.push_back(Verts[0]);
1114 0 : Vertices.push_back(Verts[1]);
1115 0 : Vertices.push_back(Verts[2]);
1116 :
1117 0 : TexCoords.push_back(Texs[0]);
1118 0 : TexCoords.push_back(Texs[1]);
1119 0 : TexCoords.push_back(Texs[2]);
1120 :
1121 0 : Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
1122 0 : Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
1123 0 : Normals.push_back(glm::vec3(0,0,1));//all normals always face the screen when untransformed.
1124 0 : }
1125 :
1126 : namespace
1127 : {
1128 :
1129 0 : class DiamondTransition : public OGLTransitionImpl
1130 : {
1131 : public:
1132 0 : DiamondTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1133 0 : : OGLTransitionImpl(rScene, rSettings)
1134 0 : {}
1135 :
1136 : private:
1137 : virtual void prepare( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight ) SAL_OVERRIDE;
1138 : // mmPrepare = &OGLTransitionImpl::prepareDiamond;
1139 : };
1140 :
1141 0 : void DiamondTransition::prepare( double nTime, double /* SlideWidth */, double /* SlideHeight */, double /* DispWidth */, double /* DispHeight */ )
1142 : {
1143 0 : Primitive Slide1, Slide2;
1144 :
1145 0 : Slide1.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
1146 0 : Slide1.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
1147 0 : Primitives_t aEnteringSlidePrimitives;
1148 0 : aEnteringSlidePrimitives.push_back (Slide1);
1149 :
1150 0 : if( nTime >= 0.5 ) {
1151 0 : double m = 1 - nTime;
1152 :
1153 0 : Slide2.pushTriangle (glm::vec2 (0,0), glm::vec2 (m,0), glm::vec2 (0,m));
1154 0 : Slide2.pushTriangle (glm::vec2 (nTime,0), glm::vec2 (1,0), glm::vec2 (1,m));
1155 0 : Slide2.pushTriangle (glm::vec2 (1,nTime), glm::vec2 (1,1), glm::vec2 (nTime,1));
1156 0 : Slide2.pushTriangle (glm::vec2 (0,nTime), glm::vec2 (m,1), glm::vec2 (0,1));
1157 : } else {
1158 0 : double l = 0.5 - nTime;
1159 0 : double h = 0.5 + nTime;
1160 :
1161 0 : Slide2.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0.5,l));
1162 0 : Slide2.pushTriangle (glm::vec2 (0.5,l), glm::vec2 (1,0), glm::vec2 (h,0.5));
1163 0 : Slide2.pushTriangle (glm::vec2 (1,0), glm::vec2 (1,1), glm::vec2 (h,0.5));
1164 0 : Slide2.pushTriangle (glm::vec2 (h,0.5), glm::vec2 (1,1), glm::vec2 (0.5,h));
1165 0 : Slide2.pushTriangle (glm::vec2 (0.5,h), glm::vec2 (1,1), glm::vec2 (0,1));
1166 0 : Slide2.pushTriangle (glm::vec2 (l,0.5), glm::vec2 (0.5,h), glm::vec2 (0,1));
1167 0 : Slide2.pushTriangle (glm::vec2 (0,0), glm::vec2 (l,0.5), glm::vec2 (0,1));
1168 0 : Slide2.pushTriangle (glm::vec2 (0,0), glm::vec2 (0.5,l), glm::vec2 (l,0.5));
1169 : }
1170 0 : Slide2.Operations.push_back (makeSTranslate (glm::vec3 (0, 0, 0.00000001), false, -1, 0));
1171 0 : Primitives_t aLeavingSlidePrimitives;
1172 0 : aLeavingSlidePrimitives.push_back (Slide2);
1173 :
1174 0 : setScene(TransitionScene(aLeavingSlidePrimitives, aEnteringSlidePrimitives));
1175 0 : }
1176 :
1177 : shared_ptr<OGLTransitionImpl>
1178 0 : makeDiamondTransition(const TransitionSettings& rSettings)
1179 : {
1180 0 : return make_shared<DiamondTransition>(TransitionScene(), rSettings);
1181 : }
1182 :
1183 : }
1184 :
1185 0 : boost::shared_ptr<OGLTransitionImpl> makeDiamond()
1186 : {
1187 0 : TransitionSettings aSettings;
1188 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
1189 :
1190 0 : return makeDiamondTransition(aSettings);
1191 : }
1192 :
1193 0 : boost::shared_ptr<OGLTransitionImpl> makeVenetianBlinds( bool vertical, int parts )
1194 : {
1195 : static double t30 = tan( M_PI/6.0 );
1196 0 : double n, ln = 0;
1197 0 : double p = 1.0/parts;
1198 :
1199 0 : Primitives_t aLeavingSlide;
1200 0 : Primitives_t aEnteringSlide;
1201 0 : for( int i=0; i<parts; i++ ) {
1202 0 : Primitive Slide;
1203 0 : n = (i + 1)/(double)parts;
1204 0 : if( vertical ) {
1205 0 : Slide.pushTriangle (glm::vec2 (ln,0), glm::vec2 (n,0), glm::vec2 (ln,1));
1206 0 : Slide.pushTriangle (glm::vec2 (n,0), glm::vec2 (ln,1), glm::vec2 (n,1));
1207 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByWidth(glm::vec3(0, 1, 0), glm::vec3(n + ln - 1, 0, -t30*p), -120, true, 0.0, 1.0));
1208 : } else {
1209 0 : Slide.pushTriangle (glm::vec2 (0,ln), glm::vec2 (1,ln), glm::vec2 (0,n));
1210 0 : Slide.pushTriangle (glm::vec2 (1,ln), glm::vec2 (0,n), glm::vec2 (1,n));
1211 0 : Slide.Operations.push_back(makeRotateAndScaleDepthByHeight(glm::vec3(1, 0, 0), glm::vec3(0, 1 - n - ln, -t30*p), -120, true, 0.0, 1.0));
1212 : }
1213 0 : aLeavingSlide.push_back (Slide);
1214 :
1215 0 : if( vertical ) {
1216 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(0, 1, 0), glm::vec3(2*n - 1, 0, 0), -60, false, -1, 0));
1217 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(0, 1, 0), glm::vec3(n + ln - 1, 0, 0), 180, false, -1, 0));
1218 : } else {
1219 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(1, 0, 0), glm::vec3(0, 1 - 2*n, 0), -60, false, -1, 0));
1220 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(1, 0, 0), glm::vec3(0, 1 - n - ln, 0), 180, false, -1, 0));
1221 : }
1222 0 : aEnteringSlide.push_back (Slide);
1223 0 : ln = n;
1224 0 : }
1225 :
1226 0 : return makeSimpleTransition(aLeavingSlide, aEnteringSlide);
1227 : }
1228 :
1229 : namespace
1230 : {
1231 :
1232 0 : class FadeSmoothlyTransition : public OGLTransitionImpl
1233 : {
1234 : public:
1235 0 : FadeSmoothlyTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1236 0 : : OGLTransitionImpl(rScene, rSettings)
1237 0 : {}
1238 :
1239 : private:
1240 : virtual void displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) SAL_OVERRIDE;
1241 : };
1242 :
1243 0 : void FadeSmoothlyTransition::displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale )
1244 : {
1245 0 : CHECK_GL_ERROR();
1246 0 : applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
1247 :
1248 0 : CHECK_GL_ERROR();
1249 0 : glDisable(GL_DEPTH_TEST);
1250 :
1251 0 : CHECK_GL_ERROR();
1252 0 : displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
1253 0 : CHECK_GL_ERROR();
1254 :
1255 0 : CHECK_GL_ERROR();
1256 0 : glDisable(GL_LIGHTING);
1257 0 : CHECK_GL_ERROR();
1258 0 : glEnable(GL_BLEND);
1259 0 : CHECK_GL_ERROR();
1260 0 : glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1261 0 : CHECK_GL_ERROR();
1262 0 : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1263 0 : CHECK_GL_ERROR();
1264 0 : glColor4f( 1, 1, 1, nTime );
1265 0 : CHECK_GL_ERROR();
1266 0 : displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
1267 0 : CHECK_GL_ERROR();
1268 0 : glDisable(GL_BLEND);
1269 0 : CHECK_GL_ERROR();
1270 0 : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1271 0 : CHECK_GL_ERROR();
1272 0 : glEnable(GL_LIGHTING);
1273 0 : CHECK_GL_ERROR();
1274 :
1275 0 : glEnable(GL_DEPTH_TEST);
1276 0 : CHECK_GL_ERROR();
1277 0 : }
1278 :
1279 : shared_ptr<OGLTransitionImpl>
1280 0 : makeFadeSmoothlyTransition(
1281 : const Primitives_t& rLeavingSlidePrimitives,
1282 : const Primitives_t& rEnteringSlidePrimitives,
1283 : const TransitionSettings& rSettings)
1284 : {
1285 : return make_shared<FadeSmoothlyTransition>(
1286 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
1287 0 : rSettings)
1288 : ;
1289 : }
1290 :
1291 : }
1292 :
1293 0 : boost::shared_ptr<OGLTransitionImpl> makeFadeSmoothly()
1294 : {
1295 0 : Primitive Slide;
1296 :
1297 0 : Slide.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
1298 0 : Slide.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
1299 0 : Primitives_t aLeavingSlide;
1300 0 : aLeavingSlide.push_back (Slide);
1301 0 : Primitives_t aEnteringSlide;
1302 0 : aEnteringSlide.push_back (Slide);
1303 :
1304 0 : TransitionSettings aSettings;
1305 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
1306 :
1307 0 : return makeFadeSmoothlyTransition(aLeavingSlide, aEnteringSlide, aSettings);
1308 : }
1309 :
1310 : namespace
1311 : {
1312 :
1313 0 : class FadeThroughBlackTransition : public OGLTransitionImpl
1314 : {
1315 : public:
1316 0 : FadeThroughBlackTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1317 0 : : OGLTransitionImpl(rScene, rSettings)
1318 0 : {}
1319 :
1320 : private:
1321 : virtual void displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) SAL_OVERRIDE;
1322 : };
1323 :
1324 0 : void FadeThroughBlackTransition::displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale )
1325 : {
1326 0 : CHECK_GL_ERROR();
1327 0 : applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
1328 :
1329 0 : glDisable(GL_DEPTH_TEST);
1330 :
1331 0 : glDisable(GL_LIGHTING);
1332 0 : glEnable(GL_BLEND);
1333 0 : glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1334 0 : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1335 0 : if( nTime < 0.5 ) {
1336 0 : glColor4f( 1, 1, 1, 1 - nTime*2 );
1337 0 : displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
1338 : } else {
1339 0 : glColor4f( 1, 1, 1, (nTime - 0.5)*2 );
1340 0 : displaySlide( nTime, glEnteringSlideTex, getScene().getEnteringSlide(), SlideWidthScale, SlideHeightScale );
1341 : }
1342 0 : glDisable(GL_BLEND);
1343 0 : glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1344 0 : glEnable(GL_LIGHTING);
1345 :
1346 0 : glEnable(GL_DEPTH_TEST);
1347 0 : CHECK_GL_ERROR();
1348 0 : }
1349 :
1350 : shared_ptr<OGLTransitionImpl>
1351 0 : makeFadeThroughBlackTransition(
1352 : const Primitives_t& rLeavingSlidePrimitives,
1353 : const Primitives_t& rEnteringSlidePrimitives,
1354 : const TransitionSettings& rSettings)
1355 : {
1356 : return make_shared<FadeThroughBlackTransition>(
1357 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
1358 0 : rSettings)
1359 : ;
1360 : }
1361 :
1362 : }
1363 :
1364 0 : boost::shared_ptr<OGLTransitionImpl> makeFadeThroughBlack()
1365 : {
1366 0 : Primitive Slide;
1367 :
1368 0 : Slide.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
1369 0 : Slide.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
1370 0 : Primitives_t aLeavingSlide;
1371 0 : aLeavingSlide.push_back (Slide);
1372 0 : Primitives_t aEnteringSlide;
1373 0 : aEnteringSlide.push_back (Slide);
1374 :
1375 0 : TransitionSettings aSettings;
1376 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
1377 :
1378 0 : return makeFadeThroughBlackTransition(aLeavingSlide, aEnteringSlide, aSettings);
1379 : }
1380 :
1381 : namespace
1382 : {
1383 :
1384 0 : class ShaderTransition : public OGLTransitionImpl
1385 : {
1386 : protected:
1387 0 : ShaderTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1388 : : OGLTransitionImpl(rScene, rSettings)
1389 : , m_nProgramObject(0)
1390 0 : , m_nHelperTexture(0)
1391 0 : {}
1392 :
1393 : private:
1394 : virtual void displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale ) SAL_OVERRIDE;
1395 : virtual void prepareTransition( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex ) SAL_OVERRIDE;
1396 : virtual void finishTransition() SAL_OVERRIDE;
1397 : virtual GLuint makeShader() = 0;
1398 :
1399 : void impl_preparePermShader();
1400 :
1401 : private:
1402 : /** GLSL program object
1403 : */
1404 : GLuint m_nProgramObject;
1405 :
1406 : /** various data */
1407 : GLuint m_nHelperTexture;
1408 : };
1409 :
1410 0 : void ShaderTransition::displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex,
1411 : double SlideWidthScale, double SlideHeightScale )
1412 : {
1413 0 : CHECK_GL_ERROR();
1414 0 : applyOverallOperations( nTime, SlideWidthScale, SlideHeightScale );
1415 :
1416 0 : if( m_nProgramObject ) {
1417 0 : GLint location = glGetUniformLocation( m_nProgramObject, "time" );
1418 0 : if( location != -1 ) {
1419 0 : glUniform1f( location, nTime );
1420 : }
1421 : }
1422 :
1423 0 : glActiveTexture( GL_TEXTURE2 );
1424 0 : glBindTexture( GL_TEXTURE_2D, glEnteringSlideTex );
1425 0 : glActiveTexture( GL_TEXTURE0 );
1426 :
1427 0 : displaySlide( nTime, glLeavingSlideTex, getScene().getLeavingSlide(), SlideWidthScale, SlideHeightScale );
1428 0 : CHECK_GL_ERROR();
1429 0 : }
1430 :
1431 0 : void ShaderTransition::prepareTransition( ::sal_Int32 /* glLeavingSlideTex */, ::sal_Int32 /* glEnteringSlideTex */ )
1432 : {
1433 0 : m_nProgramObject = makeShader();
1434 :
1435 0 : impl_preparePermShader();
1436 0 : }
1437 :
1438 0 : void ShaderTransition::finishTransition()
1439 : {
1440 0 : CHECK_GL_ERROR();
1441 0 : if( m_nProgramObject ) {
1442 0 : glDeleteProgram( m_nProgramObject );
1443 0 : m_nProgramObject = 0;
1444 : }
1445 0 : if ( m_nHelperTexture )
1446 : {
1447 0 : glDeleteTextures( 1, &m_nHelperTexture );
1448 0 : m_nHelperTexture = 0;
1449 : }
1450 0 : CHECK_GL_ERROR();
1451 0 : }
1452 :
1453 : int permutation256 [256]= {
1454 : 215, 100, 200, 204, 233, 50, 85, 196,
1455 : 71, 141, 122, 160, 93, 131, 243, 234,
1456 : 162, 183, 36, 155, 4, 62, 35, 205,
1457 : 40, 102, 33, 27, 255, 55, 214, 156,
1458 : 75, 163, 134, 126, 249, 74, 197, 228,
1459 : 72, 90, 206, 235, 17, 22, 49, 169,
1460 : 227, 89, 16, 5, 117, 60, 248, 230,
1461 : 217, 68, 138, 96, 194, 170, 136, 10,
1462 : 112, 238, 184, 189, 176, 42, 225, 212,
1463 : 84, 58, 175, 244, 150, 168, 219, 236,
1464 : 101, 208, 123, 37, 164, 110, 158, 201,
1465 : 78, 114, 57, 48, 70, 142, 106, 43,
1466 : 232, 26, 32, 252, 239, 98, 191, 94,
1467 : 59, 149, 39, 187, 203, 190, 19, 13,
1468 : 133, 45, 61, 247, 23, 34, 20, 52,
1469 : 118, 209, 146, 193, 222, 18, 1, 152,
1470 : 46, 41, 91, 148, 115, 25, 135, 77,
1471 : 254, 147, 224, 161, 9, 213, 223, 250,
1472 : 231, 251, 127, 166, 63, 179, 81, 130,
1473 : 139, 28, 120, 151, 241, 86, 111, 0,
1474 : 88, 153, 172, 182, 159, 105, 178, 47,
1475 : 51, 167, 65, 66, 92, 73, 198, 211,
1476 : 245, 195, 31, 220, 140, 76, 221, 186,
1477 : 154, 185, 56, 83, 38, 165, 109, 67,
1478 : 124, 226, 132, 53, 229, 29, 12, 181,
1479 : 121, 24, 207, 199, 177, 113, 30, 80,
1480 : 3, 97, 188, 79, 216, 173, 8, 145,
1481 : 87, 128, 180, 237, 240, 137, 125, 104,
1482 : 15, 242, 119, 246, 103, 143, 95, 144,
1483 : 2, 44, 69, 157, 192, 174, 14, 54,
1484 : 218, 82, 64, 210, 11, 6, 129, 21,
1485 : 116, 171, 99, 202, 7, 107, 253, 108
1486 : };
1487 :
1488 0 : void initPermTexture(GLuint *texID)
1489 : {
1490 0 : CHECK_GL_ERROR();
1491 0 : glGenTextures(1, texID);
1492 0 : glBindTexture(GL_TEXTURE_2D, *texID);
1493 :
1494 : static bool initialized = false;
1495 : static unsigned char permutation2D[256*256*4];
1496 0 : if( !initialized ) {
1497 : int x, y;
1498 :
1499 0 : for( y=0; y < 256; y++ )
1500 0 : for( x=0; x < 256; x++ )
1501 0 : permutation2D[x*4 + y*1024] = permutation256[(y + permutation256[x]) & 0xff];
1502 :
1503 0 : initialized = true;
1504 : }
1505 :
1506 0 : glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, permutation2D );
1507 0 : glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
1508 0 : glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
1509 0 : CHECK_GL_ERROR();
1510 0 : }
1511 :
1512 0 : void ShaderTransition::impl_preparePermShader()
1513 : {
1514 0 : CHECK_GL_ERROR();
1515 0 : if( m_nProgramObject ) {
1516 0 : glUseProgram( m_nProgramObject );
1517 :
1518 0 : GLint location = glGetUniformLocation( m_nProgramObject, "leavingSlideTexture" );
1519 0 : if( location != -1 ) {
1520 0 : glUniform1i( location, 0 ); // texture unit 0
1521 : }
1522 :
1523 0 : glActiveTexture(GL_TEXTURE1);
1524 0 : if( !m_nHelperTexture )
1525 0 : initPermTexture( &m_nHelperTexture );
1526 0 : glActiveTexture(GL_TEXTURE0);
1527 :
1528 0 : location = glGetUniformLocation( m_nProgramObject, "permTexture" );
1529 0 : if( location != -1 ) {
1530 0 : glUniform1i( location, 1 ); // texture unit 1
1531 : }
1532 :
1533 0 : location = glGetUniformLocation( m_nProgramObject, "enteringSlideTexture" );
1534 0 : if( location != -1 ) {
1535 0 : glUniform1i( location, 2 ); // texture unit 2
1536 : }
1537 : }
1538 0 : CHECK_GL_ERROR();
1539 0 : }
1540 :
1541 : }
1542 :
1543 : namespace
1544 : {
1545 :
1546 0 : class StaticNoiseTransition : public ShaderTransition
1547 : {
1548 : public:
1549 0 : StaticNoiseTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1550 0 : : ShaderTransition(rScene, rSettings)
1551 0 : {}
1552 :
1553 : private:
1554 : virtual GLuint makeShader() SAL_OVERRIDE;
1555 : };
1556 :
1557 0 : GLuint StaticNoiseTransition::makeShader()
1558 : {
1559 0 : return OpenGLHelper::LoadShaders( "basicVertexShader", "staticFragmentShader" );
1560 : }
1561 :
1562 : shared_ptr<OGLTransitionImpl>
1563 0 : makeStaticNoiseTransition(
1564 : const Primitives_t& rLeavingSlidePrimitives,
1565 : const Primitives_t& rEnteringSlidePrimitives,
1566 : const TransitionSettings& rSettings)
1567 : {
1568 : return make_shared<StaticNoiseTransition>(
1569 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
1570 0 : rSettings)
1571 : ;
1572 : }
1573 :
1574 : }
1575 :
1576 0 : boost::shared_ptr<OGLTransitionImpl> makeStatic()
1577 : {
1578 0 : Primitive Slide;
1579 :
1580 0 : Slide.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
1581 0 : Slide.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
1582 0 : Primitives_t aLeavingSlide;
1583 0 : aLeavingSlide.push_back (Slide);
1584 0 : Primitives_t aEnteringSlide;
1585 0 : aEnteringSlide.push_back (Slide);
1586 :
1587 0 : TransitionSettings aSettings;
1588 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
1589 0 : aSettings.mnRequiredGLVersion = 2.0;
1590 :
1591 0 : return makeStaticNoiseTransition(aLeavingSlide, aEnteringSlide, aSettings);
1592 : }
1593 :
1594 : namespace
1595 : {
1596 :
1597 0 : class DissolveTransition : public ShaderTransition
1598 : {
1599 : public:
1600 0 : DissolveTransition(const TransitionScene& rScene, const TransitionSettings& rSettings)
1601 0 : : ShaderTransition(rScene, rSettings)
1602 0 : {}
1603 :
1604 : private:
1605 : virtual GLuint makeShader() SAL_OVERRIDE;
1606 : };
1607 :
1608 0 : GLuint DissolveTransition::makeShader()
1609 : {
1610 0 : return OpenGLHelper::LoadShaders( "basicVertexShader", "dissolveFragmentShader" );
1611 : }
1612 :
1613 : shared_ptr<OGLTransitionImpl>
1614 0 : makeDissolveTransition(
1615 : const Primitives_t& rLeavingSlidePrimitives,
1616 : const Primitives_t& rEnteringSlidePrimitives,
1617 : const TransitionSettings& rSettings)
1618 : {
1619 : return make_shared<DissolveTransition>(
1620 : TransitionScene(rLeavingSlidePrimitives, rEnteringSlidePrimitives),
1621 0 : rSettings)
1622 : ;
1623 : }
1624 :
1625 : }
1626 :
1627 0 : boost::shared_ptr<OGLTransitionImpl> makeDissolve()
1628 : {
1629 0 : Primitive Slide;
1630 :
1631 0 : Slide.pushTriangle (glm::vec2 (0,0), glm::vec2 (1,0), glm::vec2 (0,1));
1632 0 : Slide.pushTriangle (glm::vec2 (1,0), glm::vec2 (0,1), glm::vec2 (1,1));
1633 0 : Primitives_t aLeavingSlide;
1634 0 : aLeavingSlide.push_back (Slide);
1635 0 : Primitives_t aEnteringSlide;
1636 0 : aEnteringSlide.push_back (Slide);
1637 :
1638 0 : TransitionSettings aSettings;
1639 0 : aSettings.mbUseMipMapLeaving = aSettings.mbUseMipMapEntering = false;
1640 0 : aSettings.mnRequiredGLVersion = 2.0;
1641 :
1642 0 : return makeDissolveTransition(aLeavingSlide, aEnteringSlide, aSettings);
1643 : }
1644 :
1645 0 : boost::shared_ptr<OGLTransitionImpl> makeNewsflash()
1646 : {
1647 0 : Primitive Slide;
1648 :
1649 0 : Slide.pushTriangle(glm::vec2(0,0),glm::vec2(1,0),glm::vec2(0,1));
1650 0 : Slide.pushTriangle(glm::vec2(1,0),glm::vec2(0,1),glm::vec2(1,1));
1651 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(0,0,1),glm::vec3(0,0,0),3000,true,0,0.5));
1652 0 : Slide.Operations.push_back(makeSScale(glm::vec3(0.01,0.01,0.01),glm::vec3(0,0,0),true,0,0.5));
1653 0 : Slide.Operations.push_back(makeSTranslate(glm::vec3(-10000, 0, 0),false, 0.5, 2));
1654 0 : Primitives_t aLeavingSlide;
1655 0 : aLeavingSlide.push_back(Slide);
1656 :
1657 0 : Slide.Operations.clear();
1658 0 : Slide.Operations.push_back(makeSRotate(glm::vec3(0,0,1),glm::vec3(0,0,0),-3000,true,0.5,1));
1659 0 : Slide.Operations.push_back(makeSTranslate(glm::vec3(-100, 0, 0),false, -1, 1));
1660 0 : Slide.Operations.push_back(makeSTranslate(glm::vec3(100, 0, 0),false, 0.5, 1));
1661 0 : Slide.Operations.push_back(makeSScale(glm::vec3(0.01,0.01,0.01),glm::vec3(0,0,0),false,-1,1));
1662 0 : Slide.Operations.push_back(makeSScale(glm::vec3(100,100,100),glm::vec3(0,0,0),true,0.5,1));
1663 0 : Primitives_t aEnteringSlide;
1664 0 : aEnteringSlide.push_back(Slide);
1665 :
1666 0 : Operations_t aOverallOperations;
1667 0 : aOverallOperations.push_back(makeSRotate(glm::vec3(0,0,1),glm::vec3(0.2,0.2,0),1080,true,0,1));
1668 :
1669 0 : return makeSimpleTransition(aLeavingSlide, aEnteringSlide, aOverallOperations);
1670 6 : }
1671 :
1672 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|