1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofe3dsphere.hxx>
28 #include <svx/sphere3d.hxx>
29 #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx>
30 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
31 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace sdr
36 {
37 	namespace contact
38 	{
ViewContactOfE3dSphere(E3dSphereObj & rSphere)39 		ViewContactOfE3dSphere::ViewContactOfE3dSphere(E3dSphereObj& rSphere)
40 		:	ViewContactOfE3d(rSphere)
41 		{
42 		}
43 
~ViewContactOfE3dSphere()44 		ViewContactOfE3dSphere::~ViewContactOfE3dSphere()
45 		{
46 		}
47 
createViewIndependentPrimitive3DSequence() const48 		drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dSphere::createViewIndependentPrimitive3DSequence() const
49 		{
50 			drawinglayer::primitive3d::Primitive3DSequence xRetval;
51 			const SfxItemSet& rItemSet = GetE3dSphereObj().GetMergedItemSet();
52 			const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
53 				drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
54 
55 			// get sphere center and size for geometry
56 			basegfx::B3DRange aSphereRange;
57 			const basegfx::B3DPoint aSpherePosition(GetE3dSphereObj().Center());
58 			const basegfx::B3DVector aSphereSize(GetE3dSphereObj().Size());
59 			basegfx::B3DHomMatrix aWorldTransform;
60 
61 			aWorldTransform.translate(-0.5, -0.5, -0.5);
62 			aWorldTransform.scale(aSphereSize.getX(), aSphereSize.getY(), aSphereSize.getZ());
63 			aWorldTransform.translate(aSpherePosition.getX(), aSpherePosition.getY(), aSpherePosition.getZ());
64 
65 			// get 3D Object Attributes
66 			drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
67 
68 			// get segment count
69 			const sal_uInt32 nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
70 			const sal_uInt32 nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
71 
72 			// calculate texture size, use radii for (2 * PI * r) to get a perfect
73 			// mapping on the sphere
74 			const basegfx::B2DVector aTextureSize(
75 				F_PI * ((aSphereSize.getX() + aSphereSize.getZ()) / 2.0), // PI * d
76 				F_PI2 * aSphereSize.getY()); // half outline, (PI * d)/2 -> PI/2 * d
77 
78 			// create primitive and add
79 			const drawinglayer::primitive3d::Primitive3DReference xReference(
80 				new drawinglayer::primitive3d::SdrSpherePrimitive3D(
81 					aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
82 					nHorizontalSegments, nVerticalSegments));
83             xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
84 
85 			// delete 3D Object Attributes
86 			delete pSdr3DObjectAttribute;
87 
88 			return xRetval;
89 		}
90 	} // end of namespace contact
91 } // end of namespace sdr
92 
93 //////////////////////////////////////////////////////////////////////////////
94 // eof
95