Update ooo320-m1
[ooovba.git] / slideshow / source / engine / OGLTrans / OGLTrans_TransitionImpl.hxx
blob2aa0529c78062fad039ca2ea9bfdf26ee6bf6a66
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OGLTrans_TransitionImpl.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
31 #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
33 #include <basegfx/vector/b2dvector.hxx>
34 #include <basegfx/vector/b3dvector.hxx>
36 #include <tools/prewin.h>
37 #include <tools/postwin.h>
39 #if defined( WNT )
40 #include <tools/prewin.h>
41 #include <tools/postwin.h>
42 #elif defined( OS2 )
43 #elif defined( QUARTZ )
44 #elif defined( UNX )
45 #endif
47 #include <vector>
48 #include <GL/gl.h>
50 using namespace std;
52 class Primitive;
53 class Operation;
54 class SceneObject;
57 /** OpenGL 3D Transition class. It implicitly is constructed from XOGLTransition
59 This class is capable of making itself into many difference transitions. It holds Primitives and Operations on those primitives.
61 class OGLTransitionImpl
63 public:
64 OGLTransitionImpl() :
65 mbUseMipMapLeaving( true ),
66 mbUseMipMapEntering( true ),
67 mnRequiredGLVersion( 1.0 ),
68 maLeavingSlidePrimitives(),
69 maEnteringSlidePrimitives(),
70 maSceneObjects(),
71 mbReflectSlides( false ),
72 mVertexObject( 0 ),
73 mFragmentObject( 0 ),
74 mProgramObject( 0 ),
75 maHelperTexture( 0 ),
76 mmPrepare( NULL ),
77 mmPrepareTransition( NULL ),
78 mmClearTransition( NULL ),
79 mmDisplaySlides( NULL )
82 ~OGLTransitionImpl();
84 void prepare( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
85 void display( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
86 void finish();
88 void makeOutsideCubeFaceToLeft();
89 void makeInsideCubeFaceToLeft();
90 void makeNByMTileFlip( ::sal_uInt16 n, ::sal_uInt16 m );
91 void makeRevolvingCircles( ::sal_uInt16 nCircles , ::sal_uInt16 nPointsOnCircles );
92 void makeHelix( ::sal_uInt16 nRows );
93 void makeFallLeaving();
94 void makeTurnAround();
95 void makeTurnDown();
96 void makeIris();
97 void makeRochade();
98 void makeVenetianBlinds( bool vertical, int parts );
99 void makeStatic();
100 void makeDissolve();
101 void makeNewsflash();
103 /** 2D replacements
105 void makeDiamond();
106 void makeFadeSmoothly();
107 void makeFadeThroughBlack();
109 /** Whether to use mipmaping for slides textures
111 bool mbUseMipMapLeaving;
112 bool mbUseMipMapEntering;
114 /** which GL version does the transition require
116 float mnRequiredGLVersion;
118 private:
119 /** clears all the primitives and operations
121 void clear();
123 /** All the primitives that use the leaving slide texture
125 vector<Primitive> maLeavingSlidePrimitives;
127 /** All the primitives that use the leaving slide texture
129 vector<Primitive> maEnteringSlidePrimitives;
131 /** All the surrounding scene objects
133 vector<SceneObject*> maSceneObjects;
135 /** 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.
137 vector<Operation*> OverallOperations;
139 /** Whether to reflect slides, the reflection happens on flat surface beneath the slides.
140 ** Now it only works with slides which keep their rectangular shape together.
142 bool mbReflectSlides;
144 /** GLSL objects, shaders and program
146 GLuint mVertexObject, mFragmentObject, mProgramObject;
148 /** various data */
149 GLuint maHelperTexture;
151 /** When this method is not NULL, it is called in display method to prepare the slides, scene, etc.
152 ** We might later replace this by cleaner derived class.
154 void (OGLTransitionImpl::*mmPrepare)( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
156 /** 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.
157 ** We might later replace this by cleaner derived class.
159 void (OGLTransitionImpl::*mmPrepareTransition)( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
161 /** When this method is not NULL, it is called when the transition needs to clear after itself, like delete own textures etc.
162 ** We might later replace this by cleaner derived class.
164 void (OGLTransitionImpl::*mmClearTransition)();
166 /** When this method is not NULL, it is called in display method to display the slides.
167 ** We might later replace this by cleaner derived class.
169 void (OGLTransitionImpl::*mmDisplaySlides)( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
171 void displaySlides( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
172 void displaySlide( double nTime, ::sal_Int32 glSlideTex, std::vector<Primitive>& primitives, double SlideWidthScale, double SlideHeightScale );
173 void displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
174 void applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale );
176 /** various transitions helper methods
178 void prepareDiamond( double nTime, double SlideWidth, double SlideHeight,double DispWidth, double DispHeight );
179 void displaySlidesFadeSmoothly( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
180 void displaySlidesFadeThroughBlack( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
181 void displaySlidesRochade( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
182 void displaySlidesShaders( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
183 void prepareStatic( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
184 void prepareDissolve( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
185 void preparePermShader();
188 class SceneObject
190 public:
191 SceneObject();
193 virtual void prepare() {};
194 virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
195 virtual void finish() {};
197 void pushPrimitive (const Primitive &p);
199 protected:
200 /** All the surrounding scene primitives
202 vector<Primitive> maPrimitives;
205 class Iris : public SceneObject
207 public:
208 Iris ();
210 virtual void prepare();
211 virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
212 virtual void finish();
214 private:
216 GLuint maTexture;
219 /** This class is a list of Triangles that will share Operations, and could possibly share
221 class Primitive
223 public:
224 Primitive() {}
225 // making copy constructor explicit makes the class un-suitable for use with stl containers
226 Primitive(const Primitive& rvalue);
227 ~Primitive();
229 void applyOperations(double nTime, double SlideWidthScale, double SlideHeightScale);
230 void display(double nTime, double SlideWidthScale, double SlideHeightScale);
231 const Primitive& operator=(const Primitive& rvalue);
233 /** 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.
235 @param SlideLocation0
236 Location of first Vertex on slide
238 @param SlideLocation1
239 Location of second Vertex on slide
241 @param SlideLocation2
242 Location of third Vertex on slide
245 void pushTriangle(const basegfx::B2DVector& SlideLocation0,const basegfx::B2DVector& SlideLocation1,const basegfx::B2DVector& SlideLocation2);
247 /** clear all the vertices, normals, tex coordinates, and normals
249 void clearTriangles();
251 /** guards against directly changing the vertices
253 @return
254 the list of vertices
256 const vector<basegfx::B3DVector>& getVertices() const {return Vertices;}
258 /** guards against directly changing the vertices
260 const vector<basegfx::B3DVector>& getNormals() const {return Normals;}
262 /** guards against directly changing the vertices
264 @return
265 the list of Texture Coordinates
268 const vector<basegfx::B2DVector>& getTexCoords() const {return TexCoords;}
270 /** 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.
272 @return
273 the list of Operations
276 vector<Operation*> Operations;
278 private:
279 /** list of vertices
281 vector<basegfx::B3DVector> Vertices;
283 /** list of Normals
285 vector<basegfx::B3DVector> Normals;
287 /** list of Texture Coordinates
289 vector<basegfx::B2DVector> TexCoords;
292 /** This class is to be derived to make any operation (tranform) you may need in order to construct your transitions
294 class Operation
296 public:
297 Operation(){}
298 virtual ~Operation(){}
300 /** 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.
302 bool bInterpolate;
304 /** time to begin the transformation
306 double nT0;
308 /** time to finish the transformation
310 double nT1;
311 public:
312 /** this is the function that is called to give the Operation to OpenGL.
314 @param t
315 time from t = 0 to t = 1
317 @param SlideWidthScale
318 width of slide divided by width of window
320 @param SlideHeightScale
321 height of slide divided by height of window
324 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) = 0;
326 /** return a copy of this operation
328 virtual Operation* clone() = 0;
331 /** this class is a generic CounterClockWise(CCW) rotation with an axis angle
333 class SRotate: public Operation
335 public:
336 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
337 virtual SRotate* clone();
339 /** Constructor
341 @param Axis
342 axis to rotate about
344 @param Origin
345 position that rotation axis runs through
347 @param Angle
348 angle in radians of CCW rotation
350 @param bInter
351 see Operation
353 @param T0
354 transformation starting time
356 @param T1
357 transformation ending time
360 SRotate(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
361 ~SRotate(){}
362 private:
363 /** axis to rotate CCW about
365 basegfx::B3DVector axis;
367 /** position that rotation axis runs through
369 basegfx::B3DVector origin;
371 /** angle in radians of CCW rotation
373 double angle;
376 /** scaling transformation
378 class SScale: public Operation
380 public:
381 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
382 SScale* clone();
384 /** Constructor
386 @param Scale
387 amount to scale by
389 @param Origin
390 position that rotation axis runs through
392 @param bInter
393 see Operation
395 @param T0
396 transformation starting time
398 @param T1
399 transformation ending time
402 SScale(const basegfx::B3DVector& Scale, const basegfx::B3DVector& Origin,bool bInter, double T0, double T1);
403 ~SScale(){}
404 private:
405 basegfx::B3DVector scale;
406 basegfx::B3DVector origin;
409 /** translation transformation
411 class STranslate: public Operation
413 public:
414 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
415 STranslate* clone();
417 /** Constructor
419 @param Vector
420 vector to translate
422 @param bInter
423 see Operation
425 @param T0
426 transformation starting time
428 @param T1
429 transformation ending time
432 STranslate(const basegfx::B3DVector& Vector,bool bInter, double T0, double T1);
433 ~STranslate(){}
434 private:
435 /** vector to translate by
437 basegfx::B3DVector vector;
440 /** translation transformation
442 class SEllipseTranslate: public Operation
444 public:
445 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
446 SEllipseTranslate* clone();
448 /** Constructor
450 @param Vector
451 vector to translate
453 @param bInter
454 see Operation
456 @param T0
457 transformation starting time
459 @param T1
460 transformation ending time
463 SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1);
464 ~SEllipseTranslate(){}
465 private:
466 /** width and length of the ellipse
468 double width, height;
470 /** start and end position on the ellipse <0,1>
472 double startPosition;
473 double endPosition;
476 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window.
478 class RotateAndScaleDepthByWidth: public Operation
480 public:
481 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
482 RotateAndScaleDepthByWidth* clone();
484 RotateAndScaleDepthByWidth(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
485 ~RotateAndScaleDepthByWidth(){}
486 private:
487 basegfx::B3DVector axis;
488 basegfx::B3DVector origin;
489 double angle;
492 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window.
494 class RotateAndScaleDepthByHeight: public Operation
496 public:
497 void interpolate(double t,double SlideWidthScale,double SlideHeightScale);
498 RotateAndScaleDepthByHeight* clone();
500 RotateAndScaleDepthByHeight(const basegfx::B3DVector& Axis,const basegfx::B3DVector& Origin,double Angle,bool bInter, double T0, double T1);
501 ~RotateAndScaleDepthByHeight(){}
502 private:
503 basegfx::B3DVector axis;
504 basegfx::B3DVector origin;
505 double angle;
508 #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_