ScummVM API documentation
dgSphere.h
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 __dgSphere__
23 #define __dgSphere__
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 dgFace;
33 class dgPlane;
34 //class dgCamera;
35 
36 DG_MSC_VECTOR_ALIGMENT
37 class dgSphere: public dgMatrix {
38 public:
39  constexpr dgSphere() : dgMatrix(
40  dgVector(dgFloat32(1.0f), dgFloat32(0.0f), dgFloat32(0.0f),
41  dgFloat32(0.0f)),
42  dgVector(dgFloat32(0.0f), dgFloat32(1.0f), dgFloat32(0.0f),
43  dgFloat32(0.0f)),
44  dgVector(dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(1.0f),
45  dgFloat32(0.0f)),
46  dgVector(dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(0.0f),
47  dgFloat32(1.0f))),
48  m_size(0, 0, 0, 0) {
49  }
50 // dgSphere (const dgQuaternion &quat, const dgVector &position, const dgVector dim = dgVector(0, 0, 0, 0));
51 // dgSphere (const dgMatrix &matrix, const dgVector dim = dgVector(0, 0, 0, 0));
52 
53  dgSphere(const dgQuaternion &quat, const dgVector &position, const dgVector &dim = dgVector(0, 0, 0, 0));
54  dgSphere(const dgMatrix &matrix, const dgVector &dim = dgVector(0, 0, 0, 0));
55 
56  dgSphere &operator= (const dgMatrix &arg);
57  void Scale(dgFloat32 Ws, dgFloat32 Hs, dgFloat32 Bs) ;
58  void SetDimensions(dgFloat32 W, dgFloat32 H, dgFloat32 B);
59  void SetDimensions(const dgFloat32 vertex[], dgInt32 strideInBytes, dgInt32 vertexCount, const dgMatrix *basis = NULL);
60  void SetDimensions(const dgFloat32 vertex[], dgInt32 strideInBytes, const dgInt32 trangles[], dgInt32 indexCount, const dgMatrix *basis);
61 // void SetDimensions (const dgFloat32 vertex[], dgInt32 strideInBytes, const dgInt32 index[], dgInt32 indexCount, const dgMatrix *basis = NULL);
62 
63  // return: 0 if the sphere is wholly inside the viewport
64  // 1 if the sphere is partially inside the viewport
65  // -1 if the sphere is wholly outside the viewport
66 // dgInt32 VisibilityTest (const dgCamera* camera) const;
67 // dgInt32 VisibilityTest (const dgCamera* camera, const dgMatrix &worldMatrix) const;
68 // void Render (const dgCamera* camera, const dgMatrix &transform, unsigned rgb) const;
69 
70 private:
71  /*
72  typedef dgInt32 (dgSphere::*CachedVisibilityTest) (const dgMatrix &point, const dgPlane* plane) const;
73 
74  mutable CachedVisibilityTest planeTest;
75  static CachedVisibilityTest planeTestArray[6];
76 
77  void ChangeCachedVisibilityTest (CachedVisibilityTest fnt);
78  dgInt32 FrontTest (const dgMatrix &point, const dgPlane* plane) const;
79  dgInt32 RearTest (const dgMatrix &point, const dgPlane* plane) const;
80  dgInt32 LeftTest (const dgMatrix &point, const dgPlane* plane) const;
81  dgInt32 RightTest (const dgMatrix &point, const dgPlane* plane) const;
82  dgInt32 TopTest (const dgMatrix &point, const dgPlane* plane) const;
83  dgInt32 BottomTest (const dgMatrix &point, const dgPlane* plane) const;
84  dgInt32 VisibilityTestLow (const dgCamera* camera, const dgMatrix& viewMNatrix) const;
85  */
86 
87 public:
88  dgVector m_size;
89 } DG_GCC_VECTOR_ALIGMENT;
90 
91 
92 const dgSphere &GetIdentitySphere();
93 
94 
95 inline dgSphere &dgSphere::operator= (const dgMatrix &arg) {
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 dgSphere::SetDimensions(dgFloat32 W, dgFloat32 H, dgFloat32 B) {
104  m_size = dgVector(dgAbsf(W), dgAbsf(H), dgAbsf(B), dgSqrt(W * W + H * H + B * B));
105 }
106 
107 inline void dgSphere::Scale(dgFloat32 Ws, dgFloat32 Hs, dgFloat32 Bs) {
108  SetDimensions(m_size.m_x * Ws, m_size.m_y * Hs, m_size.m_z * Bs);
109 }
110 
111 
112 #endif
113 
Definition: dgPlane.h:29
Definition: dgVector.h:86
Definition: dgQuaternion.h:31
Definition: dgSphere.h:37
Definition: dgMatrix.h:41