1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir #include <svx/camera3d.hxx> 31*cdf0e10cSrcweir #include <tools/stream.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir /************************************************************************* 34*cdf0e10cSrcweir |* 35*cdf0e10cSrcweir |* Konstruktor 36*cdf0e10cSrcweir |* 37*cdf0e10cSrcweir \************************************************************************/ 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir Camera3D::Camera3D(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt, 40*cdf0e10cSrcweir double fFocalLen, double fBankAng) : 41*cdf0e10cSrcweir aResetPos(rPos), 42*cdf0e10cSrcweir aResetLookAt(rLookAt), 43*cdf0e10cSrcweir fResetFocalLength(fFocalLen), 44*cdf0e10cSrcweir fResetBankAngle(fBankAng), 45*cdf0e10cSrcweir fBankAngle(fBankAng), 46*cdf0e10cSrcweir bAutoAdjustProjection(sal_True) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir SetVPD(0); 49*cdf0e10cSrcweir SetPosition(rPos); 50*cdf0e10cSrcweir SetLookAt(rLookAt); 51*cdf0e10cSrcweir SetFocalLength(fFocalLen); 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir /************************************************************************* 55*cdf0e10cSrcweir |* 56*cdf0e10cSrcweir |* Default-Konstruktor 57*cdf0e10cSrcweir |* 58*cdf0e10cSrcweir \************************************************************************/ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir Camera3D::Camera3D() 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir basegfx::B3DPoint aVector3D(0.0 ,0.0 ,1.0); 63*cdf0e10cSrcweir Camera3D(aVector3D, basegfx::B3DPoint()); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /************************************************************************* 67*cdf0e10cSrcweir |* 68*cdf0e10cSrcweir |* Konstruktor 69*cdf0e10cSrcweir |* 70*cdf0e10cSrcweir \************************************************************************/ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir void Camera3D::Reset() 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir SetVPD(0); 75*cdf0e10cSrcweir fBankAngle = fResetBankAngle; 76*cdf0e10cSrcweir SetPosition(aResetPos); 77*cdf0e10cSrcweir SetLookAt(aResetLookAt); 78*cdf0e10cSrcweir SetFocalLength(fResetFocalLength); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir /************************************************************************* 82*cdf0e10cSrcweir |* 83*cdf0e10cSrcweir |* Defaultwerte fuer Reset setzen 84*cdf0e10cSrcweir |* 85*cdf0e10cSrcweir \************************************************************************/ 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir void Camera3D::SetDefaults(const basegfx::B3DPoint& rPos, const basegfx::B3DPoint& rLookAt, 88*cdf0e10cSrcweir double fFocalLen, double fBankAng) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir aResetPos = rPos; 91*cdf0e10cSrcweir aResetLookAt = rLookAt; 92*cdf0e10cSrcweir fResetFocalLength = fFocalLen; 93*cdf0e10cSrcweir fResetBankAngle = fBankAng; 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /************************************************************************* 97*cdf0e10cSrcweir |* 98*cdf0e10cSrcweir |* ViewWindow setzen und PRP anpassen 99*cdf0e10cSrcweir |* 100*cdf0e10cSrcweir \************************************************************************/ 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void Camera3D::SetViewWindow(double fX, double fY, double fW, double fH) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir Viewport3D::SetViewWindow(fX, fY, fW, fH); 105*cdf0e10cSrcweir if ( bAutoAdjustProjection ) 106*cdf0e10cSrcweir SetFocalLength(fFocalLength); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /************************************************************************* 110*cdf0e10cSrcweir |* 111*cdf0e10cSrcweir |* Kameraposition setzen 112*cdf0e10cSrcweir |* 113*cdf0e10cSrcweir \************************************************************************/ 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void Camera3D::SetPosition(const basegfx::B3DPoint& rNewPos) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir if ( rNewPos != aPosition ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir aPosition = rNewPos; 120*cdf0e10cSrcweir SetVRP(aPosition); 121*cdf0e10cSrcweir SetVPN(aPosition - aLookAt); 122*cdf0e10cSrcweir SetBankAngle(fBankAngle); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir /************************************************************************* 127*cdf0e10cSrcweir |* 128*cdf0e10cSrcweir |* Blickpunkt setzen 129*cdf0e10cSrcweir |* 130*cdf0e10cSrcweir \************************************************************************/ 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir void Camera3D::SetLookAt(const basegfx::B3DPoint& rNewLookAt) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir if ( rNewLookAt != aLookAt ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir aLookAt = rNewLookAt; 137*cdf0e10cSrcweir SetVPN(aPosition - aLookAt); 138*cdf0e10cSrcweir SetBankAngle(fBankAngle); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /************************************************************************* 143*cdf0e10cSrcweir |* 144*cdf0e10cSrcweir |* Position und Blickpunkt setzen 145*cdf0e10cSrcweir |* 146*cdf0e10cSrcweir \************************************************************************/ 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir void Camera3D::SetPosAndLookAt(const basegfx::B3DPoint& rNewPos, 149*cdf0e10cSrcweir const basegfx::B3DPoint& rNewLookAt) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir if ( rNewPos != aPosition || rNewLookAt != aLookAt ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir aPosition = rNewPos; 154*cdf0e10cSrcweir aLookAt = rNewLookAt; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir SetVRP(aPosition); 157*cdf0e10cSrcweir SetVPN(aPosition - aLookAt); 158*cdf0e10cSrcweir SetBankAngle(fBankAngle); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir /************************************************************************* 163*cdf0e10cSrcweir |* 164*cdf0e10cSrcweir |* seitlichen Neigungswinkel setzen 165*cdf0e10cSrcweir |* 166*cdf0e10cSrcweir \************************************************************************/ 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir void Camera3D::SetBankAngle(double fAngle) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir basegfx::B3DVector aDiff(aPosition - aLookAt); 171*cdf0e10cSrcweir basegfx::B3DVector aPrj(aDiff); 172*cdf0e10cSrcweir fBankAngle = fAngle; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if ( aDiff.getY() == 0 ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir aPrj.setY(-1.0); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir else 179*cdf0e10cSrcweir { // aPrj = Projektion von aDiff auf die XZ-Ebene 180*cdf0e10cSrcweir aPrj.setY(0.0); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir if ( aDiff.getY() < 0.0 ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir aPrj = -aPrj; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // von aDiff nach oben zeigenden View-Up-Vektor berechnen 189*cdf0e10cSrcweir aPrj = aPrj.getPerpendicular(aDiff); 190*cdf0e10cSrcweir aPrj = aPrj.getPerpendicular(aDiff); 191*cdf0e10cSrcweir aDiff.normalize(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir // auf Z-Achse rotieren, dort um BankAngle drehen und zurueck 194*cdf0e10cSrcweir basegfx::B3DHomMatrix aTf; 195*cdf0e10cSrcweir const double fV(sqrt(aDiff.getY() * aDiff.getY() + aDiff.getZ() * aDiff.getZ())); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir if ( fV != 0.0 ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 200*cdf0e10cSrcweir const double fSin(aDiff.getY() / fV); 201*cdf0e10cSrcweir const double fCos(aDiff.getZ() / fV); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir aTemp.set(1, 1, fCos); 204*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 205*cdf0e10cSrcweir aTemp.set(2, 1, fSin); 206*cdf0e10cSrcweir aTemp.set(1, 2, -fSin); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir aTf *= aTemp; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 213*cdf0e10cSrcweir const double fSin(-aDiff.getX()); 214*cdf0e10cSrcweir const double fCos(fV); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 217*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 218*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 219*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir aTf *= aTemp; 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir aTf.rotate(0.0, 0.0, fBankAngle); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 228*cdf0e10cSrcweir const double fSin(aDiff.getX()); 229*cdf0e10cSrcweir const double fCos(fV); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 232*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 233*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 234*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir aTf *= aTemp; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if ( fV != 0.0 ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 242*cdf0e10cSrcweir const double fSin(-aDiff.getY() / fV); 243*cdf0e10cSrcweir const double fCos(aDiff.getZ() / fV); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir aTemp.set(1, 1, fCos); 246*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 247*cdf0e10cSrcweir aTemp.set(2, 1, fSin); 248*cdf0e10cSrcweir aTemp.set(1, 2, -fSin); 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir aTf *= aTemp; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir SetVUV(aTf * aPrj); 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir /************************************************************************* 257*cdf0e10cSrcweir |* 258*cdf0e10cSrcweir |* Brennweite setzen 259*cdf0e10cSrcweir |* 260*cdf0e10cSrcweir \************************************************************************/ 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void Camera3D::SetFocalLength(double fLen) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if ( fLen < 5 ) 265*cdf0e10cSrcweir fLen = 5; 266*cdf0e10cSrcweir SetPRP(basegfx::B3DPoint(0.0, 0.0, fLen / 35.0 * aViewWin.W)); 267*cdf0e10cSrcweir fFocalLength = fLen; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir /************************************************************************* 271*cdf0e10cSrcweir |* 272*cdf0e10cSrcweir |* Um die Kameraposition drehen, LookAt wird dabei veraendert 273*cdf0e10cSrcweir |* 274*cdf0e10cSrcweir \************************************************************************/ 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir void Camera3D::Rotate(double fHAngle, double fVAngle) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir basegfx::B3DHomMatrix aTf; 279*cdf0e10cSrcweir basegfx::B3DVector aDiff(aLookAt - aPosition); 280*cdf0e10cSrcweir const double fV(sqrt(aDiff.getX() * aDiff.getX() + aDiff.getZ() * aDiff.getZ())); 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir if ( fV != 0.0 ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 285*cdf0e10cSrcweir const double fSin(aDiff.getZ() / fV); 286*cdf0e10cSrcweir const double fCos(aDiff.getX() / fV); 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 289*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 290*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 291*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir aTf *= aTemp; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir aTf.rotate(0.0, 0.0, fVAngle); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir if ( fV != 0.0 ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 303*cdf0e10cSrcweir const double fSin(-aDiff.getZ() / fV); 304*cdf0e10cSrcweir const double fCos(aDiff.getX() / fV); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 307*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 308*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 309*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir aTf *= aTemp; 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir aTf.rotate(0.0, fHAngle, 0.0); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir aDiff *= aTf; 319*cdf0e10cSrcweir SetLookAt(aPosition + aDiff); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir /************************************************************************* 324*cdf0e10cSrcweir |* 325*cdf0e10cSrcweir |* Um den Blickpunkt drehen, Position wird dabei veraendert 326*cdf0e10cSrcweir |* 327*cdf0e10cSrcweir \************************************************************************/ 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void Camera3D::RotateAroundLookAt(double fHAngle, double fVAngle) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir basegfx::B3DHomMatrix aTf; 332*cdf0e10cSrcweir basegfx::B3DVector aDiff(aPosition - aLookAt); 333*cdf0e10cSrcweir const double fV(sqrt(aDiff.getX() * aDiff.getX() + aDiff.getZ() * aDiff.getZ())); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir if ( fV != 0.0 ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 338*cdf0e10cSrcweir const double fSin(aDiff.getZ() / fV); 339*cdf0e10cSrcweir const double fCos(aDiff.getX() / fV); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 342*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 343*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 344*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir aTf *= aTemp; 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir aTf.rotate(0.0, 0.0, fVAngle); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir if ( fV != 0.0 ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir basegfx::B3DHomMatrix aTemp; 356*cdf0e10cSrcweir const double fSin(-aDiff.getZ() / fV); 357*cdf0e10cSrcweir const double fCos(aDiff.getX() / fV); 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir aTemp.set(0, 0, fCos); 360*cdf0e10cSrcweir aTemp.set(2, 2, fCos); 361*cdf0e10cSrcweir aTemp.set(0, 2, fSin); 362*cdf0e10cSrcweir aTemp.set(2, 0, -fSin); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir aTf *= aTemp; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir aTf.rotate(0.0, fHAngle, 0.0); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir aDiff *= aTf; 372*cdf0e10cSrcweir SetPosition(aLookAt + aDiff); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir /************************************************************************* 376*cdf0e10cSrcweir |* 377*cdf0e10cSrcweir |* FG: ??? Setzt wohl die Projektionsebene in eine bestimmte Tiefe 378*cdf0e10cSrcweir |* 379*cdf0e10cSrcweir \************************************************************************/ 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir void Camera3D::SetFocalLengthWithCorrect(double fLen) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir if ( fLen < 5.0 ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir fLen = 5.0; 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir SetPRP(basegfx::B3DPoint(0.0, 0.0, aPRP.getZ() * fLen / fFocalLength)); 389*cdf0e10cSrcweir fFocalLength = fLen; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir // eof 393