1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BaseGFXHelper.cxx,v $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "BaseGFXHelper.hxx"
35 #include <com/sun/star/drawing/DoubleSequence.hpp>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::drawing
;
39 using namespace ::basegfx
;
43 namespace BaseGFXHelper
46 ::basegfx::B3DRange
getBoundVolume( const drawing::PolyPolygonShape3D
& rPolyPoly
)
48 ::basegfx::B3DRange aRet
;
51 sal_Int32 nPolyCount
= rPolyPoly
.SequenceX
.getLength();
52 for(sal_Int32 nPoly
= 0; nPoly
< nPolyCount
; nPoly
++)
54 sal_Int32 nPointCount
= rPolyPoly
.SequenceX
[nPoly
].getLength();
55 for( sal_Int32 nPoint
= 0; nPoint
< nPointCount
; nPoint
++)
59 aRet
= ::basegfx::B3DRange(::basegfx::B3DTuple(
60 rPolyPoly
.SequenceX
[nPoly
][nPoint
]
61 , rPolyPoly
.SequenceY
[nPoly
][nPoint
]
62 , rPolyPoly
.SequenceZ
[nPoly
][nPoint
]));
67 aRet
.expand( ::basegfx::B3DTuple(
68 rPolyPoly
.SequenceX
[nPoly
][nPoint
]
69 , rPolyPoly
.SequenceY
[nPoly
][nPoint
]
70 , rPolyPoly
.SequenceZ
[nPoly
][nPoint
]));
78 B2IRectangle
makeRectangle( const awt::Point
& rPos
, const awt::Size
& rSize
)
80 return B2IRectangle(rPos
.X
,rPos
.Y
,rPos
.X
+rSize
.Width
,rPos
.Y
+rSize
.Height
);
83 awt::Point
B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle
& rB2IRectangle
)
85 return awt::Point( rB2IRectangle
.getMinX(), rB2IRectangle
.getMinY() );
88 awt::Size
B2IRectangleToAWTSize( const ::basegfx::B2IRectangle
& rB2IRectangle
)
90 return awt::Size( static_cast< sal_Int32
>( rB2IRectangle
.getWidth()),
91 static_cast< sal_Int32
>( rB2IRectangle
.getHeight()));
94 awt::Rectangle
B2IRectangleToAWTRectangle(
95 const ::basegfx::B2IRectangle
& rB2IRectangle
)
97 return awt::Rectangle( rB2IRectangle
.getMinX(), rB2IRectangle
.getMinY(),
98 static_cast< sal_Int32
>( rB2IRectangle
.getWidth()),
99 static_cast< sal_Int32
>( rB2IRectangle
.getHeight()));
102 B3DVector
Direction3DToB3DVector( const Direction3D
& rDirection
)
105 rDirection
.DirectionX
106 , rDirection
.DirectionY
107 , rDirection
.DirectionZ
111 Direction3D
B3DVectorToDirection3D( const B3DVector
& rB3DVector
)
120 B3DVector
Position3DToB3DVector( const Position3D
& rPosition
)
124 , rPosition
.PositionY
125 , rPosition
.PositionZ
129 Position3D
B3DVectorToPosition3D( const B3DVector
& rB3DVector
)
138 B3DHomMatrix
HomogenMatrixToB3DHomMatrix( const HomogenMatrix
& rHomogenMatrix
)
140 B3DHomMatrix aResult
;
142 aResult
.set( 0, 0, rHomogenMatrix
.Line1
.Column1
);
143 aResult
.set( 0, 1, rHomogenMatrix
.Line1
.Column2
);
144 aResult
.set( 0, 2, rHomogenMatrix
.Line1
.Column3
);
145 aResult
.set( 0, 3, rHomogenMatrix
.Line1
.Column4
);
147 aResult
.set( 1, 0, rHomogenMatrix
.Line2
.Column1
);
148 aResult
.set( 1, 1, rHomogenMatrix
.Line2
.Column2
);
149 aResult
.set( 1, 2, rHomogenMatrix
.Line2
.Column3
);
150 aResult
.set( 1, 3, rHomogenMatrix
.Line2
.Column4
);
152 aResult
.set( 2, 0, rHomogenMatrix
.Line3
.Column1
);
153 aResult
.set( 2, 1, rHomogenMatrix
.Line3
.Column2
);
154 aResult
.set( 2, 2, rHomogenMatrix
.Line3
.Column3
);
155 aResult
.set( 2, 3, rHomogenMatrix
.Line3
.Column4
);
157 aResult
.set( 3, 0, rHomogenMatrix
.Line4
.Column1
);
158 aResult
.set( 3, 1, rHomogenMatrix
.Line4
.Column2
);
159 aResult
.set( 3, 2, rHomogenMatrix
.Line4
.Column3
);
160 aResult
.set( 3, 3, rHomogenMatrix
.Line4
.Column4
);
165 HomogenMatrix
B3DHomMatrixToHomogenMatrix( const B3DHomMatrix
& rB3DMatrix
)
167 HomogenMatrix aResult
;
169 aResult
.Line1
.Column1
= rB3DMatrix
.get( 0, 0 );
170 aResult
.Line1
.Column2
= rB3DMatrix
.get( 0, 1 );
171 aResult
.Line1
.Column3
= rB3DMatrix
.get( 0, 2 );
172 aResult
.Line1
.Column4
= rB3DMatrix
.get( 0, 3 );
174 aResult
.Line2
.Column1
= rB3DMatrix
.get( 1, 0 );
175 aResult
.Line2
.Column2
= rB3DMatrix
.get( 1, 1 );
176 aResult
.Line2
.Column3
= rB3DMatrix
.get( 1, 2 );
177 aResult
.Line2
.Column4
= rB3DMatrix
.get( 1, 3 );
179 aResult
.Line3
.Column1
= rB3DMatrix
.get( 2, 0 );
180 aResult
.Line3
.Column2
= rB3DMatrix
.get( 2, 1 );
181 aResult
.Line3
.Column3
= rB3DMatrix
.get( 2, 2 );
182 aResult
.Line3
.Column4
= rB3DMatrix
.get( 2, 3 );
184 aResult
.Line4
.Column1
= rB3DMatrix
.get( 3, 0 );
185 aResult
.Line4
.Column2
= rB3DMatrix
.get( 3, 1 );
186 aResult
.Line4
.Column3
= rB3DMatrix
.get( 3, 2 );
187 aResult
.Line4
.Column4
= rB3DMatrix
.get( 3, 3 );
192 B3DTuple
GetRotationFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
194 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
195 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
199 B3DTuple
GetScaleFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
201 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
202 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
206 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix
& rB3DMatrix
)
208 B3DTuple
aR( GetRotationFromMatrix( rB3DMatrix
) );
209 ::basegfx::B3DHomMatrix aRotationMatrix
;
210 aRotationMatrix
.rotate(aR
.getX(),aR
.getY(),aR
.getZ());
211 rB3DMatrix
= aRotationMatrix
;
214 double Deg2Rad( double fDegrees
)
216 return fDegrees
* ( F_PI
/ 180.0 );
219 double Rad2Deg( double fRadians
)
221 return fRadians
* ( 180.0 / F_PI
);
224 } // namespace BaseGFXHelper