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 "CommonConverters.hxx"
22 #include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
23 #include <com/sun/star/drawing/DoubleSequence.hpp>
24 #include <basegfx/polygon/b3dpolygon.hxx>
25 #include <basegfx/polygon/b3dpolygontools.hxx>
27 using namespace ::com::sun::star
;
32 Stripe::Stripe( const drawing::Position3D
& rPoint1
33 , const drawing::Direction3D
& rDirectionToPoint2
34 , const drawing::Direction3D
& rDirectionToPoint4
)
36 , m_aPoint2(rPoint1
+rDirectionToPoint2
)
37 , m_aPoint3(m_aPoint2
+rDirectionToPoint4
)
38 , m_aPoint4(rPoint1
+rDirectionToPoint4
)
39 , m_bInvertNormal(false)
40 , m_bManualNormalSet(false)
44 Stripe::Stripe( const drawing::Position3D
& rPoint1
45 , const drawing::Position3D
& rPoint2
51 , m_bInvertNormal(false)
52 , m_bManualNormalSet(false)
54 m_aPoint3
.PositionZ
+= fDepth
;
55 m_aPoint4
.PositionZ
+= fDepth
;
58 Stripe::Stripe( const drawing::Position3D
& rPoint1
59 , const drawing::Position3D
& rPoint2
60 , const drawing::Position3D
& rPoint3
61 , const drawing::Position3D
& rPoint4
)
66 , m_bInvertNormal(false)
67 , m_bManualNormalSet(false)
71 void Stripe::SetManualNormal( const drawing::Direction3D
& rNormal
)
73 m_aManualNormal
= rNormal
;
74 m_bManualNormalSet
= true;
77 void Stripe::InvertNormal( bool bInvertNormal
)
79 m_bInvertNormal
= bInvertNormal
;
82 uno::Any
Stripe::getPolyPolygonShape3D() const
84 drawing::PolyPolygonShape3D aPP
;
86 aPP
.SequenceX
.realloc(1);
87 aPP
.SequenceY
.realloc(1);
88 aPP
.SequenceZ
.realloc(1);
90 drawing::DoubleSequence
* pOuterSequenceX
= aPP
.SequenceX
.getArray();
91 drawing::DoubleSequence
* pOuterSequenceY
= aPP
.SequenceY
.getArray();
92 drawing::DoubleSequence
* pOuterSequenceZ
= aPP
.SequenceZ
.getArray();
94 pOuterSequenceX
->realloc(4);
95 pOuterSequenceY
->realloc(4);
96 pOuterSequenceZ
->realloc(4);
98 double* pInnerSequenceX
= pOuterSequenceX
->getArray();
99 double* pInnerSequenceY
= pOuterSequenceY
->getArray();
100 double* pInnerSequenceZ
= pOuterSequenceZ
->getArray();
102 *pInnerSequenceX
++ = m_aPoint1
.PositionX
;
103 *pInnerSequenceY
++ = m_aPoint1
.PositionY
;
104 *pInnerSequenceZ
++ = m_aPoint1
.PositionZ
;
106 *pInnerSequenceX
++ = m_aPoint2
.PositionX
;
107 *pInnerSequenceY
++ = m_aPoint2
.PositionY
;
108 *pInnerSequenceZ
++ = m_aPoint2
.PositionZ
;
110 *pInnerSequenceX
++ = m_aPoint3
.PositionX
;
111 *pInnerSequenceY
++ = m_aPoint3
.PositionY
;
112 *pInnerSequenceZ
++ = m_aPoint3
.PositionZ
;
114 *pInnerSequenceX
++ = m_aPoint4
.PositionX
;
115 *pInnerSequenceY
++ = m_aPoint4
.PositionY
;
116 *pInnerSequenceZ
++ = m_aPoint4
.PositionZ
;
118 return uno::Any( &aPP
, cppu::UnoType
<drawing::PolyPolygonShape3D
>::get());
121 drawing::Direction3D
Stripe::getNormal() const
123 drawing::Direction3D
aRet(1.0,0.0,0.0);
125 if( m_bManualNormalSet
)
126 aRet
= m_aManualNormal
;
129 ::basegfx::B3DPolygon aPolygon3D
;
130 aPolygon3D
.append(Position3DToB3DPoint( m_aPoint1
));
131 aPolygon3D
.append(Position3DToB3DPoint( m_aPoint2
));
132 aPolygon3D
.append(Position3DToB3DPoint( m_aPoint3
));
133 aPolygon3D
.append(Position3DToB3DPoint( m_aPoint4
));
134 ::basegfx::B3DVector
aNormal(::basegfx::tools::getNormal(aPolygon3D
));
135 aRet
= B3DVectorToDirection3D(aNormal
);
138 if( m_bInvertNormal
)
140 aRet
.DirectionX
*= -1.0;
141 aRet
.DirectionY
*= -1.0;
142 aRet
.DirectionZ
*= -1.0;
147 uno::Any
Stripe::getNormalsPolygon() const
149 drawing::PolyPolygonShape3D aPP
;
151 aPP
.SequenceX
.realloc(1);
152 aPP
.SequenceY
.realloc(1);
153 aPP
.SequenceZ
.realloc(1);
155 drawing::DoubleSequence
* pOuterSequenceX
= aPP
.SequenceX
.getArray();
156 drawing::DoubleSequence
* pOuterSequenceY
= aPP
.SequenceY
.getArray();
157 drawing::DoubleSequence
* pOuterSequenceZ
= aPP
.SequenceZ
.getArray();
159 pOuterSequenceX
->realloc(4);
160 pOuterSequenceY
->realloc(4);
161 pOuterSequenceZ
->realloc(4);
163 double* pInnerSequenceX
= pOuterSequenceX
->getArray();
164 double* pInnerSequenceY
= pOuterSequenceY
->getArray();
165 double* pInnerSequenceZ
= pOuterSequenceZ
->getArray();
167 drawing::Direction3D
aNormal( getNormal() );
169 for(sal_Int32 nN
=4; --nN
; )
171 *pInnerSequenceX
++ = aNormal
.DirectionX
;
172 *pInnerSequenceY
++ = aNormal
.DirectionY
;
173 *pInnerSequenceZ
++ = aNormal
.DirectionZ
;
175 return uno::Any( &aPP
, cppu::UnoType
<drawing::PolyPolygonShape3D
>::get());
178 uno::Any
Stripe::getTexturePolygon( short nRotatedTexture
)
180 drawing::PolyPolygonShape3D aPP
;
182 aPP
.SequenceX
.realloc(1);
183 aPP
.SequenceY
.realloc(1);
184 aPP
.SequenceZ
.realloc(1);
186 drawing::DoubleSequence
* pOuterSequenceX
= aPP
.SequenceX
.getArray();
187 drawing::DoubleSequence
* pOuterSequenceY
= aPP
.SequenceY
.getArray();
188 drawing::DoubleSequence
* pOuterSequenceZ
= aPP
.SequenceZ
.getArray();
190 pOuterSequenceX
->realloc(4);
191 pOuterSequenceY
->realloc(4);
192 pOuterSequenceZ
->realloc(4);
194 double* pInnerSequenceX
= pOuterSequenceX
->getArray();
195 double* pInnerSequenceY
= pOuterSequenceY
->getArray();
196 double* pInnerSequenceZ
= pOuterSequenceZ
->getArray();
198 if( nRotatedTexture
==0 )
200 *pInnerSequenceX
++ = 0.0;
201 *pInnerSequenceY
++ = 0.0;
202 *pInnerSequenceZ
++ = 0.0;
204 *pInnerSequenceX
++ = 0.0;
205 *pInnerSequenceY
++ = 1.0;
206 *pInnerSequenceZ
++ = 0.0;
208 *pInnerSequenceX
++ = 1.0;
209 *pInnerSequenceY
++ = 1.0;
210 *pInnerSequenceZ
++ = 0.0;
212 *pInnerSequenceX
++ = 1.0;
213 *pInnerSequenceY
++ = 0.0;
214 *pInnerSequenceZ
++ = 0.0;
216 else if( nRotatedTexture
==1 )
218 *pInnerSequenceX
++ = 1.0;
219 *pInnerSequenceY
++ = 0.0;
220 *pInnerSequenceZ
++ = 0.0;
222 *pInnerSequenceX
++ = 0.0;
223 *pInnerSequenceY
++ = 0.0;
224 *pInnerSequenceZ
++ = 0.0;
226 *pInnerSequenceX
++ = 0.0;
227 *pInnerSequenceY
++ = 1.0;
228 *pInnerSequenceZ
++ = 0.0;
230 *pInnerSequenceX
++ = 1.0;
231 *pInnerSequenceY
++ = 1.0;
232 *pInnerSequenceZ
++ = 0.0;
234 else if( nRotatedTexture
==2 )
236 *pInnerSequenceX
++ = 1.0;
237 *pInnerSequenceY
++ = 1.0;
238 *pInnerSequenceZ
++ = 0.0;
240 *pInnerSequenceX
++ = 1.0;
241 *pInnerSequenceY
++ = 0.0;
242 *pInnerSequenceZ
++ = 0.0;
244 *pInnerSequenceX
++ = 0.0;
245 *pInnerSequenceY
++ = 0.0;
246 *pInnerSequenceZ
++ = 0.0;
248 *pInnerSequenceX
++ = 0.0;
249 *pInnerSequenceY
++ = 1.0;
250 *pInnerSequenceZ
++ = 0.0;
252 else if( nRotatedTexture
==3 )
254 *pInnerSequenceX
++ = 0.0;
255 *pInnerSequenceY
++ = 1.0;
256 *pInnerSequenceZ
++ = 0.0;
258 *pInnerSequenceX
++ = 1.0;
259 *pInnerSequenceY
++ = 1.0;
260 *pInnerSequenceZ
++ = 0.0;
262 *pInnerSequenceX
++ = 1.0;
263 *pInnerSequenceY
++ = 0.0;
264 *pInnerSequenceZ
++ = 0.0;
266 *pInnerSequenceX
++ = 0.0;
267 *pInnerSequenceY
++ = 0.0;
268 *pInnerSequenceZ
++ = 0.0;
270 else if( nRotatedTexture
==4 )
272 *pInnerSequenceX
++ = 1.0;
273 *pInnerSequenceY
++ = 0.0;
274 *pInnerSequenceZ
++ = 0.0;
276 *pInnerSequenceX
++ = 1.0;
277 *pInnerSequenceY
++ = 1.0;
278 *pInnerSequenceZ
++ = 0.0;
280 *pInnerSequenceX
++ = 0.0;
281 *pInnerSequenceY
++ = 1.0;
282 *pInnerSequenceZ
++ = 0.0;
284 *pInnerSequenceX
++ = 0.0;
285 *pInnerSequenceY
++ = 0.0;
286 *pInnerSequenceZ
++ = 0.0;
288 else if( nRotatedTexture
==5 )
290 *pInnerSequenceX
++ = 0.0;
291 *pInnerSequenceY
++ = 0.0;
292 *pInnerSequenceZ
++ = 0.0;
294 *pInnerSequenceX
++ = 1.0;
295 *pInnerSequenceY
++ = 0.0;
296 *pInnerSequenceZ
++ = 0.0;
298 *pInnerSequenceX
++ = 1.0;
299 *pInnerSequenceY
++ = 1.0;
300 *pInnerSequenceZ
++ = 0.0;
302 *pInnerSequenceX
++ = 0.0;
303 *pInnerSequenceY
++ = 1.0;
304 *pInnerSequenceZ
++ = 0.0;
306 else if( nRotatedTexture
==6 )
308 *pInnerSequenceX
++ = 0.0;
309 *pInnerSequenceY
++ = 1.0;
310 *pInnerSequenceZ
++ = 0.0;
312 *pInnerSequenceX
++ = 0.0;
313 *pInnerSequenceY
++ = 0.0;
314 *pInnerSequenceZ
++ = 0.0;
316 *pInnerSequenceX
++ = 1.0;
317 *pInnerSequenceY
++ = 0.0;
318 *pInnerSequenceZ
++ = 0.0;
320 *pInnerSequenceX
++ = 1.0;
321 *pInnerSequenceY
++ = 1.0;
322 *pInnerSequenceZ
++ = 0.0;
324 else if( nRotatedTexture
==7 )
326 *pInnerSequenceX
++ = 1.0;
327 *pInnerSequenceY
++ = 1.0;
328 *pInnerSequenceZ
++ = 0.0;
330 *pInnerSequenceX
++ = 0.0;
331 *pInnerSequenceY
++ = 1.0;
332 *pInnerSequenceZ
++ = 0.0;
334 *pInnerSequenceX
++ = 0.0;
335 *pInnerSequenceY
++ = 0.0;
336 *pInnerSequenceZ
++ = 0.0;
338 *pInnerSequenceX
++ = 1.0;
339 *pInnerSequenceY
++ = 0.0;
340 *pInnerSequenceZ
++ = 0.0;
343 return uno::Any( &aPP
, cppu::UnoType
<drawing::PolyPolygonShape3D
>::get());
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */