Branch data 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 : : #ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
29 : : #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
30 : :
31 : : #include <basegfx/vector/b2dvector.hxx>
32 : : #include <basegfx/vector/b3dvector.hxx>
33 : :
34 : : #include <vector>
35 : : #include <GL/gl.h>
36 : :
37 : : using namespace std;
38 : :
39 : : class Primitive;
40 : : class Operation;
41 : : class SceneObject;
42 : :
43 : :
44 : : /** OpenGL 3D Transition class. It implicitly is constructed from XOGLTransition
45 : :
46 : : This class is capable of making itself into many difference transitions. It holds Primitives and Operations on those primitives.
47 : : */
48 : : class OGLTransitionImpl
49 : : {
50 : : public:
51 : 0 : OGLTransitionImpl() :
52 : : mbUseMipMapLeaving( true ),
53 : : mbUseMipMapEntering( true ),
54 : : mnRequiredGLVersion( 1.0 ),
55 : : maLeavingSlidePrimitives(),
56 : : maEnteringSlidePrimitives(),
57 : : maSceneObjects(),
58 : : mbReflectSlides( false ),
59 : : mVertexObject( 0 ),
60 : : mFragmentObject( 0 ),
61 : : mProgramObject( 0 ),
62 : : maHelperTexture( 0 ),
63 : : mmPrepare( NULL ),
64 : : mmPrepareTransition( NULL ),
65 : : mmClearTransition( NULL ),
66 : 0 : mmDisplaySlides( NULL )
67 : 0 : {}
68 : :
69 : : ~OGLTransitionImpl();
70 : :
71 : : void prepare( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
72 : : void display( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
73 : : void finish();
74 : :
75 : : void makeOutsideCubeFaceToLeft();
76 : : void makeInsideCubeFaceToLeft();
77 : : void makeNByMTileFlip( ::sal_uInt16 n, ::sal_uInt16 m );
78 : : void makeRevolvingCircles( ::sal_uInt16 nCircles , ::sal_uInt16 nPointsOnCircles );
79 : : void makeHelix( ::sal_uInt16 nRows );
80 : : void makeFallLeaving();
81 : : void makeTurnAround();
82 : : void makeTurnDown();
83 : : void makeIris();
84 : : void makeRochade();
85 : : void makeVenetianBlinds( bool vertical, int parts );
86 : : void makeStatic();
87 : : void makeDissolve();
88 : : void makeNewsflash();
89 : :
90 : : /** 2D replacements
91 : : */
92 : : void makeDiamond();
93 : : void makeFadeSmoothly();
94 : : void makeFadeThroughBlack();
95 : :
96 : : /** Whether to use mipmaping for slides textures
97 : : */
98 : : bool mbUseMipMapLeaving;
99 : : bool mbUseMipMapEntering;
100 : :
101 : : /** which GL version does the transition require
102 : : */
103 : : float mnRequiredGLVersion;
104 : :
105 : : private:
106 : : /** clears all the primitives and operations
107 : : */
108 : : void clear();
109 : :
110 : : /** All the primitives that use the leaving slide texture
111 : : */
112 : : vector<Primitive> maLeavingSlidePrimitives;
113 : :
114 : : /** All the primitives that use the leaving slide texture
115 : : */
116 : : vector<Primitive> maEnteringSlidePrimitives;
117 : :
118 : : /** All the surrounding scene objects
119 : : */
120 : : vector<SceneObject*> maSceneObjects;
121 : :
122 : : /** All the operations that should be applied to both leaving and entering slide primitives. These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
123 : : */
124 : : vector<Operation*> OverallOperations;
125 : :
126 : : /** Whether to reflect slides, the reflection happens on flat surface beneath the slides.
127 : : ** Now it only works with slides which keep their rectangular shape together.
128 : : */
129 : : bool mbReflectSlides;
130 : :
131 : : /** GLSL objects, shaders and program
132 : : */
133 : : GLuint mVertexObject, mFragmentObject, mProgramObject;
134 : :
135 : : /** various data */
136 : : GLuint maHelperTexture;
137 : :
138 : : /** When this method is not NULL, it is called in display method to prepare the slides, scene, etc.
139 : : ** We might later replace this by cleaner derived class.
140 : : */
141 : : void (OGLTransitionImpl::*mmPrepare)( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
142 : :
143 : : /** When this method is not NULL, it is called after glx context is ready to let the transition prepare GL related things, like GLSL program.
144 : : ** We might later replace this by cleaner derived class.
145 : : */
146 : : void (OGLTransitionImpl::*mmPrepareTransition)( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
147 : :
148 : : /** When this method is not NULL, it is called when the transition needs to clear after itself, like delete own textures etc.
149 : : ** We might later replace this by cleaner derived class.
150 : : */
151 : : void (OGLTransitionImpl::*mmClearTransition)();
152 : :
153 : : /** When this method is not NULL, it is called in display method to display the slides.
154 : : ** We might later replace this by cleaner derived class.
155 : : */
156 : : void (OGLTransitionImpl::*mmDisplaySlides)( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
157 : :
158 : : void displaySlides( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
159 : : void displaySlide( double nTime, ::sal_Int32 glSlideTex, std::vector<Primitive>& primitives, double SlideWidthScale, double SlideHeightScale );
160 : : void displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
161 : : void applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale );
162 : :
163 : : /** various transitions helper methods
164 : : */
165 : : void prepareDiamond( double nTime, double SlideWidth, double SlideHeight,double DispWidth, double DispHeight );
166 : : void displaySlidesFadeSmoothly( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
167 : : void displaySlidesFadeThroughBlack( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
168 : : void displaySlidesRochade( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
169 : : void displaySlidesShaders( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
170 : : void prepareStatic( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
171 : : void prepareDissolve( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
172 : : void preparePermShader();
173 : : };
174 : :
175 : : class SceneObject
176 : : {
177 : : public:
178 : : SceneObject();
179 : : virtual ~SceneObject();
180 : :
181 : 0 : virtual void prepare() {};
182 : : virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
183 : 0 : virtual void finish() {};
184 : :
185 : : void pushPrimitive (const Primitive &p);
186 : :
187 : : protected:
188 : : /** All the surrounding scene primitives
189 : : */
190 : : vector<Primitive> maPrimitives;
191 : : };
192 : :
193 : 0 : class Iris : public SceneObject
194 : : {
195 : : public:
196 : : Iris ();
197 : :
198 : : virtual void prepare();
199 : : virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
200 : : virtual void finish();
201 : :
202 : : private:
203 : :
204 : : GLuint maTexture;
205 : : };
206 : :
207 : : /** This class is a list of Triangles that will share Operations, and could possibly share
208 : : */
209 : : class Primitive
210 : : {
211 : : public:
212 : 0 : Primitive() {}
213 : : // making copy constructor explicit makes the class un-suitable for use with stl containers
214 : : Primitive(const Primitive& rvalue);
215 : : ~Primitive();
216 : :
217 : : void applyOperations(double nTime, double SlideWidthScale, double SlideHeightScale);
218 : : void display(double nTime, double SlideWidthScale, double SlideHeightScale);
219 : : const Primitive& operator=(const Primitive& rvalue);
220 : :
221 : : /** PushBack a vertex,normal, and tex coord. Each SlideLocation is where on the slide is mapped to this location ( from (0,0) to (1,1) ). This will make sure the correct aspect ratio is used, and helps to make slides begin and end at the correct position. (0,0) is the top left of the slide, and (1,1) is the bottom right.
222 : :
223 : : @param SlideLocation0
224 : : Location of first Vertex on slide
225 : :
226 : : @param SlideLocation1
227 : : Location of second Vertex on slide
228 : :
229 : : @param SlideLocation2
230 : : Location of third Vertex on slide
231 : :
232 : : */
233 : : void pushTriangle(const basegfx::B2DVector& SlideLocation0,const basegfx::B2DVector& SlideLocation1,const basegfx::B2DVector& SlideLocation2);
234 : :
235 : : /** clear all the vertices, normals, tex coordinates, and normals
236 : : */
237 : : void clearTriangles();
238 : :
239 : : /** guards against directly changing the vertices
240 : :
241 : : @return
242 : : the list of vertices
243 : : */
244 : 0 : const vector<basegfx::B3DVector>& getVertices() const {return Vertices;}
245 : :
246 : : /** guards against directly changing the vertices
247 : : */
248 : : const vector<basegfx::B3DVector>& getNormals() const {return Normals;}
249 : :
250 : : /** guards against directly changing the vertices
251 : :
252 : : @return
253 : : the list of Texture Coordinates
254 : :
255 : : */
256 : : const vector<basegfx::B2DVector>& getTexCoords() const {return TexCoords;}
257 : :
258 : : /** list of Operations to be performed on this primitive.These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
259 : :
260 : : @return
261 : : the list of Operations
262 : :
263 : : */
264 : : vector<Operation*> Operations;
265 : :
266 : : private:
267 : : /** list of vertices
268 : : */
269 : : vector<basegfx::B3DVector> Vertices;
270 : :
271 : : /** list of Normals
272 : : */
273 : : vector<basegfx::B3DVector> Normals;
274 : :
275 : : /** list of Texture Coordinates
276 : : */
277 : : vector<basegfx::B2DVector> TexCoords;
278 : : };
279 : :
280 : : /** This class is to be derived to make any operation (tranform) you may need in order to construct your transitions
281 : : */
282 : 0 : class Operation
283 : : {
284 : : public:
285 : 0 : Operation(){}
286 : 0 : virtual ~Operation(){}
287 : :
288 : : /** Should this operation be interpolated . If TRUE, the transform will smoothly move from making no difference from t = 0.0 to nT0 to being completely transformed from t = nT1 to 1. If FALSE, the transform will be inneffectual from t = 0 to nT0, and completely transformed from t = nT0 to 1.
289 : : */
290 : : bool bInterpolate;
291 : :
292 : : /** time to begin the transformation
293 : : */
294 : : double nT0;
295 : :
296 : : /** time to finish the transformation
297 : : */
298 : : double nT1;
299 : : public:
300 : : /** this is the function that is called to give the Operation to OpenGL.
301 : :
302 : : @param t
303 : : time from t = 0 to t = 1
304 : :
305 : : @param SlideWidthScale
306 : : width of slide divided by width of window
307 : :
308 : : @param SlideHeightScale
309 : : height of slide divided by height of window
310 : :
311 : : */
312 : : virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) = 0;
313 : :
314 : : /** return a copy of this operation
315 : : */
316 : : virtual Operation* clone() = 0;
317 : : };
318 : :
319 : : /** this class is a generic CounterClockWise(CCW) rotation with an axis angle
320 : : */
321 : 0 : class SRotate: public Operation
322 : : {
323 : : public:
324 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
325 : : virtual SRotate* clone();
326 : :
327 : : /** Constructor
328 : :
329 : : @param Axis
330 : : axis to rotate about
331 : :
332 : : @param Origin
333 : : position that rotation axis runs through
334 : :
335 : : @param Angle
336 : : angle in radians of CCW rotation
337 : :
338 : : @param bInter
339 : : see Operation
340 : :
341 : : @param T0
342 : : transformation starting time
343 : :
344 : : @param T1
345 : : transformation ending time
346 : :
347 : : */
348 : : SRotate(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
349 : 0 : ~SRotate(){}
350 : : private:
351 : : /** axis to rotate CCW about
352 : : */
353 : : basegfx::B3DVector axis;
354 : :
355 : : /** position that rotation axis runs through
356 : : */
357 : : basegfx::B3DVector origin;
358 : :
359 : : /** angle in radians of CCW rotation
360 : : */
361 : : double angle;
362 : : };
363 : :
364 : : /** scaling transformation
365 : : */
366 : 0 : class SScale: public Operation
367 : : {
368 : : public:
369 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
370 : : SScale* clone();
371 : :
372 : : /** Constructor
373 : :
374 : : @param Scale
375 : : amount to scale by
376 : :
377 : : @param Origin
378 : : position that rotation axis runs through
379 : :
380 : : @param bInter
381 : : see Operation
382 : :
383 : : @param T0
384 : : transformation starting time
385 : :
386 : : @param T1
387 : : transformation ending time
388 : :
389 : : */
390 : : SScale(const basegfx::B3DVector& Scale, const basegfx::B3DVector& Origin,bool bInter, double T0, double T1);
391 : 0 : ~SScale(){}
392 : : private:
393 : : basegfx::B3DVector scale;
394 : : basegfx::B3DVector origin;
395 : : };
396 : :
397 : : /** translation transformation
398 : : */
399 : 0 : class STranslate: public Operation
400 : : {
401 : : public:
402 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
403 : : STranslate* clone();
404 : :
405 : : /** Constructor
406 : :
407 : : @param Vector
408 : : vector to translate
409 : :
410 : : @param bInter
411 : : see Operation
412 : :
413 : : @param T0
414 : : transformation starting time
415 : :
416 : : @param T1
417 : : transformation ending time
418 : :
419 : : */
420 : : STranslate(const basegfx::B3DVector& Vector,bool bInter, double T0, double T1);
421 : 0 : ~STranslate(){}
422 : : private:
423 : : /** vector to translate by
424 : : */
425 : : basegfx::B3DVector vector;
426 : : };
427 : :
428 : : /** translation transformation
429 : : */
430 : 0 : class SEllipseTranslate: public Operation
431 : : {
432 : : public:
433 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
434 : : SEllipseTranslate* clone();
435 : :
436 : : /** Constructor
437 : :
438 : : @param Vector
439 : : vector to translate
440 : :
441 : : @param bInter
442 : : see Operation
443 : :
444 : : @param T0
445 : : transformation starting time
446 : :
447 : : @param T1
448 : : transformation ending time
449 : :
450 : : */
451 : : SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1);
452 : 0 : ~SEllipseTranslate(){}
453 : : private:
454 : : /** width and length of the ellipse
455 : : */
456 : : double width, height;
457 : :
458 : : /** start and end position on the ellipse <0,1>
459 : : */
460 : : double startPosition;
461 : : double endPosition;
462 : : };
463 : :
464 : : /** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window.
465 : : */
466 : 0 : class RotateAndScaleDepthByWidth: public Operation
467 : : {
468 : : public:
469 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
470 : : RotateAndScaleDepthByWidth* clone();
471 : :
472 : : RotateAndScaleDepthByWidth(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
473 : 0 : ~RotateAndScaleDepthByWidth(){}
474 : : private:
475 : : basegfx::B3DVector axis;
476 : : basegfx::B3DVector origin;
477 : : double angle;
478 : : };
479 : :
480 : : /** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window.
481 : : */
482 : 0 : class RotateAndScaleDepthByHeight: public Operation
483 : : {
484 : : public:
485 : : void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
486 : : RotateAndScaleDepthByHeight* clone();
487 : :
488 : : RotateAndScaleDepthByHeight(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
489 : 0 : ~RotateAndScaleDepthByHeight(){}
490 : : private:
491 : : basegfx::B3DVector axis;
492 : : basegfx::B3DVector origin;
493 : : double angle;
494 : : };
495 : :
496 : : #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
497 : :
498 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|