1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _BGFX_MATRIX_B3DHOMMATRIX_HXX 25 #define _BGFX_MATRIX_B3DHOMMATRIX_HXX 26 27 #include <sal/types.h> 28 #include <basegfx/point/b3dpoint.hxx> 29 #include <basegfx/vector/b3dvector.hxx> 30 #include <o3tl/cow_wrapper.hxx> 31 #include <basegfx/basegfxdllapi.h> 32 33 namespace basegfx 34 { 35 class B3DTuple; 36 class Impl3DHomMatrix; 37 38 class BASEGFX_DLLPUBLIC B3DHomMatrix 39 { 40 public: 41 typedef o3tl::cow_wrapper< Impl3DHomMatrix > ImplType; 42 43 private: 44 ImplType mpImpl; 45 46 public: 47 B3DHomMatrix(); 48 B3DHomMatrix(const B3DHomMatrix& rMat); 49 ~B3DHomMatrix(); 50 51 /// unshare this matrix with all internally shared instances 52 void makeUnique(); 53 54 double get(sal_uInt16 nRow, sal_uInt16 nColumn) const; 55 void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue); 56 57 // test if last line is default to see if last line needs to be 58 // involved in calculations 59 bool isLastLineDefault() const; 60 61 bool isIdentity() const; 62 /// Reset to the identity matrix 63 void identity(); 64 65 bool isInvertible() const; 66 /// Invert the matrix (if possible) 67 bool invert(); 68 69 bool isNormalized() const; 70 /// Normalize (i.e. force w=1) the matrix 71 void normalize(); 72 73 /// Calc the matrix determinant 74 double determinant() const; 75 76 /// Calc the matrix trace 77 double trace() const; 78 79 /// Transpose the matrix 80 void transpose(); 81 82 /// Rotation 83 void rotate(double fAngleX,double fAngleY,double fAngleZ); 84 85 /// Translation 86 void translate(double fX, double fY, double fZ); 87 88 /// Scaling 89 void scale(double fX, double fY, double fZ); 90 91 // Shearing-Matrices 92 void shearXY(double fSx, double fSy); 93 void shearYZ(double fSy, double fSz); 94 void shearXZ(double fSx, double fSz); 95 96 // Projection matrices, used for converting between eye and 97 // clip coordinates 98 void frustum(double fLeft = -1.0, double fRight = 1.0, 99 double fBottom = -1.0, double fTop = 1.0, 100 double fNear = 0.001, double fFar = 1.0); 101 102 void ortho(double fLeft = -1.0, double fRight = 1.0, 103 double fBottom = -1.0, double fTop = 1.0, 104 double fNear = 0.0, double fFar = 1.0); 105 106 // build orientation matrix 107 void orientation( 108 B3DPoint aVRP = B3DPoint(0.0,0.0,1.0), 109 B3DVector aVPN = B3DVector(0.0,0.0,1.0), 110 B3DVector aVUV = B3DVector(0.0,1.0,0.0)); 111 112 // addition, subtraction 113 B3DHomMatrix& operator+=(const B3DHomMatrix& rMat); 114 B3DHomMatrix& operator-=(const B3DHomMatrix& rMat); 115 116 // comparison 117 bool operator==(const B3DHomMatrix& rMat) const; 118 bool operator!=(const B3DHomMatrix& rMat) const; 119 120 // multiplication, division by constant value 121 B3DHomMatrix& operator*=(double fValue); 122 B3DHomMatrix& operator/=(double fValue); 123 124 // matrix multiplication (from the left) 125 B3DHomMatrix& operator*=(const B3DHomMatrix& rMat); 126 127 // assignment operator 128 B3DHomMatrix& operator=(const B3DHomMatrix& rMat); 129 130 // decomposition 131 bool decompose(B3DTuple& rScale, B3DTuple& rTranslate, B3DTuple& rRotate, B3DTuple& rShear) const; 132 }; 133 134 // addition, subtraction operator +(const B3DHomMatrix & rMatA,const B3DHomMatrix & rMatB)135 inline B3DHomMatrix operator+(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 136 { 137 B3DHomMatrix aSum(rMatA); 138 aSum += rMatB; 139 return aSum; 140 } 141 operator -(const B3DHomMatrix & rMatA,const B3DHomMatrix & rMatB)142 inline B3DHomMatrix operator-(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 143 { 144 B3DHomMatrix aDiv(rMatA); 145 aDiv -= rMatB; 146 return aDiv; 147 } 148 149 // multiplication, division by constant value operator *(const B3DHomMatrix & rMat,double fValue)150 inline B3DHomMatrix operator*(const B3DHomMatrix& rMat, double fValue) 151 { 152 B3DHomMatrix aNew(rMat); 153 aNew *= fValue; 154 return aNew; 155 } 156 operator /(const B3DHomMatrix & rMat,double fValue)157 inline B3DHomMatrix operator/(const B3DHomMatrix& rMat, double fValue) 158 { 159 B3DHomMatrix aNew(rMat); 160 aNew *= 1.0 / fValue; 161 return aNew; 162 } 163 operator *(const B3DHomMatrix & rMatA,const B3DHomMatrix & rMatB)164 inline B3DHomMatrix operator*(const B3DHomMatrix& rMatA, const B3DHomMatrix& rMatB) 165 { 166 B3DHomMatrix aMul(rMatB); 167 aMul *= rMatA; 168 return aMul; 169 } 170 } // end of namespace basegfx 171 172 #endif /* _BGFX_MATRIX_B3DHOMMATRIX_HXX */ 173