Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SbMatrix.h
1 #ifndef COIN_SBMATRIX_H
2 #define COIN_SBMATRIX_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 #include <Inventor/SbBasic.h>
38 
39 class SbLine;
40 class SbRotation;
41 class SbVec3f;
42 class SbVec4f;
43 class SbDPMatrix;
44 
45 typedef float SbMat[4][4];
46 
47 class COIN_DLL_API SbMatrix {
48 public:
49  SbMatrix(void);
50  SbMatrix(const float a11, const float a12, const float a13, const float a14,
51  const float a21, const float a22, const float a23, const float a24,
52  const float a31, const float a32, const float a33, const float a34,
53  const float a41, const float a42, const float a43, const float a44);
54  SbMatrix(const SbMat & matrix);
55  SbMatrix(const SbMat * matrix);
56  explicit SbMatrix(const SbDPMatrix & matrix);
57  ~SbMatrix(void);
58 
59  void setValue(const SbMat & m);
60  void setValue(const SbDPMatrix & m);
61  void setValue(const float * pMat);
62  const SbMat & getValue(void) const;
63 
64  void makeIdentity(void);
65  void setRotate(const SbRotation & q);
66  SbMatrix inverse(void) const;
67  float det3(int r1, int r2, int r3,
68  int c1, int c2, int c3) const;
69  float det3(void) const;
70  float det4(void) const;
71 
72  SbBool equals(const SbMatrix & m, float tolerance) const;
73 
74 
75  void getValue(SbMat & m) const;
76  static SbMatrix identity(void);
77  void setScale(const float s);
78  void setScale(const SbVec3f & s);
79  void setTranslate(const SbVec3f & t);
80  void setTransform(const SbVec3f & t, const SbRotation & r, const SbVec3f & s);
81  void setTransform(const SbVec3f & t, const SbRotation & r, const SbVec3f & s,
82  const SbRotation & so);
83  void setTransform(const SbVec3f & translation,
84  const SbRotation & rotation, const SbVec3f & scaleFactor,
85  const SbRotation & scaleOrientation, const SbVec3f & center);
86  void getTransform(SbVec3f & t, SbRotation & r,
87  SbVec3f & s, SbRotation & so) const;
88  void getTransform(SbVec3f & translation, SbRotation & rotation,
89  SbVec3f & scaleFactor, SbRotation & scaleOrientation,
90  const SbVec3f & center) const;
91  SbBool factor(SbMatrix & r, SbVec3f & s, SbMatrix & u, SbVec3f & t,
92  SbMatrix & proj) const;
93  SbBool LUDecomposition(int index[4], float & d);
94  void LUBackSubstitution(int index[4], float b[4]) const;
95  SbMatrix transpose(void) const;
96  SbMatrix & multRight(const SbMatrix & m);
97  SbMatrix & multLeft(const SbMatrix & m);
98  void multMatrixVec(const SbVec3f & src, SbVec3f & dst) const;
99  void multVecMatrix(const SbVec3f & src, SbVec3f & dst) const;
100  void multDirMatrix(const SbVec3f & src, SbVec3f & dst) const;
101  void multLineMatrix(const SbLine & src, SbLine & dst) const;
102  void multVecMatrix(const SbVec4f & src, SbVec4f & dst) const;
103 
104  void print(FILE * fp) const;
105 
106  operator float*(void);
107  operator SbMat&(void);
108 
109  float * operator [](int i);
110  const float * operator [](int i) const;
111 
112  SbMatrix & operator =(const SbMat & m);
113  SbMatrix & operator =(const SbMatrix & m);
114  SbMatrix & operator =(const SbRotation & q);
115  SbMatrix & operator *=(const SbMatrix & m);
116 
117  friend COIN_DLL_API SbMatrix operator *(const SbMatrix & m1, const SbMatrix & m2);
118  friend COIN_DLL_API int operator ==(const SbMatrix & m1, const SbMatrix & m2);
119  friend COIN_DLL_API int operator !=(const SbMatrix & m1, const SbMatrix & m2);
120 
121 private:
122  float matrix[4][4];
123 
124  void operator /=(const float v);
125  void operator *=(const float v);
126 };
127 
128 COIN_DLL_API SbMatrix operator *(const SbMatrix & m1, const SbMatrix & m2);
129 COIN_DLL_API int operator ==(const SbMatrix & m1, const SbMatrix & m2);
130 COIN_DLL_API int operator !=(const SbMatrix & m1, const SbMatrix & m2);
131 
132 #endif // !COIN_SBMATRIX_H
The SbVec4f class is a 4 dimensional vector with floating point coordinates.
Definition: SbVec4f.h:49
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
The SbRotation class represents a rotation in 3D space.
Definition: SbRotation.h:44
The SbVec3f class is a 3 dimensional vector with floating point coordinates.
Definition: SbVec3f.h:51
The SbLine class represents a line in 3D space.
Definition: SbLine.h:41
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
SbVec2s operator*(const SbVec2s &v, int d)
The SbDPMatrix class is a 4x4 dimensional representation of a double-precision matrix.
Definition: SbDPMatrix.h:47