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: msashape3d.cxx,v $
10 * $Revision: 1.13.226.1 $
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_svx.hxx"
33 #include <msashape3d.hxx>
34 #include <tools/poly.hxx>
35 #include <svditer.hxx>
36 #include <svx/svdobj.hxx>
37 #include <svtools/poolitem.hxx>
38 #include <svtools/itemset.hxx>
39 #include <svx/xfillit0.hxx>
40 #include <svx/xit.hxx>
41 #include <svx/xbtmpit.hxx>
42 #include <svx/xflclit.hxx>
43 #include <svx/svdopath.hxx>
44 #include <svx/svdogrp.hxx>
45 #include <svx/svdpage.hxx>
46 #include <svx/polysc3d.hxx>
47 #include <svx/svddef.hxx>
48 #include <svx/svx3ditems.hxx>
49 #include <svx/extrud3d.hxx>
50 #include <svx/xflbmtit.hxx>
51 #include <vcl/svapp.hxx>
52 #include <svx/xlnclit.hxx>
54 #define ITEMVALUE(ItemSet,Id,Cast) ((const Cast&)(ItemSet).Get(Id)).GetValue()
56 double SvxMSDffCustomShape3D::Fix16ToAngle( sal_Int32 nFixAngle
)
67 SvxMSDffCustomShape3D::Transformation2D::Transformation2D( const DffPropSet
& rPropSet
, const Rectangle
& rSnapRect
) :
68 aCenter( rSnapRect
.Center() )
70 bParallel
= ( rPropSet
.GetPropertyValue( DFF_Prop_fc3DFillHarsh
, 0 ) & 4 ) != 0;
73 fSkewAngle
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_c3DSkewAngle
, sal::static_int_cast
< UINT32
>( -135 * 65536 ) ) ) * F_PI180
;
74 nSkewAmount
= rPropSet
.GetPropertyValue( DFF_Prop_c3DSkewAmount
, 50 );
79 fViewPointOriginX
= ((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DOriginX
, 32768 )) * rSnapRect
.GetWidth()) / 65536.0;
80 fViewPointOriginY
= ((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DOriginY
, (sal_uInt32
)-32768 )) * rSnapRect
.GetHeight()) / 65536.0;
81 fViewPoint
.setX((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DXViewpoint
, 1250000 )) / 360); // 360 emu = 0,01 mm
82 fViewPoint
.setY((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DYViewpoint
, (sal_uInt32
)-1250000 )) / 360);
83 fViewPoint
.setZ((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DZViewpoint
, (sal_uInt32
)-9000000 )) / 360);
87 basegfx::B3DPolygon
SvxMSDffCustomShape3D::Transformation2D::ApplySkewSettings( const basegfx::B3DPolygon
& rPoly3D
)
89 basegfx::B3DPolygon aRetval
;
92 for ( j
= 0L; j
< rPoly3D
.count(); j
++ )
94 const basegfx::B3DPoint
aPoint(rPoly3D
.getB3DPoint(j
));
95 const double fDepth(-( aPoint
.getZ() * nSkewAmount
) / 100.0);
96 const basegfx::B3DPoint
aNewPoint(
97 aPoint
.getX() + (fDepth
* cos( fSkewAngle
)),
98 aPoint
.getY() - ( fDepth
* sin( fSkewAngle
)),
100 aRetval
.append(aNewPoint
);
106 Point
SvxMSDffCustomShape3D::Transformation2D::Transform2D( const basegfx::B3DPoint
& rPoint3D
)
111 aPoint2D
.X() = (sal_Int32
)rPoint3D
.getX();
112 aPoint2D
.Y() = (sal_Int32
)rPoint3D
.getY();
116 double fX
= rPoint3D
.getX() - fViewPointOriginX
;
117 double fY
= rPoint3D
.getY() - fViewPointOriginY
;
118 double f
= ( fZScreen
- fViewPoint
.getZ() ) / ( rPoint3D
.getZ() - fViewPoint
.getZ() );
119 aPoint2D
.X() = (sal_Int32
)(( fX
- fViewPoint
.getX() ) * f
+ fViewPoint
.getX() + fViewPointOriginX
);
120 aPoint2D
.Y() = (sal_Int32
)(( fY
- fViewPoint
.getY() ) * f
+ fViewPoint
.getY() + fViewPointOriginY
);
122 aPoint2D
.Move( aCenter
.X(), aCenter
.Y() );
126 basegfx::B3DPoint
SvxMSDffCustomShape3D::Rotate( const basegfx::B3DPoint
& rPoint
, const double x
, const double y
, const double z
)
128 basegfx::B3DPoint
aRetval(rPoint
);
129 basegfx::B3DPoint
aPoint( rPoint
);
132 aRetval
.setX(aPoint
.getX() * cos( z
) + aPoint
.getY() * sin( z
));
133 aRetval
.setY(-( aPoint
.getX() * sin( z
) ) + aPoint
.getY() * cos( z
));
137 aRetval
.setX(aPoint
.getX() * cos( y
) + aPoint
.getZ() * sin( y
));
138 aRetval
.setZ(-( aPoint
.getX() * sin( y
) ) + aPoint
.getZ() * cos( y
));
142 aRetval
.setY(aPoint
.getY() * cos( x
) + aPoint
.getZ() * sin( x
));
143 aRetval
.setZ(-( aPoint
.getY() * sin( x
) ) + aPoint
.getZ() * cos( x
));
148 //basegfx::B3DPolyPolygon SvxMSDffCustomShape3D::Rotate( const basegfx::B3DPolyPolygon& rPolyPoly3D, const basegfx::B3DPoint& rOrigin, const double x, const double y, const double z )
150 // basegfx::B3DPolyPolygon aRetval;
153 // for( i = 0L; i < rPolyPoly3D.count(); i++ )
155 // const basegfx::B3DPolygon aPoly3D(rPolyPoly3D.getB3DPolygon(i));
156 // basegfx::B3DPolygon rNewPoly;
158 // for( j = 0L; j < aPoly3D.count(); j++ )
160 // basegfx::B3DPoint aPoint(aPoly3D.getB3DPoint(j));
162 // aPoint -= rOrigin;
163 // aPoint = Rotate( aPoint, x, y, z );
164 // aPoint += rOrigin;
166 // rNewPoly.append(aPoint);
169 // aRetval.append(rNewPoly);
175 SdrObject
* SvxMSDffCustomShape3D::Create3DObject( const SdrObject
* pObj
, const DffPropSet
& rPropSet
,
176 SfxItemSet
& aSet
, Rectangle
& rSnapRect
, sal_uInt32 nSpFlags
)
178 SdrObject
* pRet
= NULL
;
179 std::vector
< E3dCompoundObject
* > aPlaceholderObjectList
;
181 double fExtrusionBackward
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DExtrudeBackward
, 457200 )) / 360.0; // in emus
182 double fExtrusionForward
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DExtrudeForward
, 0 )) / 360.0;
183 double fDepth
= fExtrusionBackward
- fExtrusionForward
;
186 ProjectionType
eProjectionType( rPropSet
.GetPropertyValue( DFF_Prop_fc3DFillHarsh
, 0 ) & 4 ? PR_PARALLEL
: PR_PERSPECTIVE
);
188 // pObj Umwandeln in Szene mit 3D Objekt
189 E3dDefaultAttributes a3DDefaultAttr
;
190 a3DDefaultAttr
.SetDefaultLatheCharacterMode( TRUE
);
191 a3DDefaultAttr
.SetDefaultExtrudeCharacterMode( TRUE
);
193 E3dScene
* pScene
= new E3dPolyScene( a3DDefaultAttr
);
195 sal_Bool
bSceneHasObjects ( sal_False
);
196 sal_Bool
bUseTwoFillStyles( sal_False
);
198 MSO_3DRenderMode
eRenderMode( (MSO_3DRenderMode
)rPropSet
.GetPropertyValue( DFF_Prop_c3DRenderMode
, mso_FullRender
) );
199 XFillStyle
eFillStyle( ITEMVALUE( aSet
, XATTR_FILLSTYLE
, XFillStyleItem
) );
200 pScene
->SetMergedItem( Svx3DShadeModeItem( 0 ) );
201 aSet
.Put( Svx3DPercentDiagonalItem( 0 ) );
202 aSet
.Put( Svx3DTextureModeItem( 1 ) );
203 if ( eRenderMode
== mso_Wireframe
)
205 aSet
.Put( XLineStyleItem( XLINE_SOLID
) );
206 aSet
.Put( XFillStyleItem ( XFILL_NONE
) );
207 aSet
.Put( Svx3DDoubleSidedItem( TRUE
) );
211 aSet
.Put( XLineStyleItem( XLINE_NONE
) );
212 if ( eFillStyle
== XFILL_NONE
)
213 aSet
.Put( XFillStyleItem( XFILL_SOLID
) );
214 else if ( ( eFillStyle
== XFILL_BITMAP
) || ( eFillStyle
== XFILL_GRADIENT
) )
215 bUseTwoFillStyles
= sal_True
;
217 const SdrObject
* pNext
= NULL
;
218 SdrObjListIter
* pIter
= NULL
;
219 if ( pObj
->IsGroupObject() )
221 pIter
= new SdrObjListIter( *pObj
, IM_DEEPWITHGROUPS
);
222 if ( pIter
->IsMore() )
223 pNext
= pIter
->Next();
229 const SfxItemSet
& rNextItemSet
= pNext
->GetMergedItemSet();
231 sal_Bool bIsPlaceholderObject
= (((XFillStyleItem
&)rNextItemSet
.Get( XATTR_FILLSTYLE
)).GetValue() == XFILL_NONE
)
232 && (((XLineStyleItem
&)rNextItemSet
.Get( XATTR_LINESTYLE
)).GetValue() == XLINE_NONE
);
234 SdrObject
* pNewObj
= pNext
->ConvertToPolyObj( FALSE
, FALSE
);
235 SdrPathObj
* pPath
= PTR_CAST( SdrPathObj
, pNewObj
);
238 const basegfx::B2DPolyPolygon
aPolyPolygon(pPath
->GetPathPoly());
239 E3dCompoundObject
* p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, aPolyPolygon
, bUseTwoFillStyles
? 1 : fDepth
);
240 p3DObj
->NbcSetLayer( pObj
->GetLayer() );
241 p3DObj
->SetMergedItemSet( aSet
);
242 if ( bIsPlaceholderObject
)
243 aPlaceholderObjectList
.push_back( p3DObj
);
244 else if ( bUseTwoFillStyles
)
247 sal_Bool bFillBmpTile
= ((XFillBmpTileItem
&)p3DObj
->GetMergedItem( XATTR_FILLBMP_TILE
)).GetValue();
250 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem( XATTR_FILLBITMAP
);
251 const XOBitmap
& rXOBmp
= rBmpItm
.GetBitmapValue();
252 aFillBmp
= rXOBmp
.GetBitmap();
253 Size aLogicalSize
= aFillBmp
.GetPrefSize();
254 if ( aFillBmp
.GetPrefMapMode() == MAP_PIXEL
)
255 aLogicalSize
= Application::GetDefaultDevice()->PixelToLogic( aLogicalSize
, MAP_100TH_MM
);
257 aLogicalSize
= OutputDevice::LogicToLogic( aLogicalSize
, aFillBmp
.GetPrefMapMode(), MAP_100TH_MM
);
258 aLogicalSize
.Width() *= 5; ;// :-( nice scaling, look at engine3d/obj3d.cxx
259 aLogicalSize
.Height() *= 5;
260 aFillBmp
.SetPrefSize( aLogicalSize
);
261 aFillBmp
.SetPrefMapMode( MAP_100TH_MM
);
262 p3DObj
->SetMergedItem( XFillBitmapItem( String(), aFillBmp
) );
266 Rectangle
aBoundRect( PolyPolygon(aPolyPolygon
).GetBoundRect() );
267 if ( rSnapRect
!= aBoundRect
)
269 const XFillBitmapItem
& rBmpItm
= (XFillBitmapItem
&)p3DObj
->GetMergedItem( XATTR_FILLBITMAP
);
270 const XOBitmap
& rXOBmp
= rBmpItm
.GetBitmapValue();
271 aFillBmp
= rXOBmp
.GetBitmap();
272 Size
aBmpSize( aFillBmp
.GetSizePixel() );
273 double fXScale
= (double)aBoundRect
.GetWidth() / (double)rSnapRect
.GetWidth();
274 double fYScale
= (double)aBoundRect
.GetHeight() / (double)rSnapRect
.GetHeight();
276 Point
aPt( (sal_Int32
)( (double)( aBoundRect
.Left() - rSnapRect
.Left() )* (double)aBmpSize
.Width() / (double)rSnapRect
.GetWidth() ),
277 (sal_Int32
)( (double)( aBoundRect
.Top() - rSnapRect
.Top() ) * (double)aBmpSize
.Height() / (double)rSnapRect
.GetHeight() ) );
278 Size
aSize( (sal_Int32
)( aBmpSize
.Width() * fXScale
),
279 (sal_Int32
)( aBmpSize
.Height() * fYScale
) );
280 Rectangle
aCropRect( aPt
, aSize
);
281 aFillBmp
.Crop( aCropRect
);
282 p3DObj
->SetMergedItem( XFillBitmapItem( String(), aFillBmp
) );
285 pScene
->Insert3DObj( p3DObj
);
286 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, pPath
->GetPathPoly(), fDepth
);
287 p3DObj
->NbcSetLayer( pObj
->GetLayer() );
288 p3DObj
->SetMergedItemSet( aSet
);
289 p3DObj
->SetMergedItem( XFillStyleItem( XFILL_SOLID
) );
290 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( sal_False
) );
291 p3DObj
->SetMergedItem( Svx3DCloseBackItem( sal_False
) );
292 pScene
->Insert3DObj( p3DObj
);
293 p3DObj
= new E3dExtrudeObj( a3DDefaultAttr
, pPath
->GetPathPoly(), 1 );
294 p3DObj
->NbcSetLayer( pObj
->GetLayer() );
295 p3DObj
->SetMergedItemSet( aSet
);
296 basegfx::B3DHomMatrix
aFrontTransform( p3DObj
->GetTransform() );
297 aFrontTransform
.translate( 0.0, 0.0, fDepth
);
298 p3DObj
->NbcSetTransform( aFrontTransform
);
299 if ( ( eFillStyle
== XFILL_BITMAP
) && !aFillBmp
.IsEmpty() )
300 p3DObj
->SetMergedItem( XFillBitmapItem( String(), aFillBmp
) );
302 else if ( eFillStyle
== XFILL_NONE
)
304 XLineColorItem
& rLineColor
= (XLineColorItem
&)p3DObj
->GetMergedItem( XATTR_LINECOLOR
);
305 p3DObj
->SetMergedItem( XFillColorItem( String(), rLineColor
.GetColorValue() ) );
306 p3DObj
->SetMergedItem( Svx3DDoubleSidedItem( sal_True
) );
307 p3DObj
->SetMergedItem( Svx3DCloseFrontItem( sal_False
) );
308 p3DObj
->SetMergedItem( Svx3DCloseBackItem( sal_False
) );
310 pScene
->Insert3DObj( p3DObj
);
311 bSceneHasObjects
= sal_True
;
313 SdrObject::Free( pNewObj
);
315 if ( pIter
&& pIter
->IsMore() )
316 pNext
= pIter
->Next();
320 if ( bSceneHasObjects
) // is the SdrObject properly converted
322 // then we can change the return value
325 // Kameraeinstellungen, Perspektive ...
326 Camera3D
& rCamera
= (Camera3D
&)pScene
->GetCamera();
327 const basegfx::B3DRange
& rVolume
= pScene
->GetBoundVolume();
328 pScene
->NbcSetSnapRect( rSnapRect
);
330 // InitScene replacement
331 double fW(rVolume
.getWidth());
332 double fH(rVolume
.getHeight());
334 rCamera
.SetAutoAdjustProjection( FALSE
);
335 rCamera
.SetViewWindow( -fW
/ 2, - fH
/ 2, fW
, fH
);
336 basegfx::B3DPoint
aLookAt( 0.0, 0.0, 0.0 );
337 basegfx::B3DPoint
aCamPos( 0.0, 0.0, 100.0 );
339 rCamera
.SetDefaults( basegfx::B3DPoint( 0.0, 0.0, 100.0 ), aLookAt
, 100.0 );
340 rCamera
.SetPosAndLookAt( aCamPos
, aLookAt
);
341 rCamera
.SetFocalLength( 1.0 );
342 rCamera
.SetProjection( eProjectionType
);
343 pScene
->SetCamera( rCamera
);
344 pScene
->SetRectsDirty();
346 double fViewPointOriginX
= ((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DOriginX
, 32768 )) * rSnapRect
.GetWidth()) / 65536.0;
347 double fViewPointOriginY
= ((double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DOriginY
, (sal_uInt32
)-32768 )) * rSnapRect
.GetHeight()) / 65536.0;
349 basegfx::B3DHomMatrix
aNewTransform( pScene
->GetTransform() );
350 Point
aCenter( rSnapRect
.Center() );
351 aNewTransform
.translate( -aCenter
.X(), aCenter
.Y(), -pScene
->GetBoundVolume().getDepth() );
352 double fXRotate
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_c3DXRotationAngle
, 0 ) );
353 double fYRotate
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_c3DYRotationAngle
, 0 ) );
354 double fZRotate
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_Rotation
, 0 ) );
355 if ( fZRotate
!= 0.0 )
357 aNewTransform
.rotate(0.0, 0.0, -fZRotate
* F_PI180
);
359 if ( nSpFlags
& SP_FFLIPH
)
361 aNewTransform
.scale( -1.0, 0.0, 0.0 );
363 if ( nSpFlags
& SP_FFLIPV
)
365 aNewTransform
.scale(0.0, -1.0, 0.0 );
367 if( fYRotate
!= 0.0 )
369 aNewTransform
.rotate( 0.0, -fYRotate
* F_PI180
, 0.0 );
371 if( fXRotate
!= 0.0 )
373 aNewTransform
.rotate( -fXRotate
* F_PI180
, 0.0, 0.0 );
375 if ( eProjectionType
== PR_PARALLEL
)
377 sal_Int32 nSkewAmount
= rPropSet
.GetPropertyValue( DFF_Prop_c3DSkewAmount
, 50 );
380 sal_Int32 nSkewAngle
= ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DSkewAngle
, sal::static_int_cast
< UINT32
>( -135 * 65536 ) ) ) >> 16;
382 double fAlpha( (double)nSkewAngle
* F_PI180
);
383 double fInvTanBeta( (double)nSkewAmount
/ 100.0 );
386 aNewTransform
.shearXY(
387 fInvTanBeta
* cos(fAlpha
),
388 fInvTanBeta
* sin(fAlpha
));
394 aNewTransform
.translate( -fViewPointOriginX
, fViewPointOriginY
, 0.0 );
395 // now set correct camera position
396 // double fViewPointOriginX = ((double)((sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_c3DOriginX, 32768 )) * rSnapRect.GetWidth()) / 65536.0;
397 // double fViewPointOriginY = ((double)((sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_c3DOriginY, (sal_uInt32)-32768 )) * rSnapRect.GetHeight()) / 65536.0;
398 double fViewPointX
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DXViewpoint
, 1250000 )) / 360;
399 double fViewPointY
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DYViewpoint
,(sal_uInt32
)-1250000 )) / 360;
400 double fViewPointZ
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DZViewpoint
,(sal_uInt32
)-9000000 )) / 360;
402 basegfx::B3DPoint
aNewLookAt( fViewPointX
, -fViewPointY
, 0 );
403 basegfx::B3DPoint
aNewCamPos( fViewPointX
, -fViewPointY
, -fViewPointZ
);
404 rCamera
.SetPosAndLookAt( aNewCamPos
, aNewLookAt
);
405 pScene
->SetCamera( rCamera
);
407 pScene
->NbcSetTransform( aNewTransform
);
412 double fAmbientIntensity
= ((double)rPropSet
.GetPropertyValue( DFF_Prop_c3DAmbientIntensity
, 22178 )) / 65536.0;
414 sal_Int32 nLightX
= ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DKeyX
, 50000 )) / 360;
415 sal_Int32 nLightY
= - ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DKeyY
, 0 )) / 360;
416 sal_Int32 nLightZ
= - ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DKeyZ
, 10000 )) / 360;
419 double fLightIntensity
= ((double)rPropSet
.GetPropertyValue( DFF_Prop_c3DKeyIntensity
, 43712 )) / 65536.0;
420 // sal_Bool bLightHarsh = ( rPropSet.GetPropertyValue( DFF_Prop_fc3DFillHarsh, 0 ) & 2 ) != 0;
422 sal_Int32 nLight2X
= ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DFillX
, (sal_uInt32
)-50000 )) / 360;
423 sal_Int32 nLight2Y
= - ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DFillY
, 0 )) / 360;
424 sal_Int32 nLight2Z
= - ((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DFillZ
, 10000 )) / 360;
427 double fLight2Intensity
= ((double)rPropSet
.GetPropertyValue( DFF_Prop_c3DFillIntensity
, 43712 )) / 65536.0;
428 // sal_Bool bLight2Harsh = ( rPropSet.GetPropertyValue( DFF_Prop_fc3DFillHarsh, 0 ) & 1 ) != 0;
429 // sal_Bool bLightFace = ( rPropSet.GetPropertyValue( DFF_Prop_fc3DLightFace, 0 ) & 1 ) != 0;
431 sal_uInt16 nAmbientColor
= (sal_uInt16
)( fAmbientIntensity
* 255.0 );
432 if ( nAmbientColor
> 255 )
434 Color
aGlobalAmbientColor( (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
, (sal_uInt8
)nAmbientColor
);
435 pScene
->SetMergedItem( Svx3DAmbientcolorItem( aGlobalAmbientColor
) );
437 sal_uInt8 nSpotLight1
= (sal_uInt8
)( fLightIntensity
* 255.0 );
438 basegfx::B3DVector
aSpotLight1( (double)nLightX
, (double)nLightY
, (double)nLightZ
);
439 aSpotLight1
.normalize();
440 pScene
->SetMergedItem( Svx3DLightOnOff1Item( sal_True
) );
441 Color
aAmbientSpot1Color( nSpotLight1
, nSpotLight1
, nSpotLight1
);
442 pScene
->SetMergedItem( Svx3DLightcolor1Item( aAmbientSpot1Color
) );
443 pScene
->SetMergedItem( Svx3DLightDirection1Item( aSpotLight1
) );
445 sal_uInt8 nSpotLight2
= (sal_uInt8
)( fLight2Intensity
* 255.0 );
446 basegfx::B3DVector
aSpotLight2( (double)nLight2X
, (double)nLight2Y
, (double)nLight2Z
);
447 aSpotLight2
.normalize();
448 pScene
->SetMergedItem( Svx3DLightOnOff2Item( sal_True
) );
449 Color
aAmbientSpot2Color( nSpotLight2
, nSpotLight2
, nSpotLight2
);
450 pScene
->SetMergedItem( Svx3DLightcolor2Item( aAmbientSpot2Color
) );
451 pScene
->SetMergedItem( Svx3DLightDirection2Item( aSpotLight2
) );
453 if ( nLightX
|| nLightY
)
455 sal_uInt8 nSpotLight3
= 70;
456 basegfx::B3DVector
aSpotLight3( 0.0, 0.0, 1.0 );
457 pScene
->SetMergedItem( Svx3DLightOnOff3Item( sal_True
) );
458 Color
aAmbientSpot3Color( nSpotLight3
, nSpotLight3
, nSpotLight3
);
459 pScene
->SetMergedItem( Svx3DLightcolor3Item( aAmbientSpot3Color
) );
460 pScene
->SetMergedItem( Svx3DLightDirection3Item( aSpotLight3
) );
463 double fSpecular
= ((double)rPropSet
.GetPropertyValue( DFF_Prop_c3DSpecularAmt
, 0 )) / 65536.0;
464 // double fDiffuse = ((double)rPropSet.GetPropertyValue( DFF_Prop_c3DDiffuseAmt, 0 )) / 65536.0;
465 // double fShininess = ((double)rPropSet.GetPropertyValue( DFF_Prop_c3DShininess, 0 )) / 65536.0;
467 sal_uInt16 nItensity
= 25;
468 Color
aSpecularCol( COL_BLACK
);
469 if ( fSpecular
== 0.0 )
471 aSpecularCol
= Color( 51, 51, 51 );
473 else if ( fSpecular
> 1.2 )
475 aSpecularCol
= Color( 128, 128, 128 );
477 pScene
->SetMergedItem( Svx3DMaterialSpecularItem( aSpecularCol
) );
478 pScene
->SetMergedItem( Svx3DMaterialSpecularIntensityItem( nItensity
) );
480 pScene
->SetModel( pObj
->GetModel() );
481 pRet
->SetSnapRect( CalculateNewSnapRect( rSnapRect
, rPropSet
) );
483 // removing placeholder objects
484 std::vector
< E3dCompoundObject
* >::iterator
aObjectListIter( aPlaceholderObjectList
.begin() );
485 while ( aObjectListIter
!= aPlaceholderObjectList
.end() )
487 pScene
->Remove3DObj( *aObjectListIter
);
488 delete *aObjectListIter
++;
496 Rectangle
SvxMSDffCustomShape3D::CalculateNewSnapRect( const Rectangle
& rOriginalSnapRect
, const DffPropSet
& rPropSet
)
498 const Point
aCenter( rOriginalSnapRect
.Center() );
499 //double fExtrusionBackward = (double)((sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_c3DExtrudeBackward, 457200 )) / 360.0;
500 double fExtrusionForward
= (double)((sal_Int32
)rPropSet
.GetPropertyValue( DFF_Prop_c3DExtrudeForward
, 0 )) / 360.0;
503 // creating initial bound volume ( without rotation. skewing.and camera )
504 basegfx::B3DPolygon aBoundVolume
;
505 const Polygon
aPolygon( rOriginalSnapRect
);
507 for ( i
= 0L; i
< 4L; i
++ )
509 aBoundVolume
.append(basegfx::B3DPoint(
510 aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(),
511 aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(),
515 for ( ; i
< 8L; i
++ )
517 aBoundVolume
.append(basegfx::B3DPoint(
518 aPolygon
[ (sal_uInt16
)i
].X() - aCenter
.X(),
519 aPolygon
[ (sal_uInt16
)i
].Y() - aCenter
.Y(),
523 basegfx::B3DPoint aRotateCenter
;
524 aRotateCenter
.setX(0.0);
525 aRotateCenter
.setY(0.0);
526 aRotateCenter
.setZ(rPropSet
.GetPropertyValue( DFF_Prop_c3DRotationCenterZ
, 0 ) / 360);
528 // double XCenterInGUnits = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationCenterX, 0 );
529 // double YCenterInGUnits = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationCenterY, 0 );
531 // sal_Int32 nRotationXAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisX, 100 );
532 // sal_Int32 nRotationYAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisY, 0 );
533 // sal_Int32 nRotationZAxisInProz = rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAxisZ, 0 );
535 double fXRotate
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_c3DXRotationAngle
, 0 ) ) * F_PI180
;
536 double fYRotate
= Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_c3DYRotationAngle
, 0 ) ) * F_PI180
;
537 double fZRotate
= -Fix16ToAngle( rPropSet
.GetPropertyValue( DFF_Prop_Rotation
, 0 ) ) * F_PI180
;
538 // double fRotationAngle = Fix16ToAngle( rPropSet.GetPropertyValue( DFF_Prop_c3DRotationAngle, 0 ) ); // * F_PI180;
540 for( i
= 0; i
< 8; i
++ ) // rotating bound volume
542 basegfx::B3DPoint
aPoint(aBoundVolume
.getB3DPoint(i
));
543 aPoint
-= aRotateCenter
;
544 aPoint
= Rotate( aPoint
, fXRotate
, fYRotate
, fZRotate
);
545 aPoint
+= aRotateCenter
;
546 aBoundVolume
.setB3DPoint(i
, aPoint
);
549 Transformation2D
aTransformation2D( rPropSet
, rOriginalSnapRect
);
550 if ( aTransformation2D
.IsParallel() )
552 aBoundVolume
= aTransformation2D
.ApplySkewSettings( aBoundVolume
);
555 Polygon
aTransformed( 8 );
556 for ( i
= 0L; i
< 8L; i
++ )
558 aTransformed
[ (sal_uInt16
)i
] = aTransformation2D
.Transform2D( aBoundVolume
.getB3DPoint(i
) );
561 return aTransformed
.GetBoundRect();