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 .
20 #include <BaseGFXHelper.hxx>
21 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
22 #include <com/sun/star/awt/Rectangle.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 B2IRectangle
makeRectangle( const awt::Rectangle
& rRect
)
72 return B2IRectangle(rRect
.X
, rRect
.Y
, rRect
.X
+rRect
.Width
, rRect
.Y
+rRect
.Height
);
75 awt::Point
B2IRectangleToAWTPoint( const ::basegfx::B2IRectangle
& rB2IRectangle
)
77 return awt::Point( rB2IRectangle
.getMinX(), rB2IRectangle
.getMinY() );
80 awt::Size
B2IRectangleToAWTSize( const ::basegfx::B2IRectangle
& rB2IRectangle
)
82 return awt::Size( static_cast< sal_Int32
>( rB2IRectangle
.getWidth()),
83 static_cast< sal_Int32
>( rB2IRectangle
.getHeight()));
86 B3DVector
Direction3DToB3DVector( const Direction3D
& rDirection
)
90 , rDirection
.DirectionY
91 , rDirection
.DirectionZ
95 Direction3D
B3DVectorToDirection3D( const B3DVector
& rB3DVector
)
104 B3DVector
Position3DToB3DVector( const Position3D
& rPosition
)
108 , rPosition
.PositionY
109 , rPosition
.PositionZ
113 Position3D
B3DVectorToPosition3D( const B3DVector
& rB3DVector
)
122 B3DHomMatrix
HomogenMatrixToB3DHomMatrix( const HomogenMatrix
& rHomogenMatrix
)
124 B3DHomMatrix aResult
;
126 aResult
.set( 0, 0, rHomogenMatrix
.Line1
.Column1
);
127 aResult
.set( 0, 1, rHomogenMatrix
.Line1
.Column2
);
128 aResult
.set( 0, 2, rHomogenMatrix
.Line1
.Column3
);
129 aResult
.set( 0, 3, rHomogenMatrix
.Line1
.Column4
);
131 aResult
.set( 1, 0, rHomogenMatrix
.Line2
.Column1
);
132 aResult
.set( 1, 1, rHomogenMatrix
.Line2
.Column2
);
133 aResult
.set( 1, 2, rHomogenMatrix
.Line2
.Column3
);
134 aResult
.set( 1, 3, rHomogenMatrix
.Line2
.Column4
);
136 aResult
.set( 2, 0, rHomogenMatrix
.Line3
.Column1
);
137 aResult
.set( 2, 1, rHomogenMatrix
.Line3
.Column2
);
138 aResult
.set( 2, 2, rHomogenMatrix
.Line3
.Column3
);
139 aResult
.set( 2, 3, rHomogenMatrix
.Line3
.Column4
);
141 aResult
.set( 3, 0, rHomogenMatrix
.Line4
.Column1
);
142 aResult
.set( 3, 1, rHomogenMatrix
.Line4
.Column2
);
143 aResult
.set( 3, 2, rHomogenMatrix
.Line4
.Column3
);
144 aResult
.set( 3, 3, rHomogenMatrix
.Line4
.Column4
);
149 HomogenMatrix
B3DHomMatrixToHomogenMatrix( const B3DHomMatrix
& rB3DMatrix
)
151 HomogenMatrix aResult
;
153 aResult
.Line1
.Column1
= rB3DMatrix
.get( 0, 0 );
154 aResult
.Line1
.Column2
= rB3DMatrix
.get( 0, 1 );
155 aResult
.Line1
.Column3
= rB3DMatrix
.get( 0, 2 );
156 aResult
.Line1
.Column4
= rB3DMatrix
.get( 0, 3 );
158 aResult
.Line2
.Column1
= rB3DMatrix
.get( 1, 0 );
159 aResult
.Line2
.Column2
= rB3DMatrix
.get( 1, 1 );
160 aResult
.Line2
.Column3
= rB3DMatrix
.get( 1, 2 );
161 aResult
.Line2
.Column4
= rB3DMatrix
.get( 1, 3 );
163 aResult
.Line3
.Column1
= rB3DMatrix
.get( 2, 0 );
164 aResult
.Line3
.Column2
= rB3DMatrix
.get( 2, 1 );
165 aResult
.Line3
.Column3
= rB3DMatrix
.get( 2, 2 );
166 aResult
.Line3
.Column4
= rB3DMatrix
.get( 2, 3 );
168 aResult
.Line4
.Column1
= rB3DMatrix
.get( 3, 0 );
169 aResult
.Line4
.Column2
= rB3DMatrix
.get( 3, 1 );
170 aResult
.Line4
.Column3
= rB3DMatrix
.get( 3, 2 );
171 aResult
.Line4
.Column4
= rB3DMatrix
.get( 3, 3 );
176 B3DTuple
GetRotationFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
178 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
179 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
183 B3DTuple
GetScaleFromMatrix( const B3DHomMatrix
& rB3DMatrix
)
185 B3DTuple aScale
, aTranslation
, aRotation
, aShearing
;
186 rB3DMatrix
.decompose( aScale
, aTranslation
, aRotation
, aShearing
);
190 void ReduceToRotationMatrix( ::basegfx::B3DHomMatrix
& rB3DMatrix
)
192 B3DTuple
aR( GetRotationFromMatrix( rB3DMatrix
) );
193 ::basegfx::B3DHomMatrix aRotationMatrix
;
194 aRotationMatrix
.rotate(aR
.getX(),aR
.getY(),aR
.getZ());
195 rB3DMatrix
= aRotationMatrix
;
198 } // namespace BaseGFXHelper
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */