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 .
20 #include <svx/viewpt3d.hxx>
22 Viewport3D::Viewport3D() :
27 eProjection(ProjectionType::Perspective
),
28 aDeviceRect(Point(0,0), Size(-1,-1)),
29 aViewPoint (0, 0, 5000),
32 aViewWin
.X
= -1; aViewWin
.Y
= -1;
33 aViewWin
.W
= 2; aViewWin
.H
= 2;
36 // Set ViewWindow (in View coordinates)
38 void Viewport3D::SetViewWindow(double fX
, double fY
, double fW
, double fH
)
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;
48 // Returns observer position (PRP) in world coordinates
50 const basegfx::B3DPoint
& Viewport3D::GetViewPoint()
52 // Calculate View transformations matrix
55 double fV
, fXupVp
, fYupVp
;
56 aViewPoint
= aVRP
+ aVPN
* aPRP
.getZ();
58 // Reset to Identity matrix
61 // shift in the origin
62 aViewTf
.translate(-aVRP
.getX(), -aVRP
.getY(), -aVRP
.getZ());
64 // fV = Length of the projection of aVPN on the yz plane:
65 fV
= aVPN
.getYZLength();
69 basegfx::B3DHomMatrix aTemp
;
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
);
80 basegfx::B3DHomMatrix aTemp
;
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
);
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
= sqrt(fXupVp
* fXupVp
+ fYupVp
* fYupVp
);
98 basegfx::B3DHomMatrix aTemp
;
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
);
113 void Viewport3D::SetDeviceWindow(const tools::Rectangle
& rRect
)
118 // Set View Reference Point
120 void Viewport3D::SetVRP(const basegfx::B3DPoint
& rNewVRP
)
126 // Set View Plane Normal
128 void Viewport3D::SetVPN(const basegfx::B3DVector
& rNewVPN
)
135 // Set View Up Vector
137 void Viewport3D::SetVUV(const basegfx::B3DVector
& rNewVUV
)
143 // Set Center Of Projection
145 void Viewport3D::SetPRP(const basegfx::B3DPoint
& rNewPRP
)
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */