2003-10-28 04:26:57 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: b3dhommatrix.cxx,v $
|
|
|
|
*
|
2004-11-26 11:38:01 -06:00
|
|
|
* $Revision: 1.7 $
|
2003-10-28 04:26:57 -06:00
|
|
|
*
|
2004-11-26 11:38:01 -06:00
|
|
|
* last change: $Author: rt $ $Date: 2004-11-26 18:38:01 $
|
2003-10-28 04:26:57 -06:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _BGFX_MATRIX_B3DHOMMATRIX_HXX
|
2003-10-31 03:14:00 -06:00
|
|
|
#include <basegfx/matrix/b3dhommatrix.hxx>
|
2003-10-28 04:26:57 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _HOMMATRIX_TEMPLATE_HXX
|
|
|
|
#include <hommatrixtemplate.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _BGFX_VECTOR_B3DVECTOR_HXX
|
2003-10-31 03:14:00 -06:00
|
|
|
#include <basegfx/vector/b3dvector.hxx>
|
2003-10-28 04:26:57 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace basegfx
|
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
class Impl3DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 4 >
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
};
|
2003-11-10 08:10:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
static Impl3DHomMatrix& get3DIdentityMatrix()
|
|
|
|
{
|
|
|
|
static Impl3DHomMatrix maStatic3DIdentityHomMatrix;
|
|
|
|
return maStatic3DIdentityHomMatrix;
|
|
|
|
}
|
2003-11-10 08:10:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::implPrepareChange()
|
|
|
|
{
|
|
|
|
if(mpM->getRefCount())
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->decRefCount();
|
|
|
|
mpM = new Impl3DHomMatrix(*mpM);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix::B3DHomMatrix()
|
|
|
|
: mpM(&get3DIdentityMatrix())
|
|
|
|
{
|
|
|
|
mpM->incRefCount();
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix::B3DHomMatrix(const B3DHomMatrix& rMat)
|
|
|
|
: mpM(rMat.mpM)
|
|
|
|
{
|
|
|
|
mpM->incRefCount();
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix::~B3DHomMatrix()
|
|
|
|
{
|
|
|
|
if(mpM->getRefCount())
|
|
|
|
mpM->decRefCount();
|
|
|
|
else
|
|
|
|
delete mpM;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix& B3DHomMatrix::operator=(const B3DHomMatrix& rMat)
|
|
|
|
{
|
|
|
|
if(mpM->getRefCount())
|
|
|
|
mpM->decRefCount();
|
|
|
|
else
|
|
|
|
delete mpM;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM = rMat.mpM;
|
|
|
|
mpM->incRefCount();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
double B3DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const
|
|
|
|
{
|
|
|
|
return mpM->get(nRow, nColumn);
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
|
|
|
|
{
|
|
|
|
implPrepareChange();
|
|
|
|
mpM->set(nRow, nColumn, fValue);
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::isIdentity() const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
if(mpM == &get3DIdentityMatrix())
|
2004-01-16 03:34:43 -06:00
|
|
|
return true;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return mpM->isIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B3DHomMatrix::identity()
|
|
|
|
{
|
|
|
|
if(mpM->getRefCount())
|
|
|
|
mpM->decRefCount();
|
|
|
|
else
|
|
|
|
delete mpM;
|
|
|
|
|
|
|
|
mpM = &get3DIdentityMatrix();
|
|
|
|
mpM->incRefCount();
|
|
|
|
}
|
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::isInvertible() const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
return mpM->isInvertible();
|
|
|
|
}
|
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::invert()
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
Impl3DHomMatrix aWork(*mpM);
|
|
|
|
sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()];
|
|
|
|
sal_Int16 nParity;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(aWork.ludcmp(pIndex, nParity))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doInvert(aWork, pIndex);
|
2004-11-26 11:38:01 -06:00
|
|
|
delete[] pIndex;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
return true;
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2004-11-26 11:38:01 -06:00
|
|
|
delete[] pIndex;
|
2004-01-16 03:34:43 -06:00
|
|
|
return false;
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::isNormalized() const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
return mpM->isNormalized();
|
|
|
|
}
|
|
|
|
|
|
|
|
void B3DHomMatrix::normalize()
|
|
|
|
{
|
|
|
|
if(!mpM->isNormalized())
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doNormalize();
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
double B3DHomMatrix::determinant() const
|
|
|
|
{
|
|
|
|
return mpM->doDeterminant();
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
double B3DHomMatrix::trace() const
|
|
|
|
{
|
|
|
|
return mpM->doTrace();
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::transpose()
|
|
|
|
{
|
|
|
|
implPrepareChange();
|
|
|
|
mpM->doTranspose();
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix& B3DHomMatrix::operator+=(const B3DHomMatrix& rMat)
|
|
|
|
{
|
|
|
|
implPrepareChange();
|
|
|
|
mpM->doAddMatrix(*rMat.mpM);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix& B3DHomMatrix::operator-=(const B3DHomMatrix& rMat)
|
|
|
|
{
|
|
|
|
implPrepareChange();
|
|
|
|
mpM->doSubMatrix(*rMat.mpM);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
B3DHomMatrix& B3DHomMatrix::operator*=(double fValue)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equal(fOne, fValue))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
|
|
|
implPrepareChange();
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(fValue);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
B3DHomMatrix& B3DHomMatrix::operator/=(double fValue)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
|
|
|
|
|
|
|
if(!::basegfx::fTools::equal(fOne, fValue))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
|
|
|
implPrepareChange();
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(1.0 / fValue);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
B3DHomMatrix& B3DHomMatrix::operator*=(const B3DHomMatrix& rMat)
|
|
|
|
{
|
|
|
|
if(!rMat.isIdentity())
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
|
|
|
implPrepareChange();
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(*rMat.mpM);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return *this;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::operator==(const B3DHomMatrix& rMat) const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
if(mpM == rMat.mpM)
|
2004-01-16 03:34:43 -06:00
|
|
|
return true;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return mpM->isEqual(*rMat.mpM);
|
|
|
|
}
|
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::operator!=(const B3DHomMatrix& rMat) const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
if(mpM == rMat.mpM)
|
2004-01-16 03:34:43 -06:00
|
|
|
return false;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
return !mpM->isEqual(*rMat.mpM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void B3DHomMatrix::rotate(double fAngleX,double fAngleY,double fAngleZ)
|
|
|
|
{
|
|
|
|
if(!::basegfx::fTools::equalZero(fAngleX) || !::basegfx::fTools::equalZero(fAngleY) || !::basegfx::fTools::equalZero(fAngleZ))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fAngleX))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
Impl3DHomMatrix aRotMatX(get3DIdentityMatrix());
|
|
|
|
double fSin(sin(fAngleX));
|
|
|
|
double fCos(cos(fAngleX));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aRotMatX.set(1, 1, fCos);
|
|
|
|
aRotMatX.set(2, 2, fCos);
|
|
|
|
aRotMatX.set(2, 1, fSin);
|
|
|
|
aRotMatX.set(1, 2, -fSin);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(aRotMatX);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fAngleY))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aRotMatY(get3DIdentityMatrix());
|
|
|
|
double fSin(sin(fAngleY));
|
|
|
|
double fCos(cos(fAngleY));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aRotMatY.set(0, 0, fCos);
|
|
|
|
aRotMatY.set(2, 2, fCos);
|
|
|
|
aRotMatY.set(0, 2, fSin);
|
|
|
|
aRotMatY.set(2, 0, -fSin);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(aRotMatY);
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fAngleZ))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aRotMatZ(get3DIdentityMatrix());
|
|
|
|
double fSin(sin(fAngleZ));
|
|
|
|
double fCos(cos(fAngleZ));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aRotMatZ.set(0, 0, fCos);
|
|
|
|
aRotMatZ.set(1, 1, fCos);
|
|
|
|
aRotMatZ.set(1, 0, fSin);
|
|
|
|
aRotMatZ.set(0, 1, -fSin);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM->doMulMatrix(aRotMatZ);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::translate(double fX, double fY, double fZ)
|
|
|
|
{
|
|
|
|
if(!::basegfx::fTools::equalZero(fX) || !::basegfx::fTools::equalZero(fY) || !::basegfx::fTools::equalZero(fZ))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
Impl3DHomMatrix aTransMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aTransMat.set(0, 2, fX);
|
|
|
|
aTransMat.set(1, 2, fY);
|
|
|
|
aTransMat.set(2, 2, fZ);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doMulMatrix(aTransMat);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::scale(double fX, double fY, double fZ)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equal(fOne, fX) || !::basegfx::fTools::equal(fOne, fY) ||!::basegfx::fTools::equal(fOne, fZ))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aScaleMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aScaleMat.set(0, 0, fX);
|
|
|
|
aScaleMat.set(1, 1, fY);
|
|
|
|
aScaleMat.set(2, 2, fZ);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doMulMatrix(aScaleMat);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::shearXY(double fSx, double fSy)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equal(fOne, fSx) || !::basegfx::fTools::equal(fOne, fSy))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aShearXYMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aShearXYMat.set(0, 2, fSx);
|
|
|
|
aShearXYMat.set(1, 2, fSy);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doMulMatrix(aShearXYMat);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::shearYZ(double fSy, double fSz)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equal(fOne, fSy) || !::basegfx::fTools::equal(fOne, fSz))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aShearYZMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aShearYZMat.set(1, 0, fSy);
|
|
|
|
aShearYZMat.set(2, 0, fSz);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doMulMatrix(aShearYZMat);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::shearXZ(double fSx, double fSz)
|
|
|
|
{
|
|
|
|
const double fOne(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equal(fOne, fSx) || !::basegfx::fTools::equal(fOne, fSz))
|
|
|
|
{
|
|
|
|
Impl3DHomMatrix aShearXZMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aShearXZMat.set(0, 1, fSx);
|
|
|
|
aShearXZMat.set(2, 1, fSz);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
implPrepareChange();
|
|
|
|
mpM->doMulMatrix(aShearXZMat);
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::frustum(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar)
|
|
|
|
{
|
|
|
|
const double fZero(0.0);
|
|
|
|
const double fOne(1.0);
|
|
|
|
|
|
|
|
if(!::basegfx::fTools::more(fNear, fZero))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
fNear = 0.001;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::more(fFar, fZero))
|
|
|
|
{
|
|
|
|
fFar = fOne;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equal(fNear, fFar))
|
|
|
|
{
|
|
|
|
fFar = fNear + fOne;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equal(fLeft, fRight))
|
|
|
|
{
|
|
|
|
fLeft -= fOne;
|
|
|
|
fRight += fOne;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equal(fTop, fBottom))
|
|
|
|
{
|
|
|
|
fBottom -= fOne;
|
|
|
|
fTop += fOne;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
Impl3DHomMatrix aFrustumMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aFrustumMat.set(0, 0, 2.0 * fNear / (fRight - fLeft));
|
|
|
|
aFrustumMat.set(1, 1, 2.0 * fNear / (fTop - fBottom));
|
|
|
|
aFrustumMat.set(0, 2, (fRight + fLeft) / (fRight - fLeft));
|
|
|
|
aFrustumMat.set(1, 2, (fTop + fBottom) / (fTop - fBottom));
|
|
|
|
aFrustumMat.set(2, 2, -fOne * ((fFar + fNear) / (fFar - fNear)));
|
|
|
|
aFrustumMat.set(3, 2, -fOne);
|
|
|
|
aFrustumMat.set(2, 3, -fOne * ((2.0 * fFar * fNear) / (fFar - fNear)));
|
|
|
|
aFrustumMat.set(3, 3, fZero);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(mpM->getRefCount())
|
|
|
|
mpM->decRefCount();
|
|
|
|
else
|
|
|
|
delete mpM;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM = new Impl3DHomMatrix(aFrustumMat);
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
void B3DHomMatrix::ortho(double fLeft, double fRight, double fBottom, double fTop, double fNear, double fFar)
|
|
|
|
{
|
|
|
|
if(::basegfx::fTools::equal(fNear, fFar))
|
|
|
|
{
|
|
|
|
fFar = fNear + 1.0;
|
2003-10-28 04:26:57 -06:00
|
|
|
}
|
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equal(fLeft, fRight))
|
2003-10-28 04:26:57 -06:00
|
|
|
{
|
2003-11-28 04:18:16 -06:00
|
|
|
fLeft -= 1.0;
|
|
|
|
fRight += 1.0;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equal(fTop, fBottom))
|
|
|
|
{
|
|
|
|
fBottom -= 1.0;
|
|
|
|
fTop += 1.0;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
Impl3DHomMatrix aOrthoMat(get3DIdentityMatrix());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
aOrthoMat.set(0, 0, 2.0 / (fRight - fLeft));
|
|
|
|
aOrthoMat.set(1, 1, 2.0 / (fTop - fBottom));
|
|
|
|
aOrthoMat.set(2, 2, -1.0 * (2.0 / (fFar - fNear)));
|
|
|
|
aOrthoMat.set(0, 3, -1.0 * ((fRight + fLeft) / (fRight - fLeft)));
|
|
|
|
aOrthoMat.set(1, 3, -1.0 * ((fTop + fBottom) / (fTop - fBottom)));
|
|
|
|
aOrthoMat.set(2, 3, -1.0 * ((fFar + fNear) / (fFar - fNear)));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(mpM->getRefCount())
|
|
|
|
mpM->decRefCount();
|
|
|
|
else
|
|
|
|
delete mpM;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
mpM = new Impl3DHomMatrix(aOrthoMat);
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
bool B3DHomMatrix::decompose(B3DTuple& rScale, B3DTuple& rTranslate, B3DTuple& rRotate, B3DTuple& rShear) const
|
2003-11-28 04:18:16 -06:00
|
|
|
{
|
|
|
|
// when perspective is used, decompose is not made here
|
|
|
|
if(!mpM->isLastLineDefault())
|
2004-01-16 03:34:43 -06:00
|
|
|
return false;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// If determinant is zero, decomposition is not possible
|
|
|
|
if(0.0 == mpM->doDeterminant())
|
2004-01-16 03:34:43 -06:00
|
|
|
return false;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// isolate translation
|
|
|
|
rTranslate.setX(mpM->get(0, 3));
|
|
|
|
rTranslate.setY(mpM->get(1, 3));
|
|
|
|
rTranslate.setZ(mpM->get(2, 3));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// correct translate values
|
|
|
|
rTranslate.correctValues();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get scale and shear
|
|
|
|
B3DVector aCol0(mpM->get(0, 0), mpM->get(1, 0), mpM->get(2, 0));
|
|
|
|
B3DVector aCol1(mpM->get(0, 1), mpM->get(1, 1), mpM->get(2, 1));
|
|
|
|
B3DVector aCol2(mpM->get(0, 2), mpM->get(1, 2), mpM->get(2, 2));
|
|
|
|
B3DVector aTemp;
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ScaleX
|
|
|
|
rScale.setX(aCol0.getLength());
|
|
|
|
aCol0.normalize();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ShearXY
|
|
|
|
rShear.setX(aCol0.scalar(aCol1));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equalZero(rShear.getX()))
|
|
|
|
{
|
|
|
|
rShear.setX(0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aTemp.setX(aCol1.getX() - rShear.getX() * aCol0.getX());
|
|
|
|
aTemp.setY(aCol1.getY() - rShear.getX() * aCol0.getY());
|
|
|
|
aTemp.setZ(aCol1.getZ() - rShear.getX() * aCol0.getZ());
|
|
|
|
aCol1 = aTemp;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ScaleY
|
|
|
|
rScale.setY(aCol1.getLength());
|
|
|
|
aCol1.normalize();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
const double fShearX(rShear.getX());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fShearX))
|
|
|
|
{
|
|
|
|
rShear.setX(rShear.getX() / rScale.getY());
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ShearXZ
|
|
|
|
rShear.setY(aCol0.scalar(aCol2));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equalZero(rShear.getY()))
|
|
|
|
{
|
|
|
|
rShear.setY(0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aTemp.setX(aCol2.getX() - rShear.getY() * aCol0.getX());
|
|
|
|
aTemp.setY(aCol2.getY() - rShear.getY() * aCol0.getY());
|
|
|
|
aTemp.setZ(aCol2.getZ() - rShear.getY() * aCol0.getZ());
|
|
|
|
aCol2 = aTemp;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ShearYZ
|
|
|
|
rShear.setZ(aCol1.scalar(aCol2));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equalZero(rShear.getZ()))
|
|
|
|
{
|
|
|
|
rShear.setZ(0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aTemp.setX(aCol2.getX() - rShear.getZ() * aCol1.getX());
|
|
|
|
aTemp.setY(aCol2.getY() - rShear.getZ() * aCol1.getY());
|
|
|
|
aTemp.setZ(aCol2.getZ() - rShear.getZ() * aCol1.getZ());
|
|
|
|
aCol2 = aTemp;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// get ScaleZ
|
|
|
|
rScale.setZ(aCol2.getLength());
|
|
|
|
aCol2.normalize();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
const double fShearY(rShear.getY());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fShearY))
|
|
|
|
{
|
|
|
|
rShear.setY(rShear.getY() / rScale.getZ());
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
const double fShearZ(rShear.getZ());
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(!::basegfx::fTools::equalZero(fShearZ))
|
|
|
|
{
|
|
|
|
rShear.setZ(rShear.getZ() / rScale.getZ());
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// correct shear values
|
|
|
|
rShear.correctValues();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// Coordinate system flip?
|
|
|
|
if(0.0 > aCol0.scalar(aCol1.getPerpendicular(aCol2)))
|
|
|
|
{
|
|
|
|
rScale = -rScale;
|
|
|
|
aCol0 = -aCol0;
|
|
|
|
aCol1 = -aCol1;
|
|
|
|
aCol2 = -aCol2;
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// correct scale values
|
|
|
|
rScale.correctValues(1.0);
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// Get rotations
|
|
|
|
rRotate.setY(asin(-aCol0.getZ()));
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
if(::basegfx::fTools::equalZero(cos(rRotate.getY())))
|
|
|
|
{
|
|
|
|
rRotate.setX(atan2(aCol1.getX(), aCol1.getY()));
|
|
|
|
rRotate.setZ(0.0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rRotate.setX(atan2(aCol1.getZ(), aCol2.getZ()));
|
|
|
|
rRotate.setZ(atan2(aCol0.getY(), aCol0.getX()));
|
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2003-11-28 04:18:16 -06:00
|
|
|
// corrcet rotate values
|
|
|
|
rRotate.correctValues();
|
2003-10-28 04:26:57 -06:00
|
|
|
|
2004-01-16 03:34:43 -06:00
|
|
|
return true;
|
2003-11-28 04:18:16 -06:00
|
|
|
}
|
2003-10-28 04:26:57 -06:00
|
|
|
} // end of namespace basegfx
|
|
|
|
|
|
|
|
// eof
|