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: viewcontactofe3dsphere.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewcontactofe3dsphere.hxx>
36 #include <svx/sphere3d.hxx>
37 #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx>
38 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
39 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
41 //////////////////////////////////////////////////////////////////////////////
47 ViewContactOfE3dSphere::ViewContactOfE3dSphere(E3dSphereObj
& rSphere
)
48 : ViewContactOfE3d(rSphere
)
52 ViewContactOfE3dSphere::~ViewContactOfE3dSphere()
56 drawinglayer::primitive3d::Primitive3DSequence
ViewContactOfE3dSphere::createViewIndependentPrimitive3DSequence() const
58 drawinglayer::primitive3d::Primitive3DSequence xRetval
;
59 const SfxItemSet
& rItemSet
= GetE3dSphereObj().GetMergedItemSet();
60 drawinglayer::attribute::SdrLineFillShadowAttribute
* pAttribute
= drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet
, false);
62 // for 3D Objects, always create a primitive even when not visible. This is necessary ATM
63 // since e.g. chart geometries rely on the occupied space of non-visible objects
66 pAttribute
= new drawinglayer::attribute::SdrLineFillShadowAttribute(
67 impCreateFallbackLineAttribute(basegfx::BColor(0.0, 1.0, 0.0)),
71 // get sphere center and size for geometry
72 basegfx::B3DRange aSphereRange
;
73 const basegfx::B3DPoint
aSpherePosition(GetE3dSphereObj().Center());
74 const basegfx::B3DVector
aSphereSize(GetE3dSphereObj().Size());
75 basegfx::B3DHomMatrix aWorldTransform
;
77 aWorldTransform
.translate(-0.5, -0.5, -0.5);
78 aWorldTransform
.scale(aSphereSize
.getX(), aSphereSize
.getY(), aSphereSize
.getZ());
79 aWorldTransform
.translate(aSpherePosition
.getX(), aSpherePosition
.getY(), aSpherePosition
.getZ());
81 // get 3D Object Attributes
82 drawinglayer::attribute::Sdr3DObjectAttribute
* pSdr3DObjectAttribute
= drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet
);
85 const sal_uInt32
nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
86 const sal_uInt32
nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
88 // calculate texture size, use radii for (2 * PI * r) to get a perfect
89 // mapping on the sphere
90 const basegfx::B2DVector
aTextureSize(
91 F_PI
* ((aSphereSize
.getX() + aSphereSize
.getZ()) / 2.0), // PI * d
92 F_PI2
* aSphereSize
.getY()); // half outline, (PI * d)/2 -> PI/2 * d
94 // create primitive and add
95 const drawinglayer::primitive3d::Primitive3DReference
xReference(new drawinglayer::primitive3d::SdrSpherePrimitive3D(
96 aWorldTransform
, aTextureSize
, *pAttribute
, *pSdr3DObjectAttribute
,
97 nHorizontalSegments
, nVerticalSegments
));
98 xRetval
= drawinglayer::primitive3d::Primitive3DSequence(&xReference
, 1);
100 // delete 3D Object Attributes
101 delete pSdr3DObjectAttribute
;
106 } // end of namespace contact
107 } // end of namespace sdr
109 //////////////////////////////////////////////////////////////////////////////