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