/src/libreoffice/svx/source/sdr/contact/viewcontactofe3dcube.cxx
Line | Count | Source |
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 | | |
21 | | #include <sdr/contact/viewcontactofe3dcube.hxx> |
22 | | #include <svx/cube3d.hxx> |
23 | | #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx> |
24 | | #include <sdr/primitive2d/sdrattributecreator.hxx> |
25 | | #include <sdr/primitive3d/sdrattributecreator3d.hxx> |
26 | | #include <basegfx/range/b3drange.hxx> |
27 | | |
28 | | |
29 | | namespace sdr::contact |
30 | | { |
31 | | ViewContactOfE3dCube::ViewContactOfE3dCube(E3dCubeObj& rCubeObj) |
32 | 0 | : ViewContactOfE3d(rCubeObj) |
33 | 0 | { |
34 | 0 | } |
35 | | |
36 | | ViewContactOfE3dCube::~ViewContactOfE3dCube() |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | drawinglayer::primitive3d::Primitive3DContainer ViewContactOfE3dCube::createViewIndependentPrimitive3DContainer() const |
41 | 0 | { |
42 | 0 | drawinglayer::primitive3d::Primitive3DContainer xRetval; |
43 | 0 | const SfxItemSet& rItemSet = GetE3dCubeObj().GetMergedItemSet(); |
44 | 0 | const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute( |
45 | 0 | drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false)); |
46 | | |
47 | | // get cube geometry and use as translation and scaling for unit cube |
48 | 0 | basegfx::B3DRange aCubeRange; |
49 | 0 | const basegfx::B3DVector aCubeSize(GetE3dCubeObj().GetCubeSize()); |
50 | 0 | const basegfx::B3DPoint aCubePosition(GetE3dCubeObj().GetCubePos()); |
51 | 0 | basegfx::B3DHomMatrix aWorldTransform; |
52 | |
|
53 | 0 | if(GetE3dCubeObj().GetPosIsCenter()) |
54 | 0 | { |
55 | 0 | const basegfx::B3DVector aHalfCubeSize(aCubeSize / 2.0); |
56 | 0 | aCubeRange.expand(aCubePosition - aHalfCubeSize); |
57 | 0 | aCubeRange.expand(aCubePosition + aHalfCubeSize); |
58 | 0 | } |
59 | 0 | else |
60 | 0 | { |
61 | 0 | aCubeRange.expand(aCubePosition); |
62 | 0 | aCubeRange.expand(aCubePosition + aCubeSize); |
63 | 0 | } |
64 | | |
65 | | // add scale and translate to world transformation |
66 | 0 | const basegfx::B3DVector abjectRange(aCubeRange.getRange()); |
67 | 0 | aWorldTransform.scale(abjectRange.getX(), abjectRange.getY(), abjectRange.getZ()); |
68 | 0 | aWorldTransform.translate(aCubeRange.getMinX(), aCubeRange.getMinY(), aCubeRange.getMinZ()); |
69 | | |
70 | | // get 3D Object Attributes |
71 | 0 | drawinglayer::attribute::Sdr3DObjectAttribute aSdr3DObjectAttribute(drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet)); |
72 | | |
73 | | // calculate texture size to get a perfect mapping for |
74 | | // the front/back sides |
75 | 0 | const basegfx::B2DVector aTextureSize(aCubeSize.getX(), aCubeSize.getY()); |
76 | | |
77 | | // create primitive and add |
78 | 0 | const drawinglayer::primitive3d::Primitive3DReference xReference( |
79 | 0 | new drawinglayer::primitive3d::SdrCubePrimitive3D( |
80 | 0 | aWorldTransform, aTextureSize, aAttribute, aSdr3DObjectAttribute)); |
81 | 0 | xRetval = { xReference }; |
82 | |
|
83 | 0 | return xRetval; |
84 | 0 | } |
85 | | |
86 | | } // end of namespace |
87 | | |
88 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |