Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / Opcode / Ice / IceHPoint.cpp
1 /*
2  *      ICE / OPCODE - Optimized Collision Detection
3  * http://www.codercorner.com/Opcode.htm
4  * 
5  * Copyright (c) 2001-2008 Pierre Terdiman,  pierre@codercorner.com
6
7 This software is provided 'as-is', without any express or implied warranty.
8 In no event will the authors be held liable for any damages arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose, 
10 including commercial applications, and to alter it and redistribute it freely, 
11 subject to the following restrictions:
12
13 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.
14 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
15 3. This notice may not be removed or altered from any source distribution.
16 */
17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18 /**
19  *      Contains code for homogeneous points.
20  *      \file           IceHPoint.cpp
21  *      \author         Pierre Terdiman
22  *      \date           April, 4, 2000
23  */
24 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25
26 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27 /**
28  *      Homogeneous point.
29  *
30  *      Use it:
31  *      - for clipping in homogeneous space (standard way)
32  *      - to differentiate between points (w=1) and vectors (w=0).
33  *      - in some cases you can also use it instead of Point for padding reasons.
34  *
35  *      \class          HPoint
36  *      \author         Pierre Terdiman
37  *      \version        1.0
38  *      \warning        No cross-product in 4D.
39  *      \warning        HPoint *= Matrix3x3 doesn't exist, the matrix is first casted to a 4x4
40  */
41 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42
43 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
44 // Precompiled Header
45 #include "Stdafx.h"
46
47 using namespace Opcode;
48
49 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 // Point Mul = HPoint * Matrix3x3;
51 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52 Point HPoint::operator*(const Matrix3x3& mat) const
53 {
54         return Point(
55         x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0],
56         x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1],
57         x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] );
58 }
59
60 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 // HPoint Mul = HPoint * Matrix4x4;
62 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63 HPoint HPoint::operator*(const Matrix4x4& mat) const
64 {
65         return HPoint(
66         x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0],
67         x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1],
68         x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2],
69         x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3]);
70 }
71
72 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 // HPoint *= Matrix4x4
74 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 HPoint& HPoint::operator*=(const Matrix4x4& mat)
76 {
77         float xp = x * mat.m[0][0] + y * mat.m[1][0] + z * mat.m[2][0] + w * mat.m[3][0];
78         float yp = x * mat.m[0][1] + y * mat.m[1][1] + z * mat.m[2][1] + w * mat.m[3][1];
79         float zp = x * mat.m[0][2] + y * mat.m[1][2] + z * mat.m[2][2] + w * mat.m[3][2];
80         float wp = x * mat.m[0][3] + y * mat.m[1][3] + z * mat.m[2][3] + w * mat.m[3][3];
81
82         x = xp; y = yp; z = zp; w = wp;
83
84         return  *this;
85 }
86
87