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