xref: /trunk/main/svx/source/sdr/contact/viewcontactofe3dsphere.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/sdr/contact/viewcontactofe3dsphere.hxx>
32 #include <svx/sphere3d.hxx>
33 #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx>
34 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
35 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace sdr
40 {
41     namespace contact
42     {
43         ViewContactOfE3dSphere::ViewContactOfE3dSphere(E3dSphereObj& rSphere)
44         :   ViewContactOfE3d(rSphere)
45         {
46         }
47 
48         ViewContactOfE3dSphere::~ViewContactOfE3dSphere()
49         {
50         }
51 
52         drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dSphere::createViewIndependentPrimitive3DSequence() const
53         {
54             drawinglayer::primitive3d::Primitive3DSequence xRetval;
55             const SfxItemSet& rItemSet = GetE3dSphereObj().GetMergedItemSet();
56             const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
57                 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
58 
59             // get sphere center and size for geometry
60             basegfx::B3DRange aSphereRange;
61             const basegfx::B3DPoint aSpherePosition(GetE3dSphereObj().Center());
62             const basegfx::B3DVector aSphereSize(GetE3dSphereObj().Size());
63             basegfx::B3DHomMatrix aWorldTransform;
64 
65             aWorldTransform.translate(-0.5, -0.5, -0.5);
66             aWorldTransform.scale(aSphereSize.getX(), aSphereSize.getY(), aSphereSize.getZ());
67             aWorldTransform.translate(aSpherePosition.getX(), aSpherePosition.getY(), aSpherePosition.getZ());
68 
69             // get 3D Object Attributes
70             drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
71 
72             // get segment count
73             const sal_uInt32 nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
74             const sal_uInt32 nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
75 
76             // calculate texture size, use radii for (2 * PI * r) to get a perfect
77             // mapping on the sphere
78             const basegfx::B2DVector aTextureSize(
79                 F_PI * ((aSphereSize.getX() + aSphereSize.getZ()) / 2.0), // PI * d
80                 F_PI2 * aSphereSize.getY()); // half outline, (PI * d)/2 -> PI/2 * d
81 
82             // create primitive and add
83             const drawinglayer::primitive3d::Primitive3DReference xReference(
84                 new drawinglayer::primitive3d::SdrSpherePrimitive3D(
85                     aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
86                     nHorizontalSegments, nVerticalSegments));
87             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
88 
89             // delete 3D Object Attributes
90             delete pSdr3DObjectAttribute;
91 
92             return xRetval;
93         }
94     } // end of namespace contact
95 } // end of namespace sdr
96 
97 //////////////////////////////////////////////////////////////////////////////
98 // eof
99