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