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/viewcontactofe3d.hxx>
22 #include <svx/sdr/contact/viewobjectcontactofe3d.hxx>
23 #include <svx/obj3d.hxx>
24 #include <drawinglayer/primitive2d/embedded3dprimitive2d.hxx>
25 #include <svx/sdr/contact/viewcontactofe3dscene.hxx>
26 #include <svx/scene3d.hxx>
27 #include <drawinglayer/primitive3d/transformprimitive3d.hxx>
28 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
29 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
30 #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
31 #include <drawinglayer/attribute/sdrlineattribute.hxx>
33 //////////////////////////////////////////////////////////////////////////////
37 const sdr::contact::ViewContactOfE3dScene
* tryToFindVCOfE3DScene(
38 const sdr::contact::ViewContact
& rCandidate
,
39 basegfx::B3DHomMatrix
& o_rInBetweenObjectTransform
)
41 const sdr::contact::ViewContactOfE3dScene
* pSceneParent
=
42 dynamic_cast< const sdr::contact::ViewContactOfE3dScene
* >(rCandidate
.GetParentContact());
46 // each 3d object (including in-between scenes) should have a scene as parent
47 const sdr::contact::ViewContactOfE3dScene
* pSceneParentParent
=
48 dynamic_cast< const sdr::contact::ViewContactOfE3dScene
* >(pSceneParent
->GetParentContact());
50 if(pSceneParentParent
)
52 // the parent scene of rCandidate is a in-between scene, call recursively and collect
53 // the in-between scene's object transformation part in o_rInBetweenObjectTransform
54 const basegfx::B3DHomMatrix
& rSceneParentTransform
= pSceneParent
->GetE3dScene().GetTransform();
55 o_rInBetweenObjectTransform
= rSceneParentTransform
* o_rInBetweenObjectTransform
;
56 return tryToFindVCOfE3DScene(*pSceneParent
, o_rInBetweenObjectTransform
);
60 // the parent scene is the outmost scene
65 // object hierarchy structure is incorrect; no result
68 } // end of anonymous namespace
70 //////////////////////////////////////////////////////////////////////////////
76 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfE3d::impCreateWithGivenPrimitive3DSequence(
77 const drawinglayer::primitive3d::Primitive3DSequence
& rxContent3D
) const
79 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
81 if(rxContent3D
.hasElements())
83 // try to get the outmost ViewObjectContactOfE3dScene for this single 3d object,
84 // the ones on the way there are grouping scenes. Collect the in-between scene's
85 // transformations to build a correct object transformation for the embedded
87 basegfx::B3DHomMatrix aInBetweenObjectTransform
;
88 const ViewContactOfE3dScene
* pVCOfE3DScene
= tryToFindVCOfE3DScene(*this, aInBetweenObjectTransform
);
92 basegfx::B3DVector aLightNormal
;
93 const double fShadowSlant(pVCOfE3DScene
->getSdrSceneAttribute().getShadowSlant());
94 const basegfx::B3DRange
& rAllContentRange
= pVCOfE3DScene
->getAllContentRange3D();
95 drawinglayer::geometry::ViewInformation3D
aViewInformation3D(pVCOfE3DScene
->getViewInformation3D());
97 if(pVCOfE3DScene
->getSdrLightingAttribute().getLightVector().size())
99 // get light normal from first light and normalize
100 aLightNormal
= pVCOfE3DScene
->getSdrLightingAttribute().getLightVector()[0].getDirection();
101 aLightNormal
.normalize();
104 if(!aInBetweenObjectTransform
.isIdentity())
106 // if aInBetweenObjectTransform is used, create combined ViewInformation3D which
107 // contains the correct object transformation for the embedded 3d object
108 aViewInformation3D
= drawinglayer::geometry::ViewInformation3D(
109 aViewInformation3D
.getObjectTransformation() * aInBetweenObjectTransform
,
110 aViewInformation3D
.getOrientation(),
111 aViewInformation3D
.getProjection(),
112 aViewInformation3D
.getDeviceToView(),
113 aViewInformation3D
.getViewTime(),
114 aViewInformation3D
.getExtendedInformationSequence());
117 // create embedded 2d primitive and add. LightNormal and ShadowSlant are needed for evtl.
118 // 3D shadow extraction for correct B2DRange calculation (shadow is part of the object)
119 const drawinglayer::primitive2d::Primitive2DReference
xReference(
120 new drawinglayer::primitive2d::Embedded3DPrimitive2D(
122 pVCOfE3DScene
->getObjectTransformation(),
128 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
135 ViewContactOfE3d::ViewContactOfE3d(E3dObject
& rSdrObject
)
136 : ViewContactOfSdrObj(rSdrObject
)
140 ViewContactOfE3d::~ViewContactOfE3d()
144 drawinglayer::primitive3d::Primitive3DSequence
ViewContactOfE3d::getVIP3DSWithoutObjectTransform() const
146 // local up-to-date checks. Create new list and compare.
147 drawinglayer::primitive3d::Primitive3DSequence
xNew(createViewIndependentPrimitive3DSequence());
149 if(!drawinglayer::primitive3d::arePrimitive3DSequencesEqual(mxViewIndependentPrimitive3DSequence
, xNew
))
151 // has changed, copy content
152 const_cast< ViewContactOfE3d
* >(this)->mxViewIndependentPrimitive3DSequence
= xNew
;
155 // return current Primitive2DSequence
156 return mxViewIndependentPrimitive3DSequence
;
159 drawinglayer::primitive3d::Primitive3DSequence
ViewContactOfE3d::getViewIndependentPrimitive3DSequence() const
161 // get sequence without object transform
162 drawinglayer::primitive3d::Primitive3DSequence
xRetval(getVIP3DSWithoutObjectTransform());
164 if(xRetval
.hasElements())
166 // add object transform if it's used
167 const basegfx::B3DHomMatrix
& rObjectTransform(GetE3dObject().GetTransform());
169 if(!rObjectTransform
.isIdentity())
171 const drawinglayer::primitive3d::Primitive3DReference
xReference(
172 new drawinglayer::primitive3d::TransformPrimitive3D(
176 xRetval
= drawinglayer::primitive3d::Primitive3DSequence(&xReference
, 1);
180 // return current Primitive2DSequence
184 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfE3d::createViewIndependentPrimitive2DSequence() const
186 // also need to create a 2D embedding when the view-independent part is requested,
187 // see view-dependent part in ViewObjectContactOfE3d::createPrimitive2DSequence
188 // get 3d primitive vector, isPrimitiveVisible() is done in 3d creator
189 return impCreateWithGivenPrimitive3DSequence(getViewIndependentPrimitive3DSequence());
192 ViewObjectContact
& ViewContactOfE3d::CreateObjectSpecificViewObjectContact(ObjectContact
& rObjectContact
)
194 ViewObjectContact
* pRetval
= new ViewObjectContactOfE3d(rObjectContact
, *this);
195 DBG_ASSERT(pRetval
, "ViewContactOfE3d::CreateObjectSpecificViewObjectContact() failed (!)");
199 } // end of namespace contact
200 } // end of namespace sdr
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */