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 <svx/sdr/contact/viewcontactofe3dcube.hxx>
22 #include <svx/cube3d.hxx>
23 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
24 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
25 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
26 #include <basegfx/range/b3drange.hxx>
28 //////////////////////////////////////////////////////////////////////////////
34 ViewContactOfE3dCube::ViewContactOfE3dCube(E3dCubeObj
& rCubeObj
)
35 : ViewContactOfE3d(rCubeObj
)
39 ViewContactOfE3dCube::~ViewContactOfE3dCube()
43 drawinglayer::primitive3d::Primitive3DSequence
ViewContactOfE3dCube::createViewIndependentPrimitive3DSequence() const
45 drawinglayer::primitive3d::Primitive3DSequence xRetval
;
46 const SfxItemSet
& rItemSet
= GetE3dCubeObj().GetMergedItemSet();
47 const drawinglayer::attribute::SdrLineFillShadowAttribute3D
aAttribute(
48 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet
, false));
50 // get cube geometry and use as traslation and scaling for unit cube
51 basegfx::B3DRange aCubeRange
;
52 const basegfx::B3DVector
aCubeSize(GetE3dCubeObj().GetCubeSize());
53 const basegfx::B3DPoint
aCubePosition(GetE3dCubeObj().GetCubePos());
54 basegfx::B3DHomMatrix aWorldTransform
;
56 if(GetE3dCubeObj().GetPosIsCenter())
58 const basegfx::B3DVector
aHalfCubeSize(aCubeSize
/ 2.0);
59 aCubeRange
.expand(aCubePosition
- aHalfCubeSize
);
60 aCubeRange
.expand(aCubePosition
+ aHalfCubeSize
);
64 aCubeRange
.expand(aCubePosition
);
65 aCubeRange
.expand(aCubePosition
+ aCubeSize
);
68 // add scale and translate to world transformation
69 const basegfx::B3DVector
abjectRange(aCubeRange
.getRange());
70 aWorldTransform
.scale(abjectRange
.getX(), abjectRange
.getY(), abjectRange
.getZ());
71 aWorldTransform
.translate(aCubeRange
.getMinX(), aCubeRange
.getMinY(), aCubeRange
.getMinZ());
73 // get 3D Object Attributes
74 drawinglayer::attribute::Sdr3DObjectAttribute
* pSdr3DObjectAttribute
= drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet
);
76 // calculate texture size to get a perfect mapping for
77 // the front/back sides
78 const basegfx::B2DVector
aTextureSize(aCubeSize
.getX(), aCubeSize
.getY());
80 // create primitive and add
81 const drawinglayer::primitive3d::Primitive3DReference
xReference(
82 new drawinglayer::primitive3d::SdrCubePrimitive3D(
83 aWorldTransform
, aTextureSize
, aAttribute
, *pSdr3DObjectAttribute
));
84 xRetval
= drawinglayer::primitive3d::Primitive3DSequence(&xReference
, 1);
86 // delete 3D Object Attributes
87 delete pSdr3DObjectAttribute
;
91 } // end of namespace contact
92 } // end of namespace sdr
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */