fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofe3dsphere.cxx
blob927444afb1431a2debcc86b97a39b13843d3e849
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/sdr/contact/viewcontactofe3dsphere.hxx>
22 #include <svx/sphere3d.hxx>
23 #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx>
24 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
25 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
27 //////////////////////////////////////////////////////////////////////////////
29 namespace sdr
31 namespace contact
33 ViewContactOfE3dSphere::ViewContactOfE3dSphere(E3dSphereObj& rSphere)
34 : ViewContactOfE3d(rSphere)
38 ViewContactOfE3dSphere::~ViewContactOfE3dSphere()
42 drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dSphere::createViewIndependentPrimitive3DSequence() const
44 drawinglayer::primitive3d::Primitive3DSequence xRetval;
45 const SfxItemSet& rItemSet = GetE3dSphereObj().GetMergedItemSet();
46 const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
47 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
49 // get sphere center and size for geometry
50 basegfx::B3DRange aSphereRange;
51 const basegfx::B3DPoint aSpherePosition(GetE3dSphereObj().Center());
52 const basegfx::B3DVector aSphereSize(GetE3dSphereObj().Size());
53 basegfx::B3DHomMatrix aWorldTransform;
55 aWorldTransform.translate(-0.5, -0.5, -0.5);
56 aWorldTransform.scale(aSphereSize.getX(), aSphereSize.getY(), aSphereSize.getZ());
57 aWorldTransform.translate(aSpherePosition.getX(), aSpherePosition.getY(), aSpherePosition.getZ());
59 // get 3D Object Attributes
60 drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
62 // get segment count
63 const sal_uInt32 nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
64 const sal_uInt32 nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
66 // calculate texture size, use radii for (2 * PI * r) to get a perfect
67 // mapping on the sphere
68 const basegfx::B2DVector aTextureSize(
69 F_PI * ((aSphereSize.getX() + aSphereSize.getZ()) / 2.0), // PI * d
70 F_PI2 * aSphereSize.getY()); // half outline, (PI * d)/2 -> PI/2 * d
72 // create primitive and add
73 const drawinglayer::primitive3d::Primitive3DReference xReference(
74 new drawinglayer::primitive3d::SdrSpherePrimitive3D(
75 aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
76 nHorizontalSegments, nVerticalSegments));
77 xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
79 // delete 3D Object Attributes
80 delete pSdr3DObjectAttribute;
82 return xRetval;
84 } // end of namespace contact
85 } // end of namespace sdr
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */