Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/bullet/LinearMath/btTransform.h @ 2753

Last change on this file since 2753 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 7.0 KB
Line 
1/*
2Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
3
4This software is provided 'as-is', without any express or implied warranty.
5In no event will the authors be held liable for any damages arising from the use of this software.
6Permission is granted to anyone to use this software for any purpose,
7including commercial applications, and to alter it and redistribute it freely,
8subject to the following restrictions:
9
101. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
112. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
123. This notice may not be removed or altered from any source distribution.
13*/
14
15
16
17#ifndef btTransform_H
18#define btTransform_H
19
20#include "btVector3.h"
21#include "btMatrix3x3.h"
22
23
24/**@brief The btTransform class supports rigid transforms with only translation and rotation and no scaling/shear.
25 *It can be used in combination with btVector3, btQuaternion and btMatrix3x3 linear algebra classes. */
26class btTransform {
27       
28
29public:
30       
31  /**@brief No initialization constructor */
32        btTransform() {}
33  /**@brief Constructor from btQuaternion (optional btVector3 )
34   * @param q Rotation from quaternion
35   * @param c Translation from Vector (default 0,0,0) */
36        explicit SIMD_FORCE_INLINE btTransform(const btQuaternion& q, 
37                const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0))) 
38                : m_basis(q),
39                m_origin(c)
40        {}
41
42  /**@brief Constructor from btMatrix3x3 (optional btVector3)
43   * @param b Rotation from Matrix
44   * @param c Translation from Vector default (0,0,0)*/
45        explicit SIMD_FORCE_INLINE btTransform(const btMatrix3x3& b, 
46                const btVector3& c = btVector3(btScalar(0), btScalar(0), btScalar(0)))
47                : m_basis(b),
48                m_origin(c)
49        {}
50  /**@brief Copy constructor */
51        SIMD_FORCE_INLINE btTransform (const btTransform& other)
52                : m_basis(other.m_basis),
53                m_origin(other.m_origin)
54        {
55        }
56  /**@brief Assignment Operator */
57        SIMD_FORCE_INLINE btTransform& operator=(const btTransform& other)
58        {
59                m_basis = other.m_basis;
60                m_origin = other.m_origin;
61                return *this;
62        }
63
64
65  /**@brief Set the current transform as the value of the product of two transforms
66   * @param t1 Transform 1
67   * @param t2 Transform 2
68   * This = Transform1 * Transform2 */
69                SIMD_FORCE_INLINE void mult(const btTransform& t1, const btTransform& t2) {
70                        m_basis = t1.m_basis * t2.m_basis;
71                        m_origin = t1(t2.m_origin);
72                }
73
74/*              void multInverseLeft(const btTransform& t1, const btTransform& t2) {
75                        btVector3 v = t2.m_origin - t1.m_origin;
76                        m_basis = btMultTransposeLeft(t1.m_basis, t2.m_basis);
77                        m_origin = v * t1.m_basis;
78                }
79                */
80
81/**@brief Return the transform of the vector */
82        SIMD_FORCE_INLINE btVector3 operator()(const btVector3& x) const
83        {
84                return btVector3(m_basis[0].dot(x) + m_origin.x(), 
85                        m_basis[1].dot(x) + m_origin.y(), 
86                        m_basis[2].dot(x) + m_origin.z());
87        }
88
89  /**@brief Return the transform of the vector */
90        SIMD_FORCE_INLINE btVector3 operator*(const btVector3& x) const
91        {
92                return (*this)(x);
93        }
94
95  /**@brief Return the transform of the btQuaternion */
96        SIMD_FORCE_INLINE btQuaternion operator*(const btQuaternion& q) const
97        {
98                return getRotation() * q;
99        }
100
101  /**@brief Return the basis matrix for the rotation */
102        SIMD_FORCE_INLINE btMatrix3x3&       getBasis()          { return m_basis; }
103  /**@brief Return the basis matrix for the rotation */
104        SIMD_FORCE_INLINE const btMatrix3x3& getBasis()    const { return m_basis; }
105
106  /**@brief Return the origin vector translation */
107        SIMD_FORCE_INLINE btVector3&         getOrigin()         { return m_origin; }
108  /**@brief Return the origin vector translation */
109        SIMD_FORCE_INLINE const btVector3&   getOrigin()   const { return m_origin; }
110
111  /**@brief Return a quaternion representing the rotation */
112        btQuaternion getRotation() const { 
113                btQuaternion q;
114                m_basis.getRotation(q);
115                return q;
116        }
117       
118       
119  /**@brief Set from an array
120   * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
121        void setFromOpenGLMatrix(const btScalar *m)
122        {
123                m_basis.setFromOpenGLSubMatrix(m);
124                m_origin.setValue(m[12],m[13],m[14]);
125        }
126
127  /**@brief Fill an array representation
128   * @param m A pointer to a 15 element array (12 rotation(row major padded on the right by 1), and 3 translation */
129        void getOpenGLMatrix(btScalar *m) const 
130        {
131                m_basis.getOpenGLSubMatrix(m);
132                m[12] = m_origin.x();
133                m[13] = m_origin.y();
134                m[14] = m_origin.z();
135                m[15] = btScalar(1.0);
136        }
137
138  /**@brief Set the translational element
139   * @param origin The vector to set the translation to */
140        SIMD_FORCE_INLINE void setOrigin(const btVector3& origin) 
141        { 
142                m_origin = origin;
143        }
144
145        SIMD_FORCE_INLINE btVector3 invXform(const btVector3& inVec) const;
146
147
148  /**@brief Set the rotational element by btMatrix3x3 */
149        SIMD_FORCE_INLINE void setBasis(const btMatrix3x3& basis)
150        { 
151                m_basis = basis;
152        }
153
154  /**@brief Set the rotational element by btQuaternion */
155        SIMD_FORCE_INLINE void setRotation(const btQuaternion& q)
156        {
157                m_basis.setRotation(q);
158        }
159
160
161  /**@brief Set this transformation to the identity */
162        void setIdentity()
163        {
164                m_basis.setIdentity();
165                m_origin.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0));
166        }
167
168  /**@brief Multiply this Transform by another(this = this * another)
169   * @param t The other transform */
170        btTransform& operator*=(const btTransform& t) 
171        {
172                m_origin += m_basis * t.m_origin;
173                m_basis *= t.m_basis;
174                return *this;
175        }
176
177  /**@brief Return the inverse of this transform */
178        btTransform inverse() const
179        { 
180                btMatrix3x3 inv = m_basis.transpose();
181                return btTransform(inv, inv * -m_origin);
182        }
183
184  /**@brief Return the inverse of this transform times the other transform
185   * @param t The other transform
186   * return this.inverse() * the other */
187        btTransform inverseTimes(const btTransform& t) const; 
188
189  /**@brief Return the product of this transform and the other */
190        btTransform operator*(const btTransform& t) const;
191
192  /**@brief Return an identity transform */
193        static btTransform      getIdentity()
194        {
195                btTransform tr;
196                tr.setIdentity();
197                return tr;
198        }
199       
200private:
201  ///Storage for the rotation
202        btMatrix3x3 m_basis;
203  ///Storage for the translation
204        btVector3   m_origin;
205};
206
207
208SIMD_FORCE_INLINE btVector3
209btTransform::invXform(const btVector3& inVec) const
210{
211        btVector3 v = inVec - m_origin;
212        return (m_basis.transpose() * v);
213}
214
215SIMD_FORCE_INLINE btTransform
216btTransform::inverseTimes(const btTransform& t) const 
217{
218        btVector3 v = t.getOrigin() - m_origin;
219                return btTransform(m_basis.transposeTimes(t.m_basis),
220                        v * m_basis);
221}
222
223SIMD_FORCE_INLINE btTransform
224btTransform::operator*(const btTransform& t) const
225{
226        return btTransform(m_basis * t.m_basis, 
227                (*this)(t.m_origin));
228}
229
230/**@brief Test if two transforms have all elements equal */
231SIMD_FORCE_INLINE bool operator==(const btTransform& t1, const btTransform& t2)
232{
233   return ( t1.getBasis()  == t2.getBasis() &&
234            t1.getOrigin() == t2.getOrigin() );
235}
236
237
238#endif
239
240
241
242
243
244
Note: See TracBrowser for help on using the repository browser.