1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _BGFX_MATRIX_B3DHOMMATRIX_HXX 29 #define _BGFX_MATRIX_B3DHOMMATRIX_HXX 30 31 #include <sal/types.h> 32 #include <basegfx/point/b3dpoint.hxx> 33 #include <basegfx/vector/b3dvector.hxx> 34 #include <o3tl/cow_wrapper.hxx> 35 36 namespace basegfx 37 { 38 class B3DTuple; 39 class Impl3DHomMatrix; 40 41 class B3DHomMatrix 42 { 43 public: 44 typedef o3tl::cow_wrapper< Impl3DHomMatrix > ImplType; 45 46 private: 47 ImplType mpImpl; 48 49 public: 50 B3DHomMatrix(); 51 B3DHomMatrix(const B3DHomMatrix& rMat); 52 ~B3DHomMatrix(); 53 54 /// unshare this matrix with all internally shared instances 55 void makeUnique(); 56 57 double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; 58 void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); 59 60 // test if last line is default to see if last line needs to be 61 // involved in calculations 62 bool isLastLineDefault() const; 63 64 bool isIdentity() const; 65 /// Reset to the identity matrix 66 void identity(); 67 68 bool isInvertible() const; 69 /// Invert the matrix (if possible) 70 bool invert(); 71 72 bool isNormalized() const; 73 /// Normalize (i.e. force w=1) the matrix 74 void normalize(); 75 76 /// Calc the matrix determinant 77 double determinant() const; 78 79 /// Calc the matrix trace 80 double trace() const; 81 82 /// Transpose the matrix 83 void transpose(); 84 85 /// Rotation 86 void rotate(double fAngleX,double fAngleY,double fAngleZ); 87 88 /// Translation 89 void translate(double fX, double fY, double fZ); 90 91 /// Scaling 92 void scale(double fX, double fY, double fZ); 93 94 // Shearing-Matrices 95 void shearXY(double fSx, double fSy); 96 void shearYZ(double fSy, double fSz); 97 void shearXZ(double fSx, double fSz); 98 99 // Projection matrices, used for converting between eye and 100 // clip coordinates 101 void frustum(double fLeft = -1.0, double fRight = 1.0, 102 double fBottom = -1.0, double fTop = 1.0, 103 double fNear = 0.001, double fFar = 1.0); 104 105 void ortho(double fLeft = -1.0, double fRight = 1.0, 106 double fBottom = -1.0, double fTop = 1.0, 107 double fNear = 0.0, double fFar = 1.0); 108 109 // build orientation matrix 110 void orientation( 111 B3DPoint aVRP = B3DPoint(0.0,0.0,1.0), 112 B3DVector aVPN = B3DVector(0.0,0.0,1.0), 113 B3DVector aVUV = B3DVector(0.0,1.0,0.0)); 114 115 // addition, subtraction 116 B3DHomMatrix& operator+=(const B3DHomMatrix& rMat); 117 B3DHomMatrix& operator-=(const B3DHomMatrix& rMat); 118 119 // comparison 120 bool operator==(const B3DHomMatrix& rMat) const; 121 bool operator!=(const B3DHomMatrix& rMat) const; 122 123 // multiplication, division by constant value 124 B3DHomMatrix& operator*=(double fValue); 125 B3DHomMatrix& operator/=(double fValue); 126 127 // matrix multiplication (from the left) 128 B3DHomMatrix& operator*=(const B3DHomMatrix& rMat); 129 130 // assignment operator 131 B3DHomMatrix& operator=(const B3DHomMatrix& rMat); 132 133 // decomposition 134 bool decompose(B3DTuple& rScale, B3DTuple& rTranslate, B3DTuple& rRotate, B3DTuple& rShear) const; 135 }; 136 137 // addition, subtraction 138 inline B3DHomMatrix operator+(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 139 { 140 B3DHomMatrix aSum(rMatA); 141 aSum += rMatB; 142 return aSum; 143 } 144 145 inline B3DHomMatrix operator-(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 146 { 147 B3DHomMatrix aDiv(rMatA); 148 aDiv -= rMatB; 149 return aDiv; 150 } 151 152 // multiplication, division by constant value 153 inline B3DHomMatrix operator*(const B3DHomMatrix& rMat, double fValue) 154 { 155 B3DHomMatrix aNew(rMat); 156 aNew *= fValue; 157 return aNew; 158 } 159 160 inline B3DHomMatrix operator/(const B3DHomMatrix& rMat, double fValue) 161 { 162 B3DHomMatrix aNew(rMat); 163 aNew *= 1.0 / fValue; 164 return aNew; 165 } 166 167 inline B3DHomMatrix operator*(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 168 { 169 B3DHomMatrix aMul(rMatB); 170 aMul *= rMatA; 171 return aMul; 172 } 173 } // end of namespace basegfx 174 175 #endif /* _BGFX_MATRIX_B3DHOMMATRIX_HXX */ 176