1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sdr/contact/viewcontactofe3dsphere.hxx>
22 #include <svx/sphere3d.hxx>
23 #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx>
24 #include <sdr/primitive2d/sdrattributecreator.hxx>
25 #include <sdr/primitive3d/sdrattributecreator3d.hxx>
28 namespace sdr::contact
30 ViewContactOfE3dSphere::ViewContactOfE3dSphere(E3dSphereObj
& rSphere
)
31 : ViewContactOfE3d(rSphere
)
35 ViewContactOfE3dSphere::~ViewContactOfE3dSphere()
39 drawinglayer::primitive3d::Primitive3DContainer
ViewContactOfE3dSphere::createViewIndependentPrimitive3DContainer() const
41 drawinglayer::primitive3d::Primitive3DContainer xRetval
;
42 const SfxItemSet
& rItemSet
= GetE3dSphereObj().GetMergedItemSet();
43 const drawinglayer::attribute::SdrLineFillShadowAttribute3D
aAttribute(
44 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet
, false));
46 // get sphere center and size for geometry
47 const basegfx::B3DPoint
aSpherePosition(GetE3dSphereObj().Center());
48 const basegfx::B3DVector
aSphereSize(GetE3dSphereObj().Size());
49 basegfx::B3DHomMatrix aWorldTransform
;
51 aWorldTransform
.translate(-0.5, -0.5, -0.5);
52 aWorldTransform
.scale(aSphereSize
.getX(), aSphereSize
.getY(), aSphereSize
.getZ());
53 aWorldTransform
.translate(aSpherePosition
.getX(), aSpherePosition
.getY(), aSpherePosition
.getZ());
55 // get 3D Object Attributes
56 drawinglayer::attribute::Sdr3DObjectAttribute
aSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet
));
59 const sal_uInt32
nHorizontalSegments(GetE3dSphereObj().GetHorizontalSegments());
60 const sal_uInt32
nVerticalSegments(GetE3dSphereObj().GetVerticalSegments());
62 // calculate texture size, use radii for (2 * PI * r) to get a perfect
63 // mapping on the sphere
64 const basegfx::B2DVector
aTextureSize(
65 M_PI
* ((aSphereSize
.getX() + aSphereSize
.getZ()) / 2.0), // PI * d
66 M_PI_2
* aSphereSize
.getY()); // half outline, (PI * d)/2 -> PI/2 * d
68 // create primitive and add
69 const drawinglayer::primitive3d::Primitive3DReference
xReference(
70 new drawinglayer::primitive3d::SdrSpherePrimitive3D(
71 aWorldTransform
, aTextureSize
, aAttribute
, aSdr3DObjectAttribute
,
72 nHorizontalSegments
, nVerticalSegments
));
73 xRetval
= { xReference
};
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */