LCOV - code coverage report
Current view: top level - svx/source/engine3d - camera3d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 90 101 89.1 %
Date: 2014-11-03 Functions: 8 9 88.9 %
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/camera3d.hxx>
      21             : #include <tools/stream.hxx>
      22             : 
      23        1406 : Camera3D::Camera3D(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt,
      24             :                    double fFocalLen, double fBankAng) :
      25             :     aResetPos(rPos),
      26             :     aResetLookAt(rLookAt),
      27             :     fResetFocalLength(fFocalLen),
      28             :     fResetBankAngle(fBankAng),
      29             :     fBankAngle(fBankAng),
      30        1406 :     bAutoAdjustProjection(true)
      31             : {
      32        1406 :     SetVPD(0);
      33        1406 :     SetPosition(rPos);
      34        1406 :     SetLookAt(rLookAt);
      35        1406 :     SetFocalLength(fFocalLen);
      36        1406 : }
      37             : 
      38           0 : Camera3D::Camera3D()
      39             :     : fResetFocalLength(0.0)
      40             :     , fResetBankAngle(0.0)
      41             :     , fFocalLength(0.0)
      42             :     , fBankAngle(0.0)
      43           0 :     , bAutoAdjustProjection(false)
      44             : {
      45           0 :     basegfx::B3DPoint aVector3D(0.0 ,0.0 ,1.0);
      46           0 :     Camera3D(aVector3D, basegfx::B3DPoint());
      47           0 : }
      48             : 
      49             : // Set default values for reset
      50             : 
      51        1406 : void Camera3D::SetDefaults(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt,
      52             :                             double fFocalLen, double fBankAng)
      53             : {
      54        1406 :     aResetPos           = rPos;
      55        1406 :     aResetLookAt        = rLookAt;
      56        1406 :     fResetFocalLength   = fFocalLen;
      57        1406 :     fResetBankAngle     = fBankAng;
      58        1406 : }
      59             : 
      60             : // Set ViewWindow and adjust PRP
      61             : 
      62        2812 : void Camera3D::SetViewWindow(double fX, double fY, double fW, double fH)
      63             : {
      64        2812 :     Viewport3D::SetViewWindow(fX, fY, fW, fH);
      65        2812 :     if ( bAutoAdjustProjection )
      66        1406 :         SetFocalLength(fFocalLength);
      67        2812 : }
      68             : 
      69        2849 : void Camera3D::SetPosition(const basegfx::B3DPoint& rNewPos)
      70             : {
      71        2849 :     if ( rNewPos != aPosition )
      72             :     {
      73        2849 :         aPosition = rNewPos;
      74        2849 :         SetVRP(aPosition);
      75        2849 :         SetVPN(aPosition - aLookAt);
      76        2849 :         SetBankAngle(fBankAngle);
      77             :     }
      78        2849 : }
      79             : 
      80        1406 : void Camera3D::SetLookAt(const basegfx::B3DPoint& rNewLookAt)
      81             : {
      82        1406 :     if ( rNewLookAt != aLookAt )
      83             :     {
      84           0 :         aLookAt = rNewLookAt;
      85           0 :         SetVPN(aPosition - aLookAt);
      86           0 :         SetBankAngle(fBankAngle);
      87             :     }
      88        1406 : }
      89             : 
      90        1406 : void Camera3D::SetPosAndLookAt(const basegfx::B3DPoint& rNewPos,
      91             :                                const basegfx::B3DPoint& rNewLookAt)
      92             : {
      93        1406 :     if ( rNewPos != aPosition || rNewLookAt != aLookAt )
      94             :     {
      95        1406 :         aPosition = rNewPos;
      96        1406 :         aLookAt = rNewLookAt;
      97             : 
      98        1406 :         SetVRP(aPosition);
      99        1406 :         SetVPN(aPosition - aLookAt);
     100        1406 :         SetBankAngle(fBankAngle);
     101             :     }
     102        1406 : }
     103             : 
     104        4255 : void Camera3D::SetBankAngle(double fAngle)
     105             : {
     106        4255 :     basegfx::B3DVector aDiff(aPosition - aLookAt);
     107        8510 :     basegfx::B3DVector aPrj(aDiff);
     108        4255 :     fBankAngle = fAngle;
     109             : 
     110        4255 :     if ( aDiff.getY() == 0 )
     111             :     {
     112        4255 :         aPrj.setY(-1.0);
     113             :     }
     114             :     else
     115             :     {   // aPrj = Projection from aDiff on the XZ-plane
     116           0 :         aPrj.setY(0.0);
     117             : 
     118           0 :         if ( aDiff.getY() < 0.0 )
     119             :         {
     120           0 :             aPrj = -aPrj;
     121             :         }
     122             :     }
     123             : 
     124             :     // Calculate from aDiff to uppwards pointing View-Up-Vector
     125             :     // duplicated line is intentional!
     126        4255 :     aPrj = aPrj.getPerpendicular(aDiff);
     127        4255 :     aPrj = aPrj.getPerpendicular(aDiff);
     128        4255 :     aDiff.normalize();
     129             : 
     130             :     // Rotate on Z axis, to rotate the BankAngle and back
     131        8510 :     basegfx::B3DHomMatrix aTf;
     132        4255 :     const double fV(sqrt(aDiff.getY() * aDiff.getY() + aDiff.getZ() * aDiff.getZ()));
     133             : 
     134        4255 :     if ( fV != 0.0 )
     135             :     {
     136        4255 :         basegfx::B3DHomMatrix aTemp;
     137        4255 :         const double fSin(aDiff.getY() / fV);
     138        4255 :         const double fCos(aDiff.getZ() / fV);
     139             : 
     140        4255 :         aTemp.set(1, 1, fCos);
     141        4255 :         aTemp.set(2, 2, fCos);
     142        4255 :         aTemp.set(2, 1, fSin);
     143        4255 :         aTemp.set(1, 2, -fSin);
     144             : 
     145        4255 :         aTf *= aTemp;
     146             :     }
     147             : 
     148             :     {
     149        4255 :         basegfx::B3DHomMatrix aTemp;
     150        4255 :         const double fSin(-aDiff.getX());
     151        4255 :         const double fCos(fV);
     152             : 
     153        4255 :         aTemp.set(0, 0, fCos);
     154        4255 :         aTemp.set(2, 2, fCos);
     155        4255 :         aTemp.set(0, 2, fSin);
     156        4255 :         aTemp.set(2, 0, -fSin);
     157             : 
     158        4255 :         aTf *= aTemp;
     159             :     }
     160             : 
     161        4255 :     aTf.rotate(0.0, 0.0, fBankAngle);
     162             : 
     163             :     {
     164        4255 :         basegfx::B3DHomMatrix aTemp;
     165        4255 :         const double fSin(aDiff.getX());
     166        4255 :         const double fCos(fV);
     167             : 
     168        4255 :         aTemp.set(0, 0, fCos);
     169        4255 :         aTemp.set(2, 2, fCos);
     170        4255 :         aTemp.set(0, 2, fSin);
     171        4255 :         aTemp.set(2, 0, -fSin);
     172             : 
     173        4255 :         aTf *= aTemp;
     174             :     }
     175             : 
     176        4255 :     if ( fV != 0.0 )
     177             :     {
     178        4255 :         basegfx::B3DHomMatrix aTemp;
     179        4255 :         const double fSin(-aDiff.getY() / fV);
     180        4255 :         const double fCos(aDiff.getZ() / fV);
     181             : 
     182        4255 :         aTemp.set(1, 1, fCos);
     183        4255 :         aTemp.set(2, 2, fCos);
     184        4255 :         aTemp.set(2, 1, fSin);
     185        4255 :         aTemp.set(1, 2, -fSin);
     186             : 
     187        4255 :         aTf *= aTemp;
     188             :     }
     189             : 
     190        8510 :     SetVUV(aTf * aPrj);
     191        4255 : }
     192             : 
     193        5624 : void Camera3D::SetFocalLength(double fLen)
     194             : {
     195        5624 :     if ( fLen < 5 )
     196        1406 :         fLen = 5;
     197        5624 :     SetPRP(basegfx::B3DPoint(0.0, 0.0, fLen / 35.0 * aViewWin.W));
     198        5624 :     fFocalLength = fLen;
     199        5624 : }
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10