LibreOffice Module svx (master) 1
viewpt3d2.cxx
Go to the documentation of this file.
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#include <svx/viewpt3d.hxx>
21
23 aVRP(0, 0, 5),
24 aVPN(0, 0, 1),
25 aVUV(0, 1, 1),
26 aPRP(0, 0, 2),
27 eProjection(ProjectionType::Perspective),
28 aDeviceRect(Point(0,0), Size(-1,-1)),
29 aViewPoint (0, 0, 5000),
30 bTfValid(false)
31{
32 aViewWin.X = -1; aViewWin.Y = -1;
33 aViewWin.W = 2; aViewWin.H = 2;
34}
35
36// Set ViewWindow (in View coordinates)
37
38void Viewport3D::SetViewWindow(double fX, double fY, double fW, double fH)
39{
40 aViewWin.X = fX;
41 aViewWin.Y = fY;
42 if ( fW > 0 ) aViewWin.W = fW;
43 else aViewWin.W = 1.0;
44 if ( fH > 0 ) aViewWin.H = fH;
45 else aViewWin.H = 1.0;
46}
47
48// Returns observer position (PRP) in world coordinates
49
51{
52 // Calculate View transformations matrix
53 if ( !bTfValid )
54 {
55 double fV, fXupVp, fYupVp;
57
58 // Reset to Identity matrix
60
61 // shift in the origin
63
64 // fV = Length of the projection of aVPN on the yz plane:
65 fV = aVPN.getYZLength();
66
67 if ( fV != 0 )
68 {
70 const double fSin(aVPN.getY() / fV);
71 const double fCos(aVPN.getZ() / fV);
72 aTemp.set(2, 2, fCos);
73 aTemp.set(1, 1, fCos);
74 aTemp.set(2, 1, fSin);
75 aTemp.set(1, 2, -fSin);
76 aViewTf *= aTemp;
77 }
78
79 {
81 const double fSin(-aVPN.getX());
82 const double fCos(fV);
83 aTemp.set(2, 2, fCos);
84 aTemp.set(0, 0, fCos);
85 aTemp.set(0, 2, fSin);
86 aTemp.set(2, 0, -fSin);
87 aViewTf *= aTemp;
88 }
89
90 // Convert X- and Y- coordinates of the view up vector to the
91 // (preliminary) view coordinate system.
92 fXupVp = aViewTf.get(0, 0) * aVUV.getX() + aViewTf.get(0, 1) * aVUV.getY() + aViewTf.get(0, 2) * aVUV.getZ();
93 fYupVp = aViewTf.get(1, 0) * aVUV.getX() + aViewTf.get(1, 1) * aVUV.getY() + aViewTf.get(1, 2) * aVUV.getZ();
94 fV = std::hypot(fXupVp, fYupVp);
95
96 if ( fV != 0 )
97 {
99 const double fSin(fXupVp / fV);
100 const double fCos(fYupVp / fV);
101 aTemp.set(1, 1, fCos);
102 aTemp.set(0, 0, fCos);
103 aTemp.set(1, 0, fSin);
104 aTemp.set(0, 1, -fSin);
105 aViewTf *= aTemp;
106 }
107
108 bTfValid = true;
109 }
110 return aViewPoint;
111}
112
114{
115 aDeviceRect = rRect;
116}
117
118// Set View Reference Point
119
121{
122 aVRP = rNewVRP;
123 bTfValid = false;
124}
125
126// Set View Plane Normal
127
129{
130 aVPN = rNewVPN;
131 aVPN.normalize();
132 bTfValid = false;
133}
134
135// Set View Up Vector
136
138{
139 aVUV = rNewVUV;
140 bTfValid = false;
141}
142
143// Set Center Of Projection
144
146{
147 aPRP = rNewPRP;
148 aPRP.setX(0.0);
149 aPRP.setY(0.0);
150 bTfValid = false;
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct Viewport3D::@7 aViewWin
basegfx::B3DPoint aPRP
Definition: viewpt3d.hxx:54
basegfx::B3DPoint aVRP
Definition: viewpt3d.hxx:51
basegfx::B3DPoint aViewPoint
Definition: viewpt3d.hxx:65
void SetDeviceWindow(const tools::Rectangle &rRect)
Definition: viewpt3d2.cxx:113
void SetPRP(const basegfx::B3DPoint &rNewPRP)
Definition: viewpt3d2.cxx:145
void SetViewWindow(double fX, double fY, double fW, double fH)
Definition: viewpt3d2.cxx:38
basegfx::B3DHomMatrix aViewTf
Definition: viewpt3d.hxx:50
void SetVPN(const basegfx::B3DVector &rNewVPN)
Definition: viewpt3d2.cxx:128
basegfx::B3DVector aVPN
Definition: viewpt3d.hxx:52
bool bTfValid
Definition: viewpt3d.hxx:67
void SetVUV(const basegfx::B3DVector &rNewVUV)
Definition: viewpt3d2.cxx:137
const basegfx::B3DPoint & GetViewPoint()
Definition: viewpt3d2.cxx:50
basegfx::B3DVector aVUV
Definition: viewpt3d.hxx:53
void SetVRP(const basegfx::B3DPoint &rNewVRP)
Definition: viewpt3d2.cxx:120
tools::Rectangle aDeviceRect
Definition: viewpt3d.hxx:58
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
void translate(double fX, double fY, double fZ)
double getYZLength() const
B3DVector & normalize()
void setX(TYPE fX)
TYPE getX() const
TYPE getZ() const
TYPE getY() const
void setY(TYPE fY)
ProjectionType
Definition: viewpt3d.hxx:38