Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / tools / b3dtrans.hxx
blobeca70105b248bfe2609f1d3709ad219af0edf277
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #ifndef INCLUDED_TOOLS_B3DTRANS_HXX
21 #define INCLUDED_TOOLS_B3DTRANS_HXX
23 #define ZBUFFER_DEPTH_RANGE ((double)(256L * 256L * 256L))
25 #include <basegfx/matrix/b3dhommatrix.hxx>
26 #include <basegfx/range/b3drange.hxx>
27 #include <tools/gen.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <basegfx/point/b2dpoint.hxx>
30 #include <tools/toolsdllapi.h>
32 /// Transformation sets for 3D output
33 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC B3dTransformationSet
35 private:
36 // Object Matrix Object -> World
37 basegfx::B3DHomMatrix maObjectTrans;
38 basegfx::B3DHomMatrix maInvObjectTrans;
40 // Orientation Matrix
41 basegfx::B3DHomMatrix maOrientation;
42 basegfx::B3DHomMatrix maInvOrientation;
44 // Projection Matrix
45 basegfx::B3DHomMatrix maProjection;
46 basegfx::B3DHomMatrix maInvProjection;
48 // Texture Matrices
49 basegfx::B2DHomMatrix maTexture;
51 // Parameters for ViewportTransformation
52 basegfx::B3DVector maScale;
53 basegfx::B3DVector maTranslate;
55 // ViewPlane DeviceRectangle (user-defined)
56 double mfLeftBound;
57 double mfRightBound;
58 double mfBottomBound;
59 double mfTopBound;
61 // Near and far clipping planes
62 double mfNearBound;
63 double mfFarBound;
65 // Aspect ratio of 3D transformation (Y / X)
66 // default: 1:1 -> 1.0
67 // Disable with value 0.0
68 double mfRatio;
70 // Viewport area in logical coordinates
71 tools::Rectangle maViewportRectangle;
72 // Visible area within viewport
73 tools::Rectangle maVisibleRectangle;
75 // Actual coordinates as set by CalcViewport
76 // of visible viewport area (logical coordinates)
77 tools::Rectangle maSetBound;
79 // Flags
80 bool mbPerspective : 1;
81 bool mbProjectionValid : 1;
83 public:
84 B3dTransformationSet();
85 virtual ~B3dTransformationSet();
87 void Reset();
89 // Orientation
90 void SetOrientation(
91 const basegfx::B3DPoint& rVRP = basegfx::B3DPoint(0.0,0.0,1.0),
92 const basegfx::B3DVector& rVPN = basegfx::B3DVector(0.0,0.0,1.0),
93 const basegfx::B3DVector& rVUP = basegfx::B3DVector(0.0,1.0,0.0));
95 // Projection
96 void SetProjection(const basegfx::B3DHomMatrix& mProject);
97 const basegfx::B3DHomMatrix& GetProjection();
99 // Texture
101 // aspect ratio accessors and the defined method of keeping defined aspect ratio
102 double GetRatio() { return mfRatio; }
103 void SetRatio(double fNew);
105 // Parameters of ViewportTransformation
106 void SetDeviceRectangle(double fL=-1.0, double fR=1.0,
107 double fB=-1.0, double fT=1.0);
108 double GetDeviceRectangleWidth() const { return mfRightBound - mfLeftBound; }
110 void SetPerspective(bool bNew);
112 void SetViewportRectangle(tools::Rectangle const & rRect, tools::Rectangle const & rVisible);
113 void SetViewportRectangle(tools::Rectangle const & rRect) { SetViewportRectangle(rRect, rRect); }
115 void CalcViewport();
117 // Direct accessors for miscellaneous transformations
118 const basegfx::B3DPoint WorldToEyeCoor(const basegfx::B3DPoint& rVec);
119 const basegfx::B3DPoint EyeToWorldCoor(const basegfx::B3DPoint& rVec);
121 static void Frustum(
122 basegfx::B3DHomMatrix& rTarget,
123 double fLeft = -1.0, double fRight = 1.0,
124 double fBottom = -1.0, double fTop = 1.0,
125 double fNear = 0.001, double fFar = 1.0);
126 static void Ortho(
127 basegfx::B3DHomMatrix& rTarget,
128 double fLeft = -1.0, double fRight = 1.0,
129 double fBottom = -1.0, double fTop = 1.0,
130 double fNear = 0.0, double fFar = 1.0);
131 static void Orientation(
132 basegfx::B3DHomMatrix& rTarget,
133 const basegfx::B3DPoint& aVRP = basegfx::B3DPoint(0.0,0.0,1.0),
134 basegfx::B3DVector aVPN = basegfx::B3DVector(0.0,0.0,1.0),
135 basegfx::B3DVector aVUP = basegfx::B3DVector(0.0,1.0,0.0));
137 protected:
138 void PostSetObjectTrans();
139 void PostSetOrientation();
140 void PostSetProjection();
142 virtual void DeviceRectangleChange();
145 /** Viewport for B3D
147 Uses a simplified model, in which a point is described using a View
148 Reference Point (VRP).
150 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC B3dViewport : public B3dTransformationSet
152 private:
153 basegfx::B3DPoint aVRP; // View Reference Point
154 basegfx::B3DVector aVPN; // View Plane Normal
155 basegfx::B3DVector aVUV; // View Up Vector
157 public:
158 B3dViewport();
159 virtual ~B3dViewport() override;
161 void SetVUV(const basegfx::B3DVector& rNewVUV);
162 void SetViewportValues(
163 const basegfx::B3DPoint& rNewVRP,
164 const basegfx::B3DVector& rNewVPN,
165 const basegfx::B3DVector& rNewVUV);
167 const basegfx::B3DPoint& GetVRP() const { return aVRP; }
168 const basegfx::B3DVector& GetVPN() const { return aVPN; }
169 const basegfx::B3DVector& GetVUV() const { return aVUV; }
171 protected:
172 void CalcOrientation();
175 // B3D camera
177 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC B3dCamera : public B3dViewport
179 private:
180 basegfx::B3DPoint aPosition;
181 basegfx::B3DPoint aCorrectedPosition;
182 basegfx::B3DVector aLookAt;
183 double fFocalLength;
184 double fBankAngle;
186 public:
187 B3dCamera(
188 const basegfx::B3DPoint& rPos = basegfx::B3DPoint(0.0, 0.0, 1.0),
189 const basegfx::B3DVector& rLkAt = basegfx::B3DVector(0.0, 0.0, 0.0),
190 double fFocLen = 35.0, double fBnkAng = 0.0);
191 virtual ~B3dCamera() override;
193 protected:
194 void CalcNewViewportValues();
195 bool CalcFocalLength();
197 virtual void DeviceRectangleChange() override;
200 #endif
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */