LCOV - code coverage report
Current view: top level - svx/source/engine3d - viewpt3d2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 87 107 81.3 %
Date: 2014-04-11 Functions: 10 10 100.0 %
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             : #include <svx/viewpt3d.hxx>
      21             : #include <basegfx/range/b3drange.hxx>
      22             : 
      23         344 : Viewport3D::Viewport3D() :
      24             :     aVRP(0, 0, 5),
      25             :     aVPN(0, 0, 1),
      26             :     aVUV(0, 1, 1),
      27             :     aPRP(0, 0, 2),
      28             :     fVPD(-3),
      29             :     fNearClipDist (0.0),
      30             :     fFarClipDist (0.0),
      31             :     eProjection(PR_PERSPECTIVE),
      32             :     eAspectMapping(AS_NO_MAPPING),
      33             :     aDeviceRect(Point(0,0), Size(-1,-1)),
      34             :     aViewPoint (0, 0, 5000),
      35             :     bTfValid(false),
      36             :     fWRatio (1.0),
      37         344 :     fHRatio (1.0)
      38             : {
      39         344 :     aViewWin.X = -1; aViewWin.Y = -1;
      40         344 :     aViewWin.W =  2; aViewWin.H = 2;
      41         344 : }
      42             : 
      43             : // Set ViewWindow (in View coordinates)
      44             : 
      45         688 : void Viewport3D::SetViewWindow(double fX, double fY, double fW, double fH)
      46             : {
      47         688 :     aViewWin.X = fX;
      48         688 :     aViewWin.Y = fY;
      49         688 :     if ( fW > 0 )   aViewWin.W = fW;
      50           0 :     else            aViewWin.W = 1.0;
      51         688 :     if ( fH > 0 )   aViewWin.H = fH;
      52           0 :     else            aViewWin.H = 1.0;
      53             : 
      54         688 :     fWRatio = aDeviceRect.GetWidth() / aViewWin.W;
      55         688 :     fHRatio = aDeviceRect.GetHeight() / aViewWin.H;
      56         688 : }
      57             : 
      58             : // Returns observer position (PRP) in world coordinates
      59             : 
      60         366 : const basegfx::B3DPoint& Viewport3D::GetViewPoint()
      61             : {
      62         366 :     MakeTransform();
      63             : 
      64         366 :     return aViewPoint;
      65             : }
      66             : 
      67             : // Calculate View transformations matrix
      68             : 
      69         366 : void Viewport3D::MakeTransform(void)
      70             : {
      71         366 :     if ( !bTfValid )
      72             :     {
      73             :         double fV, fXupVp, fYupVp;
      74         366 :         aViewPoint = aVRP + aVPN * aPRP.getZ();
      75             : 
      76             :         // Reset to Identity matrix
      77         366 :         aViewTf.identity();
      78             : 
      79             :         // shift in the origin
      80         366 :         aViewTf.translate(-aVRP.getX(), -aVRP.getY(), -aVRP.getZ());
      81             : 
      82             :         // fV = Length of the projection of aVPN on the yz plane:
      83         366 :         fV = aVPN.getYZLength();
      84             : 
      85         366 :         if ( fV != 0 )
      86             :         {
      87         366 :             basegfx::B3DHomMatrix aTemp;
      88         366 :             const double fSin(aVPN.getY() / fV);
      89         366 :             const double fCos(aVPN.getZ() / fV);
      90         366 :             aTemp.set(2, 2, fCos);
      91         366 :             aTemp.set(1, 1, fCos);
      92         366 :             aTemp.set(2, 1, fSin);
      93         366 :             aTemp.set(1, 2, -fSin);
      94         366 :             aViewTf *= aTemp;
      95             :         }
      96             : 
      97             :         {
      98         366 :             basegfx::B3DHomMatrix aTemp;
      99         366 :             const double fSin(-aVPN.getX());
     100         366 :             const double fCos(fV);
     101         366 :             aTemp.set(2, 2, fCos);
     102         366 :             aTemp.set(0, 0, fCos);
     103         366 :             aTemp.set(0, 2, fSin);
     104         366 :             aTemp.set(2, 0, -fSin);
     105         366 :             aViewTf *= aTemp;
     106             :         }
     107             : 
     108             :         // Convert X- and Y- coordinates of the view up vector to the
     109             :         // (preliminary) view coordinate system.
     110         366 :         fXupVp = aViewTf.get(0, 0) * aVUV.getX() + aViewTf.get(0, 1) * aVUV.getY() + aViewTf.get(0, 2) * aVUV.getZ();
     111         366 :         fYupVp = aViewTf.get(1, 0) * aVUV.getX() + aViewTf.get(1, 1) * aVUV.getY() + aViewTf.get(1, 2) * aVUV.getZ();
     112         366 :         fV = sqrt(fXupVp * fXupVp + fYupVp * fYupVp);
     113             : 
     114         366 :         if ( fV != 0 )
     115             :         {
     116         366 :             basegfx::B3DHomMatrix aTemp;
     117         366 :             const double fSin(fXupVp / fV);
     118         366 :             const double fCos(fYupVp / fV);
     119         366 :             aTemp.set(1, 1, fCos);
     120         366 :             aTemp.set(0, 0, fCos);
     121         366 :             aTemp.set(1, 0, fSin);
     122         366 :             aTemp.set(0, 1, -fSin);
     123         366 :             aViewTf *= aTemp;
     124             :         }
     125             : 
     126         366 :         bTfValid = true;
     127             :     }
     128         366 : }
     129             : 
     130        1182 : void Viewport3D::SetDeviceWindow(const Rectangle& rRect)
     131             : {
     132        1182 :     long nNewW = rRect.GetWidth();
     133        1182 :     long nNewH = rRect.GetHeight();
     134        1182 :     long nOldW = aDeviceRect.GetWidth();
     135        1182 :     long nOldH = aDeviceRect.GetHeight();
     136             : 
     137        1182 :     switch ( eAspectMapping )
     138             :     {
     139             :         double  fRatio, fTmp;
     140             : 
     141             :         // Mapping, without changing the real size of the objects in the
     142             :         // Device Window
     143             :         case AS_HOLD_SIZE:
     144             :             // When the Device is invalid (w, h = -1), adapt the  View
     145             :             // with AsHoldX
     146           0 :             if ( nOldW > 0 && nOldH > 0 )
     147             :             {
     148           0 :                 fRatio = (double) nNewW / nOldW;
     149           0 :                 aViewWin.X *= fRatio;
     150           0 :                 aViewWin.W *= fRatio;
     151           0 :                 fRatio = (double) nNewH / nOldH;
     152           0 :                 aViewWin.Y *= fRatio;
     153           0 :                 aViewWin.H *= fRatio;
     154           0 :                 break;
     155             :             }
     156             :         case AS_HOLD_X:
     157             :             // Adapt view height to view width
     158           0 :             fRatio = (double) nNewH / nNewW;
     159           0 :             fTmp = aViewWin.H;
     160           0 :             aViewWin.H = aViewWin.W * fRatio;
     161           0 :             aViewWin.Y = aViewWin.Y * aViewWin.H / fTmp;
     162           0 :             break;
     163             : 
     164             :         case AS_HOLD_Y:
     165             :             // Adapt view width to view height
     166           0 :             fRatio = (double) nNewW / nNewH;
     167           0 :             fTmp = aViewWin.W;
     168           0 :             aViewWin.W = aViewWin.H * fRatio;
     169           0 :             aViewWin.X = aViewWin.X * aViewWin.W / fTmp;
     170           0 :             break;
     171        1182 :         default: break;
     172             :     }
     173        1182 :     fWRatio = nNewW / aViewWin.W;
     174        1182 :     fHRatio = nNewH / aViewWin.H;
     175             : 
     176        1182 :     aDeviceRect = rRect;
     177        1182 : }
     178             : 
     179             : // Set View Reference Point
     180             : 
     181        1044 : void Viewport3D::SetVRP(const basegfx::B3DPoint& rNewVRP)
     182             : {
     183        1044 :     aVRP = rNewVRP;
     184        1044 :     bTfValid = false;
     185        1044 : }
     186             : 
     187             : // Set View Plane Normal
     188             : 
     189        1044 : void Viewport3D::SetVPN(const basegfx::B3DVector& rNewVPN)
     190             : {
     191        1044 :     aVPN = rNewVPN;
     192        1044 :     aVPN.normalize();
     193        1044 :     bTfValid = false;
     194        1044 : }
     195             : 
     196             : // Set View Up Vector
     197             : 
     198        1044 : void Viewport3D::SetVUV(const basegfx::B3DVector& rNewVUV)
     199             : {
     200        1044 :     aVUV = rNewVUV;
     201        1044 :     bTfValid = false;
     202        1044 : }
     203             : 
     204             : // Set Center Of Projection
     205             : 
     206        1376 : void Viewport3D::SetPRP(const basegfx::B3DPoint& rNewPRP)
     207             : {
     208        1376 :     aPRP = rNewPRP;
     209        1376 :     aPRP.setX(0.0);
     210        1376 :     aPRP.setY(0.0);
     211        1376 :     bTfValid = false;
     212        1376 : }
     213             : 
     214             : // Set View Plane Distance
     215             : 
     216         344 : void Viewport3D::SetVPD(double fNewVPD)
     217             : {
     218         344 :     fVPD = fNewVPD;
     219         344 :     bTfValid = false;
     220         344 : }
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10