LCOV - code coverage report
Current view: top level - svx/source/engine3d - camera3d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 100 90.0 %
Date: 2012-08-25 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 118 47.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svx/camera3d.hxx>
      30                 :            : #include <tools/stream.hxx>
      31                 :            : 
      32                 :        736 : Camera3D::Camera3D(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt,
      33                 :            :                    double fFocalLen, double fBankAng) :
      34                 :            :     aResetPos(rPos),
      35                 :            :     aResetLookAt(rLookAt),
      36                 :            :     fResetFocalLength(fFocalLen),
      37                 :            :     fResetBankAngle(fBankAng),
      38                 :            :     fBankAngle(fBankAng),
      39                 :        736 :     bAutoAdjustProjection(sal_True)
      40                 :            : {
      41         [ +  - ]:        736 :     SetVPD(0);
      42         [ +  - ]:        736 :     SetPosition(rPos);
      43         [ +  - ]:        736 :     SetLookAt(rLookAt);
      44         [ +  - ]:        736 :     SetFocalLength(fFocalLen);
      45                 :        736 : }
      46                 :            : 
      47                 :          0 : Camera3D::Camera3D()
      48                 :            : {
      49                 :          0 :     basegfx::B3DPoint aVector3D(0.0 ,0.0 ,1.0);
      50 [ #  # ][ #  # ]:          0 :     Camera3D(aVector3D, basegfx::B3DPoint());
      51                 :          0 : }
      52                 :            : 
      53                 :            : // Set default values for reset
      54                 :            : 
      55                 :        736 : void Camera3D::SetDefaults(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt,
      56                 :            :                             double fFocalLen, double fBankAng)
      57                 :            : {
      58                 :        736 :     aResetPos           = rPos;
      59                 :        736 :     aResetLookAt        = rLookAt;
      60                 :        736 :     fResetFocalLength   = fFocalLen;
      61                 :        736 :     fResetBankAngle     = fBankAng;
      62                 :        736 : }
      63                 :            : 
      64                 :            : // Set ViewWindow and adjust PRP
      65                 :            : 
      66                 :       1472 : void Camera3D::SetViewWindow(double fX, double fY, double fW, double fH)
      67                 :            : {
      68                 :       1472 :     Viewport3D::SetViewWindow(fX, fY, fW, fH);
      69         [ +  + ]:       1472 :     if ( bAutoAdjustProjection )
      70                 :        736 :         SetFocalLength(fFocalLength);
      71                 :       1472 : }
      72                 :            : 
      73                 :       1486 : void Camera3D::SetPosition(const basegfx::B3DPoint& rNewPos)
      74                 :            : {
      75         [ +  - ]:       1486 :     if ( rNewPos != aPosition )
      76                 :            :     {
      77                 :       1486 :         aPosition = rNewPos;
      78                 :       1486 :         SetVRP(aPosition);
      79         [ +  - ]:       1486 :         SetVPN(aPosition - aLookAt);
      80                 :       1486 :         SetBankAngle(fBankAngle);
      81                 :            :     }
      82                 :       1486 : }
      83                 :            : 
      84                 :        736 : void Camera3D::SetLookAt(const basegfx::B3DPoint& rNewLookAt)
      85                 :            : {
      86         [ -  + ]:        736 :     if ( rNewLookAt != aLookAt )
      87                 :            :     {
      88                 :          0 :         aLookAt = rNewLookAt;
      89         [ #  # ]:          0 :         SetVPN(aPosition - aLookAt);
      90                 :          0 :         SetBankAngle(fBankAngle);
      91                 :            :     }
      92                 :        736 : }
      93                 :            : 
      94                 :        736 : void Camera3D::SetPosAndLookAt(const basegfx::B3DPoint& rNewPos,
      95                 :            :                                const basegfx::B3DPoint& rNewLookAt)
      96                 :            : {
      97 [ -  + ][ #  # ]:        736 :     if ( rNewPos != aPosition || rNewLookAt != aLookAt )
                 [ +  - ]
      98                 :            :     {
      99                 :        736 :         aPosition = rNewPos;
     100                 :        736 :         aLookAt = rNewLookAt;
     101                 :            : 
     102                 :        736 :         SetVRP(aPosition);
     103         [ +  - ]:        736 :         SetVPN(aPosition - aLookAt);
     104                 :        736 :         SetBankAngle(fBankAngle);
     105                 :            :     }
     106                 :        736 : }
     107                 :            : 
     108                 :       2222 : void Camera3D::SetBankAngle(double fAngle)
     109                 :            : {
     110                 :       2222 :     basegfx::B3DVector aDiff(aPosition - aLookAt);
     111                 :       2222 :     basegfx::B3DVector aPrj(aDiff);
     112                 :       2222 :     fBankAngle = fAngle;
     113                 :            : 
     114         [ +  - ]:       2222 :     if ( aDiff.getY() == 0 )
     115                 :            :     {
     116                 :       2222 :         aPrj.setY(-1.0);
     117                 :            :     }
     118                 :            :     else
     119                 :            :     {   // aPrj = Projection from aDiff on the XZ-plane
     120                 :          0 :         aPrj.setY(0.0);
     121                 :            : 
     122         [ #  # ]:          0 :         if ( aDiff.getY() < 0.0 )
     123                 :            :         {
     124                 :          0 :             aPrj = -aPrj;
     125                 :            :         }
     126                 :            :     }
     127                 :            : 
     128                 :            :     // Calculate from aDiff to uppwards pointing View-Up-Vector
     129 [ +  - ][ +  - ]:       2222 :     aPrj = aPrj.getPerpendicular(aDiff);
     130 [ +  - ][ +  - ]:       2222 :     aPrj = aPrj.getPerpendicular(aDiff);
     131         [ +  - ]:       2222 :     aDiff.normalize();
     132                 :            : 
     133                 :            :     // Rotate on Z axis, to rotate the BankAngle and back
     134         [ +  - ]:       2222 :     basegfx::B3DHomMatrix aTf;
     135                 :       2222 :     const double fV(sqrt(aDiff.getY() * aDiff.getY() + aDiff.getZ() * aDiff.getZ()));
     136                 :            : 
     137         [ +  - ]:       2222 :     if ( fV != 0.0 )
     138                 :            :     {
     139         [ +  - ]:       2222 :         basegfx::B3DHomMatrix aTemp;
     140                 :       2222 :         const double fSin(aDiff.getY() / fV);
     141                 :       2222 :         const double fCos(aDiff.getZ() / fV);
     142                 :            : 
     143         [ +  - ]:       2222 :         aTemp.set(1, 1, fCos);
     144         [ +  - ]:       2222 :         aTemp.set(2, 2, fCos);
     145         [ +  - ]:       2222 :         aTemp.set(2, 1, fSin);
     146         [ +  - ]:       2222 :         aTemp.set(1, 2, -fSin);
     147                 :            : 
     148 [ +  - ][ +  - ]:       2222 :         aTf *= aTemp;
     149                 :            :     }
     150                 :            : 
     151                 :            :     {
     152         [ +  - ]:       2222 :         basegfx::B3DHomMatrix aTemp;
     153                 :       2222 :         const double fSin(-aDiff.getX());
     154                 :       2222 :         const double fCos(fV);
     155                 :            : 
     156         [ +  - ]:       2222 :         aTemp.set(0, 0, fCos);
     157         [ +  - ]:       2222 :         aTemp.set(2, 2, fCos);
     158         [ +  - ]:       2222 :         aTemp.set(0, 2, fSin);
     159         [ +  - ]:       2222 :         aTemp.set(2, 0, -fSin);
     160                 :            : 
     161 [ +  - ][ +  - ]:       2222 :         aTf *= aTemp;
     162                 :            :     }
     163                 :            : 
     164         [ +  - ]:       2222 :     aTf.rotate(0.0, 0.0, fBankAngle);
     165                 :            : 
     166                 :            :     {
     167         [ +  - ]:       2222 :         basegfx::B3DHomMatrix aTemp;
     168                 :       2222 :         const double fSin(aDiff.getX());
     169                 :       2222 :         const double fCos(fV);
     170                 :            : 
     171         [ +  - ]:       2222 :         aTemp.set(0, 0, fCos);
     172         [ +  - ]:       2222 :         aTemp.set(2, 2, fCos);
     173         [ +  - ]:       2222 :         aTemp.set(0, 2, fSin);
     174         [ +  - ]:       2222 :         aTemp.set(2, 0, -fSin);
     175                 :            : 
     176 [ +  - ][ +  - ]:       2222 :         aTf *= aTemp;
     177                 :            :     }
     178                 :            : 
     179         [ +  - ]:       2222 :     if ( fV != 0.0 )
     180                 :            :     {
     181         [ +  - ]:       2222 :         basegfx::B3DHomMatrix aTemp;
     182                 :       2222 :         const double fSin(-aDiff.getY() / fV);
     183                 :       2222 :         const double fCos(aDiff.getZ() / fV);
     184                 :            : 
     185         [ +  - ]:       2222 :         aTemp.set(1, 1, fCos);
     186         [ +  - ]:       2222 :         aTemp.set(2, 2, fCos);
     187         [ +  - ]:       2222 :         aTemp.set(2, 1, fSin);
     188         [ +  - ]:       2222 :         aTemp.set(1, 2, -fSin);
     189                 :            : 
     190 [ +  - ][ +  - ]:       2222 :         aTf *= aTemp;
     191                 :            :     }
     192                 :            : 
     193 [ +  - ][ +  - ]:       2222 :     SetVUV(aTf * aPrj);
                 [ +  - ]
     194                 :       2222 : }
     195                 :            : 
     196                 :       2944 : void Camera3D::SetFocalLength(double fLen)
     197                 :            : {
     198         [ +  + ]:       2944 :     if ( fLen < 5 )
     199                 :        736 :         fLen = 5;
     200         [ +  - ]:       2944 :     SetPRP(basegfx::B3DPoint(0.0, 0.0, fLen / 35.0 * aViewWin.W));
     201                 :       2944 :     fFocalLength = fLen;
     202                 :       2944 : }
     203                 :            : 
     204                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10