LibreOffice Module svx (master)  1
viewcontactofe3dsphere.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
22 #include <svx/sphere3d.hxx>
26 #include <memory>
27 
28 
29 namespace sdr::contact
30 {
32  : ViewContactOfE3d(rSphere)
33  {
34  }
35 
37  {
38  }
39 
41  {
43  const SfxItemSet& rItemSet = GetE3dSphereObj().GetMergedItemSet();
46 
47  // get sphere center and size for geometry
48  const basegfx::B3DPoint aSpherePosition(GetE3dSphereObj().Center());
49  const basegfx::B3DVector aSphereSize(GetE3dSphereObj().Size());
50  basegfx::B3DHomMatrix aWorldTransform;
51 
52  aWorldTransform.translate(-0.5, -0.5, -0.5);
53  aWorldTransform.scale(aSphereSize.getX(), aSphereSize.getY(), aSphereSize.getZ());
54  aWorldTransform.translate(aSpherePosition.getX(), aSpherePosition.getY(), aSpherePosition.getZ());
55 
56  // get 3D Object Attributes
57  std::unique_ptr<drawinglayer::attribute::Sdr3DObjectAttribute> pSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
58 
59  // get segment count
60  const sal_uInt32 nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
61  const sal_uInt32 nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
62 
63  // calculate texture size, use radii for (2 * PI * r) to get a perfect
64  // mapping on the sphere
65  const basegfx::B2DVector aTextureSize(
66  F_PI * ((aSphereSize.getX() + aSphereSize.getZ()) / 2.0), // PI * d
67  F_PI2 * aSphereSize.getY()); // half outline, (PI * d)/2 -> PI/2 * d
68 
69  // create primitive and add
72  aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
73  nHorizontalSegments, nVerticalSegments));
74  xRetval = { xReference };
75 
76  return xRetval;
77  }
78 
79 } // end of namespace
80 
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define F_PI2
Center
void scale(double fX, double fY, double fZ)
attribute::Sdr3DObjectAttribute * createNewSdr3DObjectAttribute(const SfxItemSet &rSet)
attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet &rSet, bool bSuppressFill)
const E3dSphereObj & GetE3dSphereObj() const
SphereObject with diameter r3DSize.
Definition: sphere3d.hxx:35
#define F_PI
css::uno::Reference< css::graphic::XPrimitive3D > Primitive3DReference
void translate(double fX, double fY, double fZ)
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1889
virtual drawinglayer::primitive3d::Primitive3DContainer createViewIndependentPrimitive3DContainer() const override