Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_goodies / b3dtrans.hxx
blob822fe65d225dbf36eeab7a763851ad4406d399d7
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.4 $
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 #ifndef _B3D_HMATRIX_HXX
35 #include "hmatrix.hxx"
36 #endif
38 // Zu verwendender DephRange des Z-Buffers
39 #define ZBUFFER_DEPTH_RANGE (256.0 * 256.0 * 256.0)
41 namespace binfilter {
43 // Vorausdeklarationen
44 //class Base3D;
45 class B3dVolume;
47 /*************************************************************************
49 |* Unterstuetzte Methoden, um das Seitenverhaeltnis einzuhalten
51 \************************************************************************/
53 enum Base3DRatio
55 Base3DRatioGrow = 1,
56 Base3DRatioShrink,
57 Base3DRatioMiddle
60 /*************************************************************************
62 |* Typ der Projektion
64 \************************************************************************/
66 enum Base3DProjectionType
68 Base3DProjectionTypeParallel = 1,
69 Base3DProjectionTypePerspective
72 /*************************************************************************
74 |* Transformationen fuer alle 3D Ausgaben
76 \************************************************************************/
78 class B3dTransformationSet
80 private:
81 // Object Matrix Object -> World
82 Matrix4D aObjectTrans;
83 Matrix4D aInvObjectTrans;
85 // Orientation Matrix
86 Matrix4D aOrientation;
87 Matrix4D aInvOrientation;
89 // Projection Matrix
90 Matrix4D aProjection;
91 Matrix4D aInvProjection;
93 // Texture Matrices
94 Matrix4D aTexture;
96 // Speziell zum Umwandeln von Punkten Objekt -> Device
97 Matrix4D aObjectToDevice;
99 // Transponierte Inverse fuer Vectortransformationen
100 Matrix4D aInvTransObjectToEye;
102 // Transformation World->View
103 Matrix4D aMatFromWorldToView;
104 Matrix4D aInvMatFromWorldToView;
106 // Parameters for ViewportTransformation
107 Vector3D aScale;
108 Vector3D aTranslate;
110 // ViewPlane DeviceRectangle (vom Benutzer gesetzt)
111 double fLeftBound;
112 double fRightBound;
113 double fBottomBound;
114 double fTopBound;
116 // Near and far clipping planes
117 double fNearBound;
118 double fFarBound;
120 // Seitenverhaeltnis der 3D Abbildung (Y / X)
121 // default ist 1:1 -> 1.0
122 // Deaktivieren mit 0.0 als Wert
123 double fRatio;
125 // Der gesetzte Ausgabebereich (in logischen Koordinaten)
126 // und der dazugehoerige sichtbare Bereich
127 Rectangle aViewportRectangle;
128 Rectangle aVisibleRectangle;
130 // Die tatsaechlich von CalcViewport gesetzten Abmessungen
131 // des sichtbaren Bereichs (in logischen Koordinaten)
132 Rectangle aSetBound;
134 // Methode zur Aufrechterhaltung des Seitenverhaeltnisses
135 // default ist Base3DRatioGrow
136 Base3DRatio eRatio;
138 // Flags
139 unsigned bPerspective : 1;
140 unsigned bWorldToViewValid : 1;
141 unsigned bInvTransObjectToEyeValid : 1;
142 unsigned bObjectToDeviceValid : 1;
143 unsigned bProjectionValid : 1;
145 public:
146 B3dTransformationSet();
148 // Zurueck auf Standard
149 void Reset();
151 // ObjectTrans
152 void SetObjectTrans(Matrix4D& rObj);
153 const Matrix4D& GetObjectTrans() { return aObjectTrans; }
154 const Matrix4D& GetInvObjectTrans() { return aInvObjectTrans; }
156 // Orientation
157 #if ! defined ICC && ! defined __GNUC__
158 void SetOrientation(Vector3D& aVRP = Vector3D(0.0,0.0,1.0),
159 Vector3D& aVPN = Vector3D(0.0,0.0,1.0),
160 Vector3D& aVUP = Vector3D(0.0,1.0,0.0));
161 #else
162 void SetOrientation(Vector3D aVRP = Vector3D(0.0,0.0,1.0),
163 Vector3D aVPN = Vector3D(0.0,0.0,1.0),
164 Vector3D aVUP = Vector3D(0.0,1.0,0.0));
165 #endif
166 const Matrix4D& GetOrientation() { return aOrientation; }
167 const Matrix4D& GetInvOrientation() { return aInvOrientation; }
169 // Projection
170 void SetProjection(Matrix4D& mProject);
171 const Matrix4D& GetProjection();
172 const Matrix4D& GetInvProjection();
174 // Texture
175 const Matrix4D& GetTexture() { return aTexture; }
177 // Seitenverhaeltnis und Modus zu dessen Aufrechterhaltung
178 double GetRatio() { return fRatio; }
179 void SetRatio(double fNew=1.0);
180 Base3DRatio GetRatioMode() { return eRatio; }
182 // Parameter der ViewportTransformation
183 void SetDeviceRectangle(double fL=-1.0, double fR=1.0, double fB=-1.0, double fT=1.0,
184 BOOL bBroadCastChange=TRUE);
185 void SetDeviceVolume(const B3dVolume& rVol, BOOL bBroadCastChange=TRUE);
186 double GetDeviceRectangleWidth() const { return fRightBound - fLeftBound; }
187 double GetDeviceRectangleHeight() const { return fTopBound - fBottomBound; }
188 void SetFrontClippingPlane(double fF=0.0);
189 double GetFrontClippingPlane() { return fNearBound; }
190 void SetBackClippingPlane(double fB=1.0);
191 double GetBackClippingPlane() { return fFarBound; }
192 void SetPerspective(BOOL bNew);
193 BOOL GetPerspective() { return bPerspective; }
194 void SetViewportRectangle(Rectangle& rRect, Rectangle& rVisible);
195 void SetViewportRectangle(Rectangle& rRect) { SetViewportRectangle(rRect, rRect); }
196 const Rectangle& GetViewportRectangle() { return aViewportRectangle; }
197 void CalcViewport();
199 // Speziell zum Umwandeln von Punkten World -> View
200 const Matrix4D& GetMatFromWorldToView();
201 const Matrix4D& GetInvMatFromWorldToView();
203 // Bounds des Viewports lesen
204 const Vector3D& GetScale();
205 const Vector3D& GetTranslate();
207 // Direkter Zugriff auf verschiedene Transformationen
208 const Vector3D WorldToEyeCoor(const Vector3D& rVec);
209 const Vector3D EyeToWorldCoor(const Vector3D& rVec);
210 const Vector3D ViewToEyeCoor(const Vector3D& rVec);
211 const Vector3D WorldToViewCoor(const Vector3D& rVec);
212 const Vector3D ObjectToWorldCoor(const Vector3D& rVec);
213 const Vector3D ViewToObjectCoor(const Vector3D& rVec);
214 const Vector3D ObjectToEyeCoor(const Vector3D& rVec);
215 protected:
216 void PostSetObjectTrans();
217 void PostSetOrientation();
218 void PostSetProjection();
219 void PostSetViewport();
221 void CalcMatFromWorldToView();
223 virtual void DeviceRectangleChange();
226 /*************************************************************************
228 |* Viewport fuer B3D
230 |* Verwendet wird hier ein vereinfachtes System, bei dem der abzubildende
231 |* Punkt durch VRP repraesentiert wird
233 \************************************************************************/
235 class B3dViewport : public B3dTransformationSet
237 private:
238 Vector3D aVRP; // View Reference Point
239 Vector3D aVPN; // View Plane Normal
240 Vector3D aVUV; // View Up Vector
242 public:
243 B3dViewport();
245 void SetVUV(const Vector3D& rNewVUV);
246 void SetViewportValues(
247 const Vector3D& rNewVRP,
248 const Vector3D& rNewVPN,
249 const Vector3D& rNewVUV);
251 const Vector3D& GetVRP() const { return aVRP; }
252 const Vector3D& GetVPN() const { return aVPN; }
253 const Vector3D& GetVUV() const { return aVUV; }
255 protected:
256 void CalcOrientation();
259 /*************************************************************************
261 |* Kamera fuer B3D
263 \************************************************************************/
265 class B3dCamera : public B3dViewport
267 private:
268 Vector3D aPosition;
269 Vector3D aCorrectedPosition;
270 Vector3D aLookAt;
271 double fFocalLength;
272 double fBankAngle;
274 unsigned bUseFocalLength : 1;
276 public:
277 B3dCamera(const Vector3D& rPos = Vector3D(0.0, 0.0, 1.0),
278 const Vector3D& rLkAt = Vector3D(0.0, 0.0, 0.0),
279 double fFocLen = 35.0, double fBnkAng = 0.0,
280 BOOL bUseFocLen = FALSE);
282 // Positionen
283 const Vector3D& GetPosition() const { return aPosition; }
284 const Vector3D& GetLookAt() const { return aLookAt; }
286 // Brennweite in mm
287 double GetFocalLength() const { return fFocalLength; }
289 // Neigung links/rechts
290 double GetBankAngle() const { return fBankAngle; }
292 // FocalLength Flag
293 BOOL GetUseFocalLength() const { return (BOOL)bUseFocalLength; }
295 protected:
296 void CalcNewViewportValues();
297 BOOL CalcFocalLength();
299 virtual void DeviceRectangleChange();
301 }//end of namespace binfilter
303 #endif // _B3D_B3DTRANS_HXX