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 /// Supported methods for setting the aspect ratio
40 /// Supported projection types
41 enum Base3DProjectionType
43 Base3DProjectionTypeParallel
= 1,
44 Base3DProjectionTypePerspective
47 /// Transformation sets for 3D output
48 class TOOLS_DLLPUBLIC B3dTransformationSet
51 // Object Matrix Object -> World
52 basegfx::B3DHomMatrix maObjectTrans
;
53 basegfx::B3DHomMatrix maInvObjectTrans
;
56 basegfx::B3DHomMatrix maOrientation
;
57 basegfx::B3DHomMatrix maInvOrientation
;
60 basegfx::B3DHomMatrix maProjection
;
61 basegfx::B3DHomMatrix maInvProjection
;
64 basegfx::B2DHomMatrix maTexture
;
66 // Special transformation set for converting Object -> Device
67 basegfx::B3DHomMatrix maObjectToDevice
;
69 // Transposed and inversed matrix for vector transformations
70 basegfx::B3DHomMatrix maInvTransObjectToEye
;
72 // Transformation for World->View
73 basegfx::B3DHomMatrix maMatFromWorldToView
;
74 basegfx::B3DHomMatrix maInvMatFromWorldToView
;
76 // Parameters for ViewportTransformation
77 basegfx::B3DVector maScale
;
78 basegfx::B3DVector maTranslate
;
80 // ViewPlane DeviceRectangle (user-defined)
86 // Near and far clipping planes
90 // Aspect ratio of 3D transformation (Y / X)
91 // default: 1:1 -> 1.0
92 // Disable with value 0.0
95 // Viewport area in logical coordinates
96 Rectangle maViewportRectangle
;
97 // Visible area within viewport
98 Rectangle maVisibleRectangle
;
100 // Actual coordinates as set by CalcViewport
101 // of visible viewport area (logical coordinates)
102 Rectangle maSetBound
;
104 // Method of keeping defined aspect ratio
105 // default: Base3DRatioGrow
109 bool mbPerspective
: 1;
110 bool mbWorldToViewValid
: 1;
111 bool mbInvTransObjectToEyeValid
: 1;
112 bool mbObjectToDeviceValid
: 1;
113 bool mbProjectionValid
: 1;
116 B3dTransformationSet();
117 virtual ~B3dTransformationSet();
122 const basegfx::B3DHomMatrix
& GetObjectTrans() { return maObjectTrans
; }
123 const basegfx::B3DHomMatrix
& GetInvObjectTrans() { return maInvObjectTrans
; }
127 const basegfx::B3DPoint
& rVRP
= basegfx::B3DPoint(0.0,0.0,1.0),
128 const basegfx::B3DVector
& rVPN
= basegfx::B3DVector(0.0,0.0,1.0),
129 const basegfx::B3DVector
& rVUP
= basegfx::B3DVector(0.0,1.0,0.0));
130 const basegfx::B3DHomMatrix
& GetOrientation() { return maOrientation
; }
131 const basegfx::B3DHomMatrix
& GetInvOrientation() { return maInvOrientation
; }
134 void SetProjection(const basegfx::B3DHomMatrix
& mProject
);
135 const basegfx::B3DHomMatrix
& GetProjection();
138 const basegfx::B2DHomMatrix
& GetTexture() { return maTexture
; }
140 // aspect ratio accessors and the defined method of keeping defined aspect ratio
141 double GetRatio() { return mfRatio
; }
142 void SetRatio(double fNew
=1.0);
143 Base3DRatio
GetRatioMode() { return meRatio
; }
145 // Parameters of ViewportTransformation
146 void SetDeviceRectangle(double fL
=-1.0, double fR
=1.0,
147 double fB
=-1.0, double fT
=1.0,
148 bool bBroadCastChange
=true);
149 double GetDeviceRectangleWidth() const { return mfRightBound
- mfLeftBound
; }
150 double GetDeviceRectangleHeight() const { return mfTopBound
- mfBottomBound
; }
151 double GetFrontClippingPlane() { return mfNearBound
; }
152 double GetBackClippingPlane() { return mfFarBound
; }
153 void SetPerspective(bool bNew
);
154 bool GetPerspective() { return mbPerspective
; }
155 void SetViewportRectangle(Rectangle
& rRect
, Rectangle
& rVisible
);
156 void SetViewportRectangle(Rectangle
& rRect
) { SetViewportRectangle(rRect
, rRect
); }
157 const Rectangle
& GetViewportRectangle() { return maViewportRectangle
; }
160 // Direct accessors for miscellaneous transformations
161 const basegfx::B3DPoint
WorldToEyeCoor(const basegfx::B3DPoint
& rVec
);
162 const basegfx::B3DPoint
EyeToWorldCoor(const basegfx::B3DPoint
& rVec
);
165 basegfx::B3DHomMatrix
& rTarget
,
166 double fLeft
= -1.0, double fRight
= 1.0,
167 double fBottom
= -1.0, double fTop
= 1.0,
168 double fNear
= 0.001, double fFar
= 1.0);
170 basegfx::B3DHomMatrix
& rTarget
,
171 double fLeft
= -1.0, double fRight
= 1.0,
172 double fBottom
= -1.0, double fTop
= 1.0,
173 double fNear
= 0.0, double fFar
= 1.0);
174 static void Orientation(
175 basegfx::B3DHomMatrix
& rTarget
,
176 basegfx::B3DPoint aVRP
= basegfx::B3DPoint(0.0,0.0,1.0),
177 basegfx::B3DVector aVPN
= basegfx::B3DVector(0.0,0.0,1.0),
178 basegfx::B3DVector aVUP
= basegfx::B3DVector(0.0,1.0,0.0));
181 void PostSetObjectTrans();
182 void PostSetOrientation();
183 void PostSetProjection();
185 virtual void DeviceRectangleChange();
190 Uses a simplified model, in which a point is described using a View
191 Reference Point (VRP).
193 class TOOLS_DLLPUBLIC B3dViewport
: public B3dTransformationSet
196 basegfx::B3DPoint aVRP
; // View Reference Point
197 basegfx::B3DVector aVPN
; // View Plane Normal
198 basegfx::B3DVector aVUV
; // View Up Vector
202 virtual ~B3dViewport();
204 void SetVUV(const basegfx::B3DVector
& rNewVUV
);
205 void SetViewportValues(
206 const basegfx::B3DPoint
& rNewVRP
,
207 const basegfx::B3DVector
& rNewVPN
,
208 const basegfx::B3DVector
& rNewVUV
);
210 const basegfx::B3DPoint
& GetVRP() const { return aVRP
; }
211 const basegfx::B3DVector
& GetVPN() const { return aVPN
; }
212 const basegfx::B3DVector
& GetVUV() const { return aVUV
; }
215 void CalcOrientation();
220 class TOOLS_DLLPUBLIC B3dCamera
: public B3dViewport
223 basegfx::B3DPoint aPosition
;
224 basegfx::B3DPoint aCorrectedPosition
;
225 basegfx::B3DVector aLookAt
;
229 bool bUseFocalLength
: 1;
233 const basegfx::B3DPoint
& rPos
= basegfx::B3DPoint(0.0, 0.0, 1.0),
234 const basegfx::B3DVector
& rLkAt
= basegfx::B3DVector(0.0, 0.0, 0.0),
235 double fFocLen
= 35.0, double fBnkAng
= 0.0,
236 bool bUseFocLen
= false);
237 virtual ~B3dCamera();
239 const basegfx::B3DPoint
& GetPosition() const { return aPosition
; }
240 const basegfx::B3DVector
& GetLookAt() const { return aLookAt
; }
242 // Focal length in mm
243 double GetFocalLength() const { return fFocalLength
; }
245 double GetBankAngle() const { return fBankAngle
; }
247 bool GetUseFocalLength() const { return (bool)bUseFocalLength
; }
250 void CalcNewViewportValues();
251 bool CalcFocalLength();
253 virtual void DeviceRectangleChange() SAL_OVERRIDE
;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */