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

Generated by: LCOV version 1.11