sync master with lastest vba changes
[ooovba.git] / goodies / inc / b3dtrans.hxx
blob570a5b57af2b9bbb4c269e8aee663185c2a64a97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: b3dtrans.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _B3D_B3DTRANS_HXX
32 #define _B3D_B3DTRANS_HXX
34 // Zu verwendender DephRange des Z-Buffers
35 #define ZBUFFER_DEPTH_RANGE ((double)(256L * 256L * 256L))
37 #include <basegfx/matrix/b3dhommatrix.hxx>
38 #include <basegfx/range/b3drange.hxx>
39 #include <tools/gen.hxx>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
41 #include <basegfx/point/b2dpoint.hxx>
43 // Vorausdeklarationen
45 /*************************************************************************
47 |* Unterstuetzte Methoden, um das Seitenverhaeltnis einzuhalten
49 \************************************************************************/
51 enum Base3DRatio
53 Base3DRatioGrow = 1,
54 Base3DRatioShrink,
55 Base3DRatioMiddle
58 /*************************************************************************
60 |* Typ der Projektion
62 \************************************************************************/
64 enum Base3DProjectionType
66 Base3DProjectionTypeParallel = 1,
67 Base3DProjectionTypePerspective
70 /*************************************************************************
72 |* Transformationen fuer alle 3D Ausgaben
74 \************************************************************************/
76 class B3dTransformationSet
78 private:
79 // Object Matrix Object -> World
80 basegfx::B3DHomMatrix maObjectTrans;
81 basegfx::B3DHomMatrix maInvObjectTrans;
83 // Orientation Matrix
84 basegfx::B3DHomMatrix maOrientation;
85 basegfx::B3DHomMatrix maInvOrientation;
87 // Projection Matrix
88 basegfx::B3DHomMatrix maProjection;
89 basegfx::B3DHomMatrix maInvProjection;
91 // Texture Matrices
92 basegfx::B2DHomMatrix maTexture;
94 // Speziell zum Umwandeln von Punkten Objekt -> Device
95 basegfx::B3DHomMatrix maObjectToDevice;
97 // Transponierte Inverse fuer Vectortransformationen
98 basegfx::B3DHomMatrix maInvTransObjectToEye;
100 // Transformation World->View
101 basegfx::B3DHomMatrix maMatFromWorldToView;
102 basegfx::B3DHomMatrix maInvMatFromWorldToView;
104 // Parameters for ViewportTransformation
105 basegfx::B3DVector maScale;
106 basegfx::B3DVector maTranslate;
108 // ViewPlane DeviceRectangle (vom Benutzer gesetzt)
109 double mfLeftBound;
110 double mfRightBound;
111 double mfBottomBound;
112 double mfTopBound;
114 // Near and far clipping planes
115 double mfNearBound;
116 double mfFarBound;
118 // Seitenverhaeltnis der 3D Abbildung (Y / X)
119 // default ist 1:1 -> 1.0
120 // Deaktivieren mit 0.0 als Wert
121 double mfRatio;
123 // Der gesetzte Ausgabebereich (in logischen Koordinaten)
124 // und der dazugehoerige sichtbare Bereich
125 Rectangle maViewportRectangle;
126 Rectangle maVisibleRectangle;
128 // Die tatsaechlich von CalcViewport gesetzten Abmessungen
129 // des sichtbaren Bereichs (in logischen Koordinaten)
130 Rectangle maSetBound;
132 // Methode zur Aufrechterhaltung des Seitenverhaeltnisses
133 // default ist Base3DRatioGrow
134 Base3DRatio meRatio;
136 // Flags
137 unsigned mbPerspective : 1;
138 unsigned mbWorldToViewValid : 1;
139 unsigned mbInvTransObjectToEyeValid : 1;
140 unsigned mbObjectToDeviceValid : 1;
141 unsigned mbProjectionValid : 1;
143 public:
144 B3dTransformationSet();
145 virtual ~B3dTransformationSet();
147 // Zurueck auf Standard
148 void Reset();
150 // ObjectTrans
151 void SetObjectTrans(const basegfx::B3DHomMatrix& rObj);
152 const basegfx::B3DHomMatrix& GetObjectTrans() { return maObjectTrans; }
153 const basegfx::B3DHomMatrix& GetInvObjectTrans() { return maInvObjectTrans; }
155 // Orientation
156 void SetOrientation(
157 basegfx::B3DPoint aVRP = basegfx::B3DPoint(0.0,0.0,1.0),
158 basegfx::B3DVector aVPN = basegfx::B3DVector(0.0,0.0,1.0),
159 basegfx::B3DVector aVUP = basegfx::B3DVector(0.0,1.0,0.0));
160 void SetOrientation(basegfx::B3DHomMatrix& mOrient);
161 const basegfx::B3DHomMatrix& GetOrientation() { return maOrientation; }
162 const basegfx::B3DHomMatrix& GetInvOrientation() { return maInvOrientation; }
164 // Projection
165 void SetProjection(const basegfx::B3DHomMatrix& mProject);
166 const basegfx::B3DHomMatrix& GetProjection();
167 const basegfx::B3DHomMatrix& GetInvProjection();
169 // Texture
170 void SetTexture(const basegfx::B2DHomMatrix& rTxt);
171 const basegfx::B2DHomMatrix& GetTexture() { return maTexture; }
173 // Seitenverhaeltnis und Modus zu dessen Aufrechterhaltung
174 double GetRatio() { return mfRatio; }
175 void SetRatio(double fNew=1.0);
176 Base3DRatio GetRatioMode() { return meRatio; }
177 void SetRatioMode(Base3DRatio eNew=Base3DRatioGrow);
179 // Parameter der ViewportTransformation
180 void SetDeviceRectangle(double fL=-1.0, double fR=1.0, double fB=-1.0, double fT=1.0, sal_Bool bBroadCastChange=sal_True);
181 void SetDeviceVolume(const basegfx::B3DRange& rVol, sal_Bool bBroadCastChange=sal_True);
182 void GetDeviceRectangle(double &fL, double &fR, double& fB, double& fT);
183 basegfx::B3DRange GetDeviceVolume();
184 double GetDeviceRectangleWidth() const { return mfRightBound - mfLeftBound; }
185 double GetDeviceRectangleHeight() const { return mfTopBound - mfBottomBound; }
186 void SetFrontClippingPlane(double fF=0.0);
187 double GetFrontClippingPlane() { return mfNearBound; }
188 void SetBackClippingPlane(double fB=1.0);
189 double GetBackClippingPlane() { return mfFarBound; }
190 void SetPerspective(sal_Bool bNew);
191 sal_Bool GetPerspective() { return mbPerspective; }
192 void SetViewportRectangle(Rectangle& rRect, Rectangle& rVisible);
193 void SetViewportRectangle(Rectangle& rRect) { SetViewportRectangle(rRect, rRect); }
194 const Rectangle& GetViewportRectangle() { return maViewportRectangle; }
195 void CalcViewport();
197 // Spezielle Matritzen anfordern
198 basegfx::B3DHomMatrix GetMatFromObjectToView();
200 // Transponierte Inverse fuer Vectortransformationen
201 const basegfx::B3DHomMatrix& GetInvTransObjectToEye();
203 // Speziell zum Umwandeln von Punkten Objekt -> Device
204 const basegfx::B3DHomMatrix& GetObjectToDevice();
206 // Speziell zum Umwandeln von Punkten World -> View
207 const basegfx::B3DHomMatrix& GetMatFromWorldToView();
208 const basegfx::B3DHomMatrix& GetInvMatFromWorldToView();
210 // Bounds des Viewports lesen
211 const Rectangle& GetLogicalViewportBounds();
212 const basegfx::B3DVector& GetScale();
213 const basegfx::B3DVector& GetTranslate();
215 // Direkter Zugriff auf verschiedene Transformationen
216 const basegfx::B3DPoint WorldToEyeCoor(const basegfx::B3DPoint& rVec);
217 const basegfx::B3DPoint EyeToWorldCoor(const basegfx::B3DPoint& rVec);
218 const basegfx::B3DPoint EyeToViewCoor(const basegfx::B3DPoint& rVec);
219 const basegfx::B3DPoint ViewToEyeCoor(const basegfx::B3DPoint& rVec);
220 const basegfx::B3DPoint WorldToViewCoor(const basegfx::B3DPoint& rVec);
221 const basegfx::B3DPoint ViewToWorldCoor(const basegfx::B3DPoint& rVec);
222 const basegfx::B3DPoint DeviceToViewCoor(const basegfx::B3DPoint& rVec);
223 const basegfx::B3DPoint ViewToDeviceCoor(const basegfx::B3DPoint& rVec);
224 const basegfx::B3DPoint ObjectToWorldCoor(const basegfx::B3DPoint& rVec);
225 const basegfx::B3DPoint WorldToObjectCoor(const basegfx::B3DPoint& rVec);
226 const basegfx::B3DPoint ObjectToViewCoor(const basegfx::B3DPoint& rVec);
227 const basegfx::B3DPoint ViewToObjectCoor(const basegfx::B3DPoint& rVec);
228 const basegfx::B3DPoint ObjectToEyeCoor(const basegfx::B3DPoint& rVec);
229 const basegfx::B3DPoint EyeToObjectCoor(const basegfx::B3DPoint& rVec);
230 const basegfx::B3DPoint DeviceToEyeCoor(const basegfx::B3DPoint& rVec);
231 const basegfx::B3DPoint EyeToDeviceCoor(const basegfx::B3DPoint& rVec);
233 const basegfx::B3DPoint InvTransObjectToEye(const basegfx::B3DPoint& rVec);
234 const basegfx::B2DPoint TransTextureCoor(const basegfx::B2DPoint& rVec);
236 static void Frustum(
237 basegfx::B3DHomMatrix& rTarget,
238 double fLeft = -1.0, double fRight = 1.0,
239 double fBottom = -1.0, double fTop = 1.0,
240 double fNear = 0.001, double fFar = 1.0);
241 static void Ortho(
242 basegfx::B3DHomMatrix& rTarget,
243 double fLeft = -1.0, double fRight = 1.0,
244 double fBottom = -1.0, double fTop = 1.0,
245 double fNear = 0.0, double fFar = 1.0);
246 static void Orientation(
247 basegfx::B3DHomMatrix& rTarget,
248 basegfx::B3DPoint aVRP = basegfx::B3DPoint(0.0,0.0,1.0),
249 basegfx::B3DVector aVPN = basegfx::B3DVector(0.0,0.0,1.0),
250 basegfx::B3DVector aVUP = basegfx::B3DVector(0.0,1.0,0.0));
252 protected:
253 void PostSetObjectTrans();
254 void PostSetOrientation();
255 void PostSetProjection();
256 void PostSetTexture();
257 void PostSetViewport();
259 void CalcMatObjectToDevice();
260 void CalcMatFromWorldToView();
261 void CalcMatInvTransObjectToEye();
263 virtual void DeviceRectangleChange();
266 /*************************************************************************
268 |* Viewport fuer B3D
270 |* Verwendet wird hier ein vereinfachtes System, bei dem der abzubildende
271 |* Punkt durch VRP repraesentiert wird
273 \************************************************************************/
275 class B3dViewport : public B3dTransformationSet
277 private:
278 basegfx::B3DPoint aVRP; // View Reference Point
279 basegfx::B3DVector aVPN; // View Plane Normal
280 basegfx::B3DVector aVUV; // View Up Vector
282 public:
283 B3dViewport();
284 virtual ~B3dViewport();
286 void SetVRP(const basegfx::B3DPoint& rNewVRP);
287 void SetVPN(const basegfx::B3DVector& rNewVPN);
288 void SetVUV(const basegfx::B3DVector& rNewVUV);
289 void SetViewportValues(
290 const basegfx::B3DPoint& rNewVRP,
291 const basegfx::B3DVector& rNewVPN,
292 const basegfx::B3DVector& rNewVUV);
294 const basegfx::B3DPoint& GetVRP() const { return aVRP; }
295 const basegfx::B3DVector& GetVPN() const { return aVPN; }
296 const basegfx::B3DVector& GetVUV() const { return aVUV; }
298 protected:
299 void CalcOrientation();
302 /*************************************************************************
304 |* Kamera fuer B3D
306 \************************************************************************/
308 class B3dCamera : public B3dViewport
310 private:
311 basegfx::B3DPoint aPosition;
312 basegfx::B3DPoint aCorrectedPosition;
313 basegfx::B3DVector aLookAt;
314 double fFocalLength;
315 double fBankAngle;
317 unsigned bUseFocalLength : 1;
319 public:
320 B3dCamera(
321 const basegfx::B3DPoint& rPos = basegfx::B3DPoint(0.0, 0.0, 1.0),
322 const basegfx::B3DVector& rLkAt = basegfx::B3DVector(0.0, 0.0, 0.0),
323 double fFocLen = 35.0, double fBnkAng = 0.0,
324 sal_Bool bUseFocLen = sal_False);
325 virtual ~B3dCamera();
327 // Positionen
328 void SetPosition(const basegfx::B3DPoint& rNewPos);
329 const basegfx::B3DPoint& GetPosition() const { return aPosition; }
330 void SetLookAt(const basegfx::B3DVector& rNewLookAt);
331 const basegfx::B3DVector& GetLookAt() const { return aLookAt; }
332 void SetPositionAndLookAt(const basegfx::B3DPoint& rNewPos, const basegfx::B3DVector& rNewLookAt);
334 // Brennweite in mm
335 void SetFocalLength(double fLen);
336 double GetFocalLength() const { return fFocalLength; }
338 // Neigung links/rechts
339 void SetBankAngle(double fAngle);
340 double GetBankAngle() const { return fBankAngle; }
342 // FocalLength Flag
343 void SetUseFocalLength(sal_Bool bNew);
344 sal_Bool GetUseFocalLength() const { return (sal_Bool)bUseFocalLength; }
346 protected:
347 void CalcNewViewportValues();
348 sal_Bool CalcFocalLength();
350 virtual void DeviceRectangleChange();
354 #endif // _B3D_B3DTRANS_HXX