Tizen 2.1 base
[platform/upstream/libbullet.git] / Extras / RigidBodyGpuPipeline / dynamics / basic_demo / Stubs / AdlTransform.h
1 /*
2 Copyright (c) 2012 Advanced Micro Devices, Inc.  
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose, 
7 including commercial applications, and to alter it and redistribute it freely, 
8 subject to the following restrictions:
9
10 1. 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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14 //Originally written by Takahiro Harada
15
16
17 #ifndef _ADL_TRANSFORM_H
18 #define _ADL_TRANSFORM_H
19
20 #include "AdlMath.h"
21 #include "AdlQuaternion.h"
22 #include "AdlMatrix3x3.h"
23
24 struct Transform
25 {
26         float4 m_translation;
27         Matrix3x3 m_rotation;
28 };
29
30 Transform trSetTransform(const float4& translation, const Quaternion& quat)
31 {
32         Transform tr;
33         tr.m_translation = translation;
34         tr.m_rotation = qtGetRotationMatrix( quat );
35         return tr;
36 }
37
38 Transform trInvert( const Transform& tr )
39 {
40         Transform ans;
41         ans.m_rotation = mtTranspose( tr.m_rotation );
42         ans.m_translation = mtMul1( ans.m_rotation, -tr.m_translation );
43         return ans;
44 }
45
46 Transform trMul(const Transform& trA, const Transform& trB)
47 {
48         Transform ans; 
49         ans.m_rotation = mtMul( trA.m_rotation, trB.m_rotation );
50         ans.m_translation = mtMul1( trA.m_rotation, trB.m_translation ) + trA.m_translation;
51         return ans;
52 }
53
54 float4 trMul1(const Transform& tr, const float4& p)
55 {
56         return mtMul1( tr.m_rotation, p ) + tr.m_translation;
57 }
58
59
60 #endif //_ADL_TRANSFORM_H
61