Line data Source code
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 : #ifndef _B3D_B3DTRANS_HXX
21 : #define _B3D_B3DTRANS_HXX
22 :
23 : #define ZBUFFER_DEPTH_RANGE ((double)(256L * 256L * 256L))
24 :
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>
31 :
32 : /// Supported methods for setting the aspect ratio
33 : enum Base3DRatio
34 : {
35 : Base3DRatioGrow = 1,
36 : Base3DRatioShrink,
37 : Base3DRatioMiddle
38 : };
39 :
40 : /// Supported projection types
41 : enum Base3DProjectionType
42 : {
43 : Base3DProjectionTypeParallel = 1,
44 : Base3DProjectionTypePerspective
45 : };
46 :
47 : /// Transformation sets for 3D output
48 0 : class TOOLS_DLLPUBLIC B3dTransformationSet
49 : {
50 : private:
51 : // Object Matrix Object -> World
52 : basegfx::B3DHomMatrix maObjectTrans;
53 : basegfx::B3DHomMatrix maInvObjectTrans;
54 :
55 : // Orientation Matrix
56 : basegfx::B3DHomMatrix maOrientation;
57 : basegfx::B3DHomMatrix maInvOrientation;
58 :
59 : // Projection Matrix
60 : basegfx::B3DHomMatrix maProjection;
61 : basegfx::B3DHomMatrix maInvProjection;
62 :
63 : // Texture Matrices
64 : basegfx::B2DHomMatrix maTexture;
65 :
66 : // Special transformation set for converting Object -> Device
67 : basegfx::B3DHomMatrix maObjectToDevice;
68 :
69 : // Transposed and inversed matrix for vector transformations
70 : basegfx::B3DHomMatrix maInvTransObjectToEye;
71 :
72 : // Transformation for World->View
73 : basegfx::B3DHomMatrix maMatFromWorldToView;
74 : basegfx::B3DHomMatrix maInvMatFromWorldToView;
75 :
76 : // Parameters for ViewportTransformation
77 : basegfx::B3DVector maScale;
78 : basegfx::B3DVector maTranslate;
79 :
80 : // ViewPlane DeviceRectangle (user-defined)
81 : double mfLeftBound;
82 : double mfRightBound;
83 : double mfBottomBound;
84 : double mfTopBound;
85 :
86 : // Near and far clipping planes
87 : double mfNearBound;
88 : double mfFarBound;
89 :
90 : // Aspect ratio of 3D transformation (Y / X)
91 : // default: 1:1 -> 1.0
92 : // Disable with value 0.0
93 : double mfRatio;
94 :
95 : // Viewport area in logical coordinates
96 : Rectangle maViewportRectangle;
97 : // Visible area within viewport
98 : Rectangle maVisibleRectangle;
99 :
100 : // Actual coordinates as set by CalcViewport
101 : // of visible viewport area (logical coordinates)
102 : Rectangle maSetBound;
103 :
104 : // Method of keeping defined aspect ratio
105 : // default: Base3DRatioGrow
106 : Base3DRatio meRatio;
107 :
108 : // Flags
109 : bool mbPerspective : 1;
110 : bool mbWorldToViewValid : 1;
111 : bool mbInvTransObjectToEyeValid : 1;
112 : bool mbObjectToDeviceValid : 1;
113 : bool mbProjectionValid : 1;
114 :
115 : public:
116 : B3dTransformationSet();
117 : virtual ~B3dTransformationSet();
118 :
119 : void Reset();
120 :
121 : // ObjectTrans
122 : const basegfx::B3DHomMatrix& GetObjectTrans() { return maObjectTrans; }
123 : const basegfx::B3DHomMatrix& GetInvObjectTrans() { return maInvObjectTrans; }
124 :
125 : // Orientation
126 : void SetOrientation(
127 : basegfx::B3DPoint aVRP = basegfx::B3DPoint(0.0,0.0,1.0),
128 : basegfx::B3DVector aVPN = basegfx::B3DVector(0.0,0.0,1.0),
129 : basegfx::B3DVector aVUP = basegfx::B3DVector(0.0,1.0,0.0));
130 816 : const basegfx::B3DHomMatrix& GetOrientation() { return maOrientation; }
131 0 : const basegfx::B3DHomMatrix& GetInvOrientation() { return maInvOrientation; }
132 :
133 : // Projection
134 : void SetProjection(const basegfx::B3DHomMatrix& mProject);
135 : const basegfx::B3DHomMatrix& GetProjection();
136 :
137 : // Texture
138 : const basegfx::B2DHomMatrix& GetTexture() { return maTexture; }
139 :
140 : // aspect ratio accessors and the defined method of keeping defined aspect ratio
141 408 : double GetRatio() { return mfRatio; }
142 : void SetRatio(double fNew=1.0);
143 : Base3DRatio GetRatioMode() { return meRatio; }
144 :
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 816 : 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 1733 : void SetViewportRectangle(Rectangle& rRect) { SetViewportRectangle(rRect, rRect); }
157 : const Rectangle& GetViewportRectangle() { return maViewportRectangle; }
158 : void CalcViewport();
159 :
160 : // Direct accessors for miscellaneous transformations
161 : const basegfx::B3DPoint WorldToEyeCoor(const basegfx::B3DPoint& rVec);
162 : const basegfx::B3DPoint EyeToWorldCoor(const basegfx::B3DPoint& rVec);
163 :
164 : static void Frustum(
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);
169 : static void Ortho(
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));
179 :
180 : protected:
181 : void PostSetObjectTrans();
182 : void PostSetOrientation();
183 : void PostSetProjection();
184 : void PostSetViewport();
185 :
186 : virtual void DeviceRectangleChange();
187 : };
188 :
189 : /** Viewport for B3D
190 :
191 : Uses a simplified model, in which a point is described using a View
192 : Reference Point (VRP).
193 : */
194 0 : class TOOLS_DLLPUBLIC B3dViewport : public B3dTransformationSet
195 : {
196 : private:
197 : basegfx::B3DPoint aVRP; // View Reference Point
198 : basegfx::B3DVector aVPN; // View Plane Normal
199 : basegfx::B3DVector aVUV; // View Up Vector
200 :
201 : public:
202 : B3dViewport();
203 : virtual ~B3dViewport();
204 :
205 : void SetVUV(const basegfx::B3DVector& rNewVUV);
206 : void SetViewportValues(
207 : const basegfx::B3DPoint& rNewVRP,
208 : const basegfx::B3DVector& rNewVPN,
209 : const basegfx::B3DVector& rNewVUV);
210 :
211 622 : const basegfx::B3DPoint& GetVRP() const { return aVRP; }
212 0 : const basegfx::B3DVector& GetVPN() const { return aVPN; }
213 311 : const basegfx::B3DVector& GetVUV() const { return aVUV; }
214 :
215 : protected:
216 : void CalcOrientation();
217 : };
218 :
219 : // B3D camera
220 :
221 0 : class TOOLS_DLLPUBLIC B3dCamera : public B3dViewport
222 : {
223 : private:
224 : basegfx::B3DPoint aPosition;
225 : basegfx::B3DPoint aCorrectedPosition;
226 : basegfx::B3DVector aLookAt;
227 : double fFocalLength;
228 : double fBankAngle;
229 :
230 : unsigned bUseFocalLength : 1;
231 :
232 : public:
233 : B3dCamera(
234 : const basegfx::B3DPoint& rPos = basegfx::B3DPoint(0.0, 0.0, 1.0),
235 : const basegfx::B3DVector& rLkAt = basegfx::B3DVector(0.0, 0.0, 0.0),
236 : double fFocLen = 35.0, double fBnkAng = 0.0,
237 : bool bUseFocLen = false);
238 : virtual ~B3dCamera();
239 :
240 : const basegfx::B3DPoint& GetPosition() const { return aPosition; }
241 : const basegfx::B3DVector& GetLookAt() const { return aLookAt; }
242 :
243 : // Focal length in mm
244 : double GetFocalLength() const { return fFocalLength; }
245 :
246 : double GetBankAngle() const { return fBankAngle; }
247 :
248 : bool GetUseFocalLength() const { return (bool)bUseFocalLength; }
249 :
250 : protected:
251 : void CalcNewViewportValues();
252 : bool CalcFocalLength();
253 :
254 : virtual void DeviceRectangleChange();
255 : };
256 :
257 : #endif
258 :
259 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|