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 #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
36 // Object Matrix Object -> World
37 basegfx::B3DHomMatrix maObjectTrans
;
38 basegfx::B3DHomMatrix maInvObjectTrans
;
41 basegfx::B3DHomMatrix maOrientation
;
42 basegfx::B3DHomMatrix maInvOrientation
;
45 basegfx::B3DHomMatrix maProjection
;
46 basegfx::B3DHomMatrix maInvProjection
;
49 basegfx::B2DHomMatrix maTexture
;
51 // Parameters for ViewportTransformation
52 basegfx::B3DVector maScale
;
53 basegfx::B3DVector maTranslate
;
55 // ViewPlane DeviceRectangle (user-defined)
61 // Near and far clipping planes
65 // Aspect ratio of 3D transformation (Y / X)
66 // default: 1:1 -> 1.0
67 // Disable with value 0.0
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
;
80 bool mbPerspective
: 1;
81 bool mbProjectionValid
: 1;
84 B3dTransformationSet();
85 virtual ~B3dTransformationSet();
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));
96 void SetProjection(const basegfx::B3DHomMatrix
& mProject
);
97 const basegfx::B3DHomMatrix
& GetProjection();
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
); }
117 // Direct accessors for miscellaneous transformations
118 const basegfx::B3DPoint
WorldToEyeCoor(const basegfx::B3DPoint
& rVec
);
119 const basegfx::B3DPoint
EyeToWorldCoor(const basegfx::B3DPoint
& rVec
);
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);
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));
138 void PostSetObjectTrans();
139 void PostSetOrientation();
140 void PostSetProjection();
142 virtual void DeviceRectangleChange();
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
153 basegfx::B3DPoint aVRP
; // View Reference Point
154 basegfx::B3DVector aVPN
; // View Plane Normal
155 basegfx::B3DVector aVUV
; // View Up Vector
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
; }
172 void CalcOrientation();
177 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC B3dCamera
: public B3dViewport
180 basegfx::B3DPoint aPosition
;
181 basegfx::B3DPoint aCorrectedPosition
;
182 basegfx::B3DVector aLookAt
;
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
;
194 void CalcNewViewportValues();
195 bool CalcFocalLength();
197 virtual void DeviceRectangleChange() override
;
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */