My Project: dynamics.mod/NewtonDynamics/source/core/dgObb.h Source File

My Project

dgObb.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __dgOOBB_H__
23 #define __dgOOBB_H__
24
25 #include "dgStdafx.h"
26 #include "dgTypes.h"
27 #include "dgVector.h"
28 #include "dgMatrix.h"
29 #include "dgQuaternion.h"
30
31
32 class dgPlane;
33
34 DG_MSC_VECTOR_ALIGMENT
35 class dgObb: public dgMatrix
36 {
37 public:
38 DG_INLINE dgObb (){};
39 dgObb (const dgQuaternion &quat, const dgVector &position, const dgVector& dim = dgVector(0, 0, 0, 0));
40 dgObb (const dgMatrix& matrix, const dgVector& dim = dgVector(0, 0, 0, 0));
41
42 dgObb &operator= (const dgMatrix &arg);
43 void Scale (dgFloat32 Ws, dgFloat32 Hs, dgFloat32 Bs) ;
44 void SetDimensions (dgFloat32 W, dgFloat32 H, dgFloat32 B);
45 void SetDimensions (const dgFloat32 vertex[], dgInt32 strideInBytes, dgInt32 vertexCount, const dgMatrix *basis = NULL);
46 void SetDimensions (const dgFloat32 vertex[], dgInt32 strideInBytes, const dgInt32 triangles[], dgInt32 indexCount, const dgMatrix *basis);
47 // void SetDimensions (const dgFloat32 vertex[], dgInt32 strideInBytes, const dgInt32 index[], dgInt32 indexCount, const dgMatrix *basis = NULL);
48
49 // return: 0 if the sphere is wholly inside the view port
50 // 1 if the sphere is partially inside the view port
51 // -1 if the sphere is wholly outside the view port
52 // dgInt32 VisibilityTest (const dgCamera* camera) const;
53 // dgInt32 VisibilityTest (const dgCamera* camera, const dgMatrix &worldMatrix) const;
54 // void Render (const dgCamera* camera, const dgMatrix &transform, unsigned rgb) const;
55
56 private:
57 /*
58 typedef dgInt32 (dgSphere::*CachedVisibilityTest) (const dgMatrix &point, const dgPlane* plane) const;
59
60 mutable CachedVisibilityTest planeTest;
61 static CachedVisibilityTest planeTestArray[6];
62
63 void ChangeCachedVisibilityTest (CachedVisibilityTest fnt);
64 dgInt32 FrontTest (const dgMatrix &point, const dgPlane* plane) const;
65 dgInt32 RearTest (const dgMatrix &point, const dgPlane* plane) const;
66 dgInt32 LeftTest (const dgMatrix &point, const dgPlane* plane) const;
67 dgInt32 RightTest (const dgMatrix &point, const dgPlane* plane) const;
68 dgInt32 TopTest (const dgMatrix &point, const dgPlane* plane) const;
69 dgInt32 BottomTest (const dgMatrix &point, const dgPlane* plane) const;
70 dgInt32 VisibilityTestLow (const dgCamera* camera, const dgMatrix& viewMNatrix) const;
71 */
72
73 public:
74 dgVector m_size;
75 } DG_GCC_VECTOR_ALIGMENT;
76
77
78 inline dgObb::dgObb (const dgQuaternion &quat, const dgVector &position, const dgVector& dim)
79 :dgMatrix(quat, position)
80 {
81 SetDimensions (dim.m_x, dim.m_y, dim.m_z);
82 dgAssert (0);
83 }
84
85 inline dgObb::dgObb(const dgMatrix& matrix, const dgVector& dim)
86 :dgMatrix(matrix)
87 {
88 SetDimensions (dim.m_x, dim.m_y, dim.m_z);
89 }
90
91
92
93
94 inline dgObb &dgObb::operator= (const dgMatrix &arg)
95 {
96 m_front = arg.m_front;
97 m_up = arg.m_up;
98 m_right = arg.m_right;
99 m_posit = arg.m_posit;
100 return *this;
101 }
102
103 inline void dgObb::SetDimensions (dgFloat32 W, dgFloat32 H, dgFloat32 B)
104 {
105 m_size = dgVector (dgAbsf(W), dgAbsf(H), dgAbsf(B), dgSqrt (W * W + H * H + B * B));
106 }
107
108 inline void dgObb::Scale (dgFloat32 Ws, dgFloat32 Hs, dgFloat32 Bs)
109 {
110 SetDimensions (m_size.m_x * Ws, m_size.m_y * Hs, m_size.m_z * Bs);
111 }
112
113
114 #endif
115
dgPlane
Definition: dgPlane.h:29
dgMatrix::m_front
dgVector m_front
Definition: dgMatrix.h:101
dgObb::Scale
void Scale(dgFloat32 Ws, dgFloat32 Hs, dgFloat32 Bs)
Definition: dgObb.h:108
dgAbsf
DG_INLINE dgFloat32 dgAbsf(dgFloat32 x)
Definition: dgTypes.h:627
dgObb::dgObb
DG_INLINE dgObb()
Definition: dgObb.h:38
dgObb::SetDimensions
void SetDimensions(dgFloat32 W, dgFloat32 H, dgFloat32 B)
Definition: dgObb.h:103
dgObb
Definition: dgObb.h:35
DG_INLINE
#define DG_INLINE
Definition: dgTypes.h:178
dgAssert
#define dgAssert(x)
Definition: dgTypes.h:158
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
dgVector
Definition: dgVector.h:639
dgVector::m_z
dgFloat32 m_z
Definition: dgVector.h:1027
dgQuaternion
Definition: dgQuaternion.h:31
dgMatrix.h
dgVector.h
dgObb::m_size
dgVector m_size
Definition: dgObb.h:74
DG_MSC_VECTOR_ALIGMENT
#define DG_MSC_VECTOR_ALIGMENT
Definition: dgTypes.h:194
dgVector::m_x
dgFloat32 m_x
Definition: dgVector.h:1025
dgStdafx.h
DG_GCC_VECTOR_ALIGMENT
dgObb DG_GCC_VECTOR_ALIGMENT
dgMatrix::m_right
dgVector m_right
Definition: dgMatrix.h:103
dgMatrix::m_up
dgVector m_up
Definition: dgMatrix.h:102
dgQuaternion.h
dgMatrix
Definition: dgMatrix.h:40
dgMatrix::m_posit
dgVector m_posit
Definition: dgMatrix.h:104
dgSqrt
#define dgSqrt(x)
Definition: dgTypes.h:691
dgTypes.h
dgObb::operator=
dgObb & operator=(const dgMatrix &arg)
Definition: dgObb.h:94
dgVector::m_y
dgFloat32 m_y
Definition: dgVector.h:1026