LCOV - code coverage report
Current view: top level - include/tools - b3dtrans.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 11 63.6 %
Date: 2015-06-13 12:38:46 Functions: 7 11 63.6 %
Legend: Lines: hit not hit

          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 INCLUDED_TOOLS_B3DTRANS_HXX
      21             : #define INCLUDED_TOOLS_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             :         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        2546 :     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        1273 :     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        2546 :     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        5863 :     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             : 
     185             :     virtual void DeviceRectangleChange();
     186             : };
     187             : 
     188             : /** Viewport for B3D
     189             : 
     190             :     Uses a simplified model, in which a point is described using a View
     191             :     Reference Point (VRP).
     192             : */
     193           0 : class TOOLS_DLLPUBLIC B3dViewport : public B3dTransformationSet
     194             : {
     195             : private:
     196             :     basegfx::B3DPoint           aVRP;   // View Reference Point
     197             :     basegfx::B3DVector          aVPN;   // View Plane Normal
     198             :     basegfx::B3DVector          aVUV;   // View Up Vector
     199             : 
     200             : public:
     201             :     B3dViewport();
     202             :     virtual ~B3dViewport();
     203             : 
     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);
     209             : 
     210         627 :     const basegfx::B3DPoint&    GetVRP() const  { return aVRP; }
     211         627 :     const basegfx::B3DVector&   GetVPN() const  { return aVPN; }
     212         627 :     const basegfx::B3DVector&   GetVUV() const  { return aVUV; }
     213             : 
     214             : protected:
     215             :     void CalcOrientation();
     216             : };
     217             : 
     218             : // B3D camera
     219             : 
     220           0 : class TOOLS_DLLPUBLIC B3dCamera : public B3dViewport
     221             : {
     222             : private:
     223             :     basegfx::B3DPoint       aPosition;
     224             :     basegfx::B3DPoint       aCorrectedPosition;
     225             :     basegfx::B3DVector  aLookAt;
     226             :     double                  fFocalLength;
     227             :     double                  fBankAngle;
     228             : 
     229             :     bool                    bUseFocalLength         : 1;
     230             : 
     231             : public:
     232             :     B3dCamera(
     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();
     238             : 
     239             :     const basegfx::B3DPoint& GetPosition() const { return aPosition; }
     240             :     const basegfx::B3DVector& GetLookAt() const { return aLookAt; }
     241             : 
     242             :     // Focal length in mm
     243             :     double GetFocalLength() const { return fFocalLength; }
     244             : 
     245             :     double GetBankAngle() const { return fBankAngle; }
     246             : 
     247             :     bool GetUseFocalLength() const { return (bool)bUseFocalLength; }
     248             : 
     249             : protected:
     250             :     void CalcNewViewportValues();
     251             :     bool CalcFocalLength();
     252             : 
     253             :     virtual void DeviceRectangleChange() SAL_OVERRIDE;
     254             : };
     255             : 
     256             : #endif
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11