LibreOffice Module svx (master)  1
camera3d.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/camera3d.hxx>
21 
23  double fFocalLen) :
24  fBankAngle(0),
25  bAutoAdjustProjection(true)
26 {
27  SetPosition(rPos);
28  SetLookAt(rLookAt);
29  SetFocalLength(fFocalLen);
30 }
31 
33  : fFocalLength(35.0)
34  , fBankAngle(0.0)
35  , bAutoAdjustProjection(false)
36 {
37 }
38 
39 // Set ViewWindow and adjust PRP
40 
41 void Camera3D::SetViewWindow(double fX, double fY, double fW, double fH)
42 {
43  Viewport3D::SetViewWindow(fX, fY, fW, fH);
46 }
47 
49 {
50  if ( rNewPos != aPosition )
51  {
52  aPosition = rNewPos;
56  }
57 }
58 
59 void Camera3D::SetLookAt(const basegfx::B3DPoint& rNewLookAt)
60 {
61  if ( rNewLookAt != aLookAt )
62  {
63  aLookAt = rNewLookAt;
66  }
67 }
68 
70  const basegfx::B3DPoint& rNewLookAt)
71 {
72  if ( rNewPos != aPosition || rNewLookAt != aLookAt )
73  {
74  aPosition = rNewPos;
75  aLookAt = rNewLookAt;
76 
80  }
81 }
82 
83 void Camera3D::SetBankAngle(double fAngle)
84 {
86  basegfx::B3DVector aPrj(aDiff);
87  fBankAngle = fAngle;
88 
89  if ( aDiff.getY() == 0 )
90  {
91  aPrj.setY(-1.0);
92  }
93  else
94  { // aPrj = Projection from aDiff on the XZ-plane
95  aPrj.setY(0.0);
96 
97  if ( aDiff.getY() < 0.0 )
98  {
99  aPrj = -aPrj;
100  }
101  }
102 
103  // Calculate from aDiff to upwards pointing View-Up-Vector
104  // duplicated line is intentional!
105  aPrj = aPrj.getPerpendicular(aDiff);
106  aPrj = aPrj.getPerpendicular(aDiff);
107  aDiff.normalize();
108 
109  // Rotate on Z axis, to rotate the BankAngle and back
111  const double fV(sqrt(aDiff.getY() * aDiff.getY() + aDiff.getZ() * aDiff.getZ()));
112 
113  if ( fV != 0.0 )
114  {
115  basegfx::B3DHomMatrix aTemp;
116  const double fSin(aDiff.getY() / fV);
117  const double fCos(aDiff.getZ() / fV);
118 
119  aTemp.set(1, 1, fCos);
120  aTemp.set(2, 2, fCos);
121  aTemp.set(2, 1, fSin);
122  aTemp.set(1, 2, -fSin);
123 
124  aTf *= aTemp;
125  }
126 
127  {
128  basegfx::B3DHomMatrix aTemp;
129  const double fSin(-aDiff.getX());
130  const double fCos(fV);
131 
132  aTemp.set(0, 0, fCos);
133  aTemp.set(2, 2, fCos);
134  aTemp.set(0, 2, fSin);
135  aTemp.set(2, 0, -fSin);
136 
137  aTf *= aTemp;
138  }
139 
140  aTf.rotate(0.0, 0.0, fBankAngle);
141 
142  {
143  basegfx::B3DHomMatrix aTemp;
144  const double fSin(aDiff.getX());
145  const double fCos(fV);
146 
147  aTemp.set(0, 0, fCos);
148  aTemp.set(2, 2, fCos);
149  aTemp.set(0, 2, fSin);
150  aTemp.set(2, 0, -fSin);
151 
152  aTf *= aTemp;
153  }
154 
155  if ( fV != 0.0 )
156  {
157  basegfx::B3DHomMatrix aTemp;
158  const double fSin(-aDiff.getY() / fV);
159  const double fCos(aDiff.getZ() / fV);
160 
161  aTemp.set(1, 1, fCos);
162  aTemp.set(2, 2, fCos);
163  aTemp.set(2, 1, fSin);
164  aTemp.set(1, 2, -fSin);
165 
166  aTf *= aTemp;
167  }
168 
169  SetVUV(aTf * aPrj);
170 }
171 
172 void Camera3D::SetFocalLength(double fLen)
173 {
174  if ( fLen < 5 )
175  fLen = 5;
176  SetPRP(basegfx::B3DPoint(0.0, 0.0, fLen / 35.0 * aViewWin.W));
177  fFocalLength = fLen;
178 }
179 
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetViewWindow(double fX, double fY, double fW, double fH)
Definition: camera3d.cxx:41
B3DVector & normalize()
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void SetVUV(const basegfx::B3DVector &rNewVUV)
Definition: viewpt3d2.cxx:137
void SetViewWindow(double fX, double fY, double fW, double fH)
Definition: viewpt3d2.cxx:38
basegfx::B3DPoint aLookAt
Definition: camera3d.hxx:37
void SetLookAt(const basegfx::B3DPoint &rNewLookAt)
Definition: camera3d.cxx:59
B3DVector getPerpendicular(const B3DVector &rNormalizedVec) const
void SetFocalLength(double fLen)
Definition: camera3d.cxx:172
void SetBankAngle(double fAngle)
Definition: camera3d.cxx:83
Camera3D()
Definition: camera3d.cxx:32
void SetVRP(const basegfx::B3DPoint &rNewVRP)
Definition: viewpt3d2.cxx:120
double fBankAngle
Definition: camera3d.hxx:39
double fFocalLength
Definition: camera3d.hxx:38
void SetPosAndLookAt(const basegfx::B3DPoint &rNewPos, const basegfx::B3DPoint &rNewLookAt)
Definition: camera3d.cxx:69
struct Viewport3D::@5 aViewWin
void SetVPN(const basegfx::B3DVector &rNewVPN)
Definition: viewpt3d2.cxx:128
void rotate(double fAngleX, double fAngleY, double fAngleZ)
void SetPRP(const basegfx::B3DPoint &rNewPRP)
Definition: viewpt3d2.cxx:145
bool bAutoAdjustProjection
Definition: camera3d.hxx:41
void SetPosition(const basegfx::B3DPoint &rNewPos)
Definition: camera3d.cxx:48
basegfx::B3DPoint aPosition
Definition: camera3d.hxx:36