1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "BaseGFXHelper.hxx"
22 #include <com/sun/star/drawing/DoubleSequence.hpp>
24 using namespace ::com::sun::star
;
25 using namespace ::com::sun::star::drawing
;
26 using namespace ::basegfx
;
30 namespace BaseGFXHelper
33 ::basegfx::B3DRange
getBoundVolume( const drawing::PolyPolygonShape3D
& rPolyPoly
)
35 ::basegfx::B3DRange aRet
;
38 sal_Int32 nPolyCount
= rPolyPoly
.SequenceX
.getLength();
39 for(sal_Int32 nPoly
= 0; nPoly
< nPolyCount
; nPoly
++)
41 sal_Int32 nPointCount
= rPolyPoly
.SequenceX
[nPoly
].getLength();
42 for( sal_Int32 nPoint
= 0; nPoint
< nPointCount
; nPoint
++)
46 aRet
= ::basegfx::B3DRange(::basegfx::B3DTuple(
47 rPolyPoly
.SequenceX
[nPoly
][nPoint
]
48 , rPolyPoly
.SequenceY
[nPoly
][nPoint
]
49 , rPolyPoly
.SequenceZ
[nPoly
][nPoint
]));
54 aRet
.expand( ::basegfx::B3DTuple(
55 rPolyPoly
.SequenceX
[nPoly
][nPoint
]
56 , rPolyPoly
.SequenceY
[nPoly
][nPoint
]
57 , rPolyPoly
.SequenceZ
[nPoly
][nPoint
]));
65 B2IRectangle
makeRectangle( const awt::Point
& rPos
, const awt::Size
& rSize
)
67 return B2IRectangle(rPos
.X
,rPos
.Y
,rPos
.X
+rSize
.Width
,rPos
.Y
+rSize
.Height
);
70 awt::Point
B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle
& rB2IRectangle
)
72 return awt::Point( rB2IRectangle
.getMinX(), rB2IRectangle
.getMinY() );
75 awt::Size
B2IRectangleToAWTSize( const ::basegfx::B2IRectangle
& rB2IRectangle
)
77 return awt::Size( static_cast< sal_Int32
>( rB2IRectangle
.getWidth()),
78 static_cast< sal_Int32
>( rB2IRectangle
.getHeight()));
81 awt::Rectangle
B2IRectangleToAWTRectangle(
82 const ::basegfx::B2IRectangle
& rB2IRectangle
)
84 return awt::Rectangle( rB2IRectangle
.getMinX(), rB2IRectangle
.getMinY(),
85 static_cast< sal_Int32
>( rB2IRectangle
.getWidth()),
86 static_cast< sal_Int32
>( rB2IRectangle
.getHeight()));
89 B3DVector
Direction3DToB3DVector( const Direction3D
& rDirection
)
93 , rDirection
.DirectionY
94 , rDirection
.DirectionZ
98 Direction3D
B3DVectorToDirection3D( const B3DVector
& rB3DVector
)
107 B3DVector
Position3DToB3DVector( const Position3D
& rPosition
)
111 , rPosition
.PositionY
112 , rPosition
.PositionZ
116 Position3D
B3DVectorToPosition3D( const B3DVector
& rB3DVector
)
125 B3DHomMatrix
HomogenMatrixToB3DHomMatrix( const HomogenMatrix
& rHomogenMatrix
)
127 B3DHomMatrix aResult
;
129 aResult
.set( 0, 0, rHomogenMatrix
.Line1
.Column1
);
130 aResult
.set( 0, 1, rHomogenMatrix
.Line1
.Column2
);
131 aResult
.set( 0, 2, rHomogenMatrix
.Line1
.Column3
);
132 aResult
.set( 0, 3, rHomogenMatrix
.Line1
.Column4
);
134 aResult
.set( 1, 0, rHomogenMatrix
.Line2
.Column1
);
135 aResult
.set( 1, 1, rHomogenMatrix
.Line2
.Column2
);
136 aResult
.set( 1, 2, rHomogenMatrix
.Line2
.Column3
);
137 aResult
.set( 1, 3, rHomogenMatrix
.Line2
.Column4
);
139 aResult
.set( 2, 0, rHomogenMatrix
.Line3
.Column1
);
140 aResult
.set( 2, 1, rHomogenMatrix
.Line3
.Column2
);
141 aResult
.set( 2, 2, rHomogenMatrix
.Line3
.Column3
);
142 aResult
.set( 2, 3, rHomogenMatrix
.Line3
.Column4
);
144 aResult
.set( 3, 0, rHomogenMatrix
.Line4
.Column1
);
145 aResult
.set( 3, 1, rHomogenMatrix
.Line4
.Column2
);
146 aResult
.set( 3, 2, rHomogenMatrix
.Line4
.Column3
);
147 aResult
.set( 3, 3, rHomogenMatrix
.Line4
.Column4
);
152 HomogenMatrix
B3DHomMatrixToHomogenMatrix( const B3DHomMatrix
& rB3DMatrix
)
154 HomogenMatrix aResult
;
156 aResult
.Line1
.Column1
= rB3DMatrix
.get( 0, 0 );
157 aResult
.Line1
.Column2
= rB3DMatrix
.get( 0, 1 );
158 aResult
.Line1
.Column3
= rB3DMatrix
.get( 0, 2 );
159 aResult
.Line1
.Column4
= rB3DMatrix
.get( 0, 3 );
161 aResult
.Line2
.Column1
= rB3DMatrix
.get( 1, 0 );
162 aResult
.Line2
.Column2
= rB3DMatrix
.get( 1, 1 );
163 aResult
.Line2
.Column3
= rB3DMatrix
.get( 1, 2 );
164 aResult
.Line2
.Column4
= rB3DMatrix
.get( 1, 3 );
166 aResult
.Line3
.Column1
= rB3DMatrix
.get( 2, 0 );
167 aResult
.Line3
.Column2
= rB3DMatrix
.get( 2, 1 );
168 aResult
.Line3
.Column3
= rB3DMatrix
.get( 2, 2 );
169 aResult
.Line3
.Column4
= rB3DMatrix
.get( 2, 3 );
171 aResult
.Line4
.Column1
= rB3DMatrix
.get( 3, 0 );
172 aResult
.Line4
.Column2
= rB3DMatrix
.get( 3, 1 );
173 aResult
.Line4
.Column3
= rB3DMatrix
.get( 3, 2 );
174 aResult
.Line4
.Column4
= rB3DMatrix
.get( 3, 3 );
179 B3DTuple
GetRotationFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
181 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
182 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
186 B3DTuple
GetScaleFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
188 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
189 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
193 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix
& rB3DMatrix
)
195 B3DTuple
aR( GetRotationFromMatrix( rB3DMatrix
) );
196 ::basegfx::B3DHomMatrix aRotationMatrix
;
197 aRotationMatrix
.rotate(aR
.getX(),aR
.getY(),aR
.getZ());
198 rB3DMatrix
= aRotationMatrix
;
201 double Deg2Rad( double fDegrees
)
203 return fDegrees
* ( F_PI
/ 180.0 );
206 double Rad2Deg( double fRadians
)
208 return fRadians
* ( 180.0 / F_PI
);
211 } // namespace BaseGFXHelper
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */