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
30 {
31  namespace contact
32  {
34  : ViewContactOfE3d(rSphere)
35  {
36  }
37 
39  {
40  }
41 
43  {
45  const SfxItemSet& rItemSet = GetE3dSphereObj().GetMergedItemSet();
48 
49  // get sphere center and size for geometry
50  const basegfx::B3DPoint aSpherePosition(GetE3dSphereObj().Center());
51  const basegfx::B3DVector aSphereSize(GetE3dSphereObj().Size());
52  basegfx::B3DHomMatrix aWorldTransform;
53 
54  aWorldTransform.translate(-0.5, -0.5, -0.5);
55  aWorldTransform.scale(aSphereSize.getX(), aSphereSize.getY(), aSphereSize.getZ());
56  aWorldTransform.translate(aSpherePosition.getX(), aSpherePosition.getY(), aSpherePosition.getZ());
57 
58  // get 3D Object Attributes
59  std::unique_ptr<drawinglayer::attribute::Sdr3DObjectAttribute> pSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet));
60 
61  // get segment count
62  const sal_uInt32 nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
63  const sal_uInt32 nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
64 
65  // calculate texture size, use radii for (2 * PI * r) to get a perfect
66  // mapping on the sphere
67  const basegfx::B2DVector aTextureSize(
68  F_PI * ((aSphereSize.getX() + aSphereSize.getZ()) / 2.0), // PI * d
69  F_PI2 * aSphereSize.getY()); // half outline, (PI * d)/2 -> PI/2 * d
70 
71  // create primitive and add
74  aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
75  nHorizontalSegments, nVerticalSegments));
76  xRetval = { xReference };
77 
78  return xRetval;
79  }
80  } // end of namespace contact
81 } // end of namespace sdr
82 
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define F_PI2
double getZ() const
Center
void scale(double fX, double fY, double fZ)
attribute::Sdr3DObjectAttribute * createNewSdr3DObjectAttribute(const SfxItemSet &rSet)
double getX() const
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:1911
double getY() const
virtual drawinglayer::primitive3d::Primitive3DContainer createViewIndependentPrimitive3DContainer() const override