1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
29 #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
31 #include <config_lgpl.h>
32 #include <glm/glm.hpp>
34 #include <boost/noncopyable.hpp>
35 #include <boost/shared_ptr.hpp>
39 #include <basegfx/vector/b2dvector.hxx>
40 #include <basegfx/vector/b3dvector.hxx>
49 struct TransitionSettings
51 TransitionSettings() :
52 mbUseMipMapLeaving( true ),
53 mbUseMipMapEntering( true ),
54 mnRequiredGLVersion( 1.0 ),
55 mbReflectSlides( false )
59 /** Whether to use mipmaping for slides textures
61 bool mbUseMipMapLeaving
;
62 bool mbUseMipMapEntering
;
64 /** which GL version does the transition require
66 float mnRequiredGLVersion
;
68 /** Whether to reflect slides, the reflection happens on flat surface beneath the slides.
69 ** Now it only works with slides which keep their rectangular shape together.
74 typedef std::vector
<Primitive
> Primitives_t
;
75 typedef std::vector
<boost::shared_ptr
<SceneObject
> > SceneObjects_t
;
76 typedef std::vector
<boost::shared_ptr
<Operation
> > Operations_t
;
86 const Primitives_t
& rLeavingSlidePrimitives
,
87 const Primitives_t
& rEnteringSlidePrimitives
,
88 const Operations_t
& rOverallOperations
= Operations_t(),
89 const SceneObjects_t
& rSceneObjects
= SceneObjects_t()
91 : maLeavingSlidePrimitives(rLeavingSlidePrimitives
)
92 , maEnteringSlidePrimitives(rEnteringSlidePrimitives
)
93 , maOverallOperations(rOverallOperations
)
94 , maSceneObjects(rSceneObjects
)
98 TransitionScene(TransitionScene
const& rOther
);
99 TransitionScene
& operator=(const TransitionScene
& rOther
);
101 void swap(TransitionScene
& rOther
);
103 const Primitives_t
& getLeavingSlide() const
105 return maLeavingSlidePrimitives
;
108 const Primitives_t
& getEnteringSlide() const
110 return maEnteringSlidePrimitives
;
113 const Operations_t
& getOperations() const
115 return maOverallOperations
;
118 const SceneObjects_t
& getSceneObjects() const
120 return maSceneObjects
;
124 /** All the primitives that use the leaving slide texture
126 Primitives_t maLeavingSlidePrimitives
;
128 /** All the primitives that use the leaving slide texture
130 Primitives_t maEnteringSlidePrimitives
;
132 /** 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.
134 Operations_t maOverallOperations
;
136 /** All the surrounding scene objects
138 SceneObjects_t maSceneObjects
;
141 /** OpenGL 3D Transition class. It implicitly is constructed from XOGLTransition
143 It holds Primitives and Operations on those primitives.
145 class OGLTransitionImpl
: private boost::noncopyable
148 virtual ~OGLTransitionImpl();
150 /** Prepare transition.
152 void prepare( ::sal_Int32 glLeavingSlideTex
, ::sal_Int32 glEnteringSlideTex
);
153 /** Display a step of the transition.
155 void display( double nTime
, ::sal_Int32 glLeavingSlideTex
, ::sal_Int32 glEnteringSlideTex
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
);
156 /** Clean up after transition.
160 TransitionSettings
const& getSettings() const
166 OGLTransitionImpl(const TransitionScene
& rScene
, const TransitionSettings
& rSettings
)
168 , maSettings(rSettings
)
171 OGLTransitionImpl() {}
173 TransitionScene
const& getScene() const
178 void setScene(TransitionScene
const& rScene
);
179 // void setSettings(TransitionSettings const& rSettings);
181 void displaySlide( double nTime
, ::sal_Int32 glSlideTex
, const Primitives_t
& primitives
, double SlideWidthScale
, double SlideHeightScale
);
182 void displayScene( double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
);
183 void applyOverallOperations( double nTime
, double SlideWidthScale
, double SlideHeightScale
);
186 /** This function is called in display method to prepare the slides, scene, etc.
188 * Default implementation does nothing.
190 virtual void prepare( double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
);
192 /** This function is called after glx context is ready to let the transition prepare GL related things, like GLSL program.
194 * Default implementation does nothing.
196 virtual void prepareTransition( ::sal_Int32 glLeavingSlideTex
, ::sal_Int32 glEnteringSlideTex
);
198 /** This function is called when the transition needs to clear after itself, like delete own textures etc.
200 * Default implementation does nothing.
202 virtual void finishTransition();
204 /** This function is called in display method to display the slides.
206 * Default implementation applies overall operations and then
207 * displays both slides.
209 virtual void displaySlides_( double nTime
, ::sal_Int32 glLeavingSlideTex
, ::sal_Int32 glEnteringSlideTex
, double SlideWidthScale
, double SlideHeightScale
);
212 TransitionScene maScene
;
213 const TransitionSettings maSettings
;
217 // "Constructors" of available transitions
218 boost::shared_ptr
<OGLTransitionImpl
> makeOutsideCubeFaceToLeft();
219 boost::shared_ptr
<OGLTransitionImpl
> makeInsideCubeFaceToLeft();
220 boost::shared_ptr
<OGLTransitionImpl
> makeNByMTileFlip( ::sal_uInt16 n
, ::sal_uInt16 m
);
221 boost::shared_ptr
<OGLTransitionImpl
> makeRevolvingCircles( ::sal_uInt16 nCircles
, ::sal_uInt16 nPointsOnCircles
);
222 boost::shared_ptr
<OGLTransitionImpl
> makeHelix( ::sal_uInt16 nRows
);
223 boost::shared_ptr
<OGLTransitionImpl
> makeFallLeaving();
224 boost::shared_ptr
<OGLTransitionImpl
> makeTurnAround();
225 boost::shared_ptr
<OGLTransitionImpl
> makeTurnDown();
226 boost::shared_ptr
<OGLTransitionImpl
> makeIris();
227 boost::shared_ptr
<OGLTransitionImpl
> makeRochade();
228 boost::shared_ptr
<OGLTransitionImpl
> makeVenetianBlinds( bool vertical
, int parts
);
229 boost::shared_ptr
<OGLTransitionImpl
> makeStatic();
230 boost::shared_ptr
<OGLTransitionImpl
> makeDissolve();
231 boost::shared_ptr
<OGLTransitionImpl
> makeNewsflash();
235 boost::shared_ptr
<OGLTransitionImpl
> makeDiamond();
236 boost::shared_ptr
<OGLTransitionImpl
> makeFadeSmoothly();
237 boost::shared_ptr
<OGLTransitionImpl
> makeFadeThroughBlack();
239 class SceneObject
: private boost::noncopyable
243 virtual ~SceneObject();
245 virtual void prepare() {}
246 virtual void display(double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
) const;
247 virtual void finish() {}
249 void pushPrimitive (const Primitive
&p
);
252 /** All the surrounding scene primitives
254 Primitives_t maPrimitives
;
257 class Iris
: public SceneObject
262 virtual void prepare() SAL_OVERRIDE
;
263 virtual void display(double nTime
, double SlideWidth
, double SlideHeight
, double DispWidth
, double DispHeight
) const SAL_OVERRIDE
;
264 virtual void finish() SAL_OVERRIDE
;
270 /** This class is a list of Triangles that will share Operations, and could possibly share
276 // making copy constructor explicit makes the class un-suitable for use with stl containers
277 Primitive(const Primitive
& rvalue
);
278 Primitive
& operator=(const Primitive
& rvalue
);
280 void swap(Primitive
& rOther
);
282 void applyOperations(double nTime
, double SlideWidthScale
, double SlideHeightScale
) const;
283 void display(double nTime
, double SlideWidthScale
, double SlideHeightScale
) const;
285 /** 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.
287 @param SlideLocation0
288 Location of first Vertex on slide
290 @param SlideLocation1
291 Location of second Vertex on slide
293 @param SlideLocation2
294 Location of third Vertex on slide
297 void pushTriangle(const glm::vec2
& SlideLocation0
,const glm::vec2
& SlideLocation1
,const glm::vec2
& SlideLocation2
);
299 /** clear all the vertices, normals, tex coordinates, and normals
301 void clearTriangles();
303 /** guards against directly changing the vertices
308 const std::vector
<glm::vec3
>& getVertices() const {return Vertices
;}
310 /** guards against directly changing the vertices
312 const std::vector
<glm::vec3
>& getNormals() const {return Normals
;}
314 /** guards against directly changing the vertices
317 the list of Texture Coordinates
320 const std::vector
<glm::vec2
>& getTexCoords() const {return TexCoords
;}
322 /** 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.
325 the list of Operations
328 Operations_t Operations
;
333 std::vector
<glm::vec3
> Vertices
;
337 std::vector
<glm::vec3
> Normals
;
339 /** list of Texture Coordinates
341 std::vector
<glm::vec2
> TexCoords
;
344 /** This class is to be derived to make any operation (transform) you may need in order to construct your transitions
346 class Operation
: private boost::noncopyable
349 virtual ~Operation(){}
352 /** Should this operation be interpolated . If TRUE, the transform will smoothly move from making no difference from t = 0.0 to mnT0 to being completely transformed from t = mnT1 to 1. If FALSE, the transform will be inneffectual from t = 0 to mnT0, and completely transformed from t = mnT0 to 1.
356 /** time to begin the transformation
360 /** time to finish the transformation
364 /** this is the function that is called to give the Operation to OpenGL.
367 time from t = 0 to t = 1
369 @param SlideWidthScale
370 width of slide divided by width of window
372 @param SlideHeightScale
373 height of slide divided by height of window
376 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const = 0;
379 Operation(bool bInterpolate
, double nT0
, double nT1
):
380 mbInterpolate(bInterpolate
), mnT0(nT0
), mnT1(nT1
){}
383 /** this class is a generic CounterClockWise(CCW) rotation with an axis angle
385 class SRotate
: public Operation
388 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
396 position that rotation axis runs through
399 angle in radians of CCW rotation
405 transformation starting time
408 transformation ending time
411 SRotate(const glm::vec3
& Axis
, const glm::vec3
& Origin
, double Angle
,
412 bool bInter
, double T0
, double T1
);
415 /** axis to rotate CCW about
419 /** position that rotation axis runs through
423 /** angle in radians of CCW rotation
428 boost::shared_ptr
<SRotate
>
429 makeSRotate(const glm::vec3
& Axis
, const glm::vec3
& Origin
, double Angle
,
430 bool bInter
, double T0
, double T1
);
432 /** scaling transformation
434 class SScale
: public Operation
437 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
445 position that rotation axis runs through
451 transformation starting time
454 transformation ending time
457 SScale(const glm::vec3
& Scale
, const glm::vec3
& Origin
,bool bInter
, double T0
, double T1
);
464 boost::shared_ptr
<SScale
>
465 makeSScale(const glm::vec3
& Scale
, const glm::vec3
& Origin
,bool bInter
, double T0
, double T1
);
467 /** translation transformation
469 class STranslate
: public Operation
472 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
483 transformation starting time
486 transformation ending time
489 STranslate(const glm::vec3
& Vector
,bool bInter
, double T0
, double T1
);
490 virtual ~STranslate(){}
492 /** vector to translate by
497 boost::shared_ptr
<STranslate
>
498 makeSTranslate(const glm::vec3
& Vector
,bool bInter
, double T0
, double T1
);
500 /** translation transformation
502 class SEllipseTranslate
: public Operation
505 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
516 transformation starting time
519 transformation ending time
522 SEllipseTranslate(double dWidth
, double dHeight
, double dStartPosition
, double dEndPosition
, bool bInter
, double T0
, double T1
);
523 virtual ~SEllipseTranslate(){}
525 /** width and length of the ellipse
527 double width
, height
;
529 /** start and end position on the ellipse <0,1>
531 double startPosition
;
535 boost::shared_ptr
<SEllipseTranslate
>
536 makeSEllipseTranslate(double dWidth
, double dHeight
, double dStartPosition
, double dEndPosition
, bool bInter
, double T0
, double T1
);
538 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window.
540 class RotateAndScaleDepthByWidth
: public Operation
543 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
545 RotateAndScaleDepthByWidth(const glm::vec3
& Axis
,const glm::vec3
& Origin
,double Angle
,bool bInter
, double T0
, double T1
);
546 virtual ~RotateAndScaleDepthByWidth(){}
553 boost::shared_ptr
<RotateAndScaleDepthByWidth
>
554 makeRotateAndScaleDepthByWidth(const glm::vec3
& Axis
,const glm::vec3
& Origin
,double Angle
,bool bInter
, double T0
, double T1
);
556 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window.
558 class RotateAndScaleDepthByHeight
: public Operation
561 virtual void interpolate(double t
,double SlideWidthScale
,double SlideHeightScale
) const SAL_OVERRIDE
;
563 RotateAndScaleDepthByHeight(const glm::vec3
& Axis
,const glm::vec3
& Origin
,double Angle
,bool bInter
, double T0
, double T1
);
564 virtual ~RotateAndScaleDepthByHeight(){}
571 boost::shared_ptr
<RotateAndScaleDepthByHeight
>
572 makeRotateAndScaleDepthByHeight(const glm::vec3
& Axis
,const glm::vec3
& Origin
,double Angle
,bool bInter
, double T0
, double T1
);
574 #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
576 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */