Newton Dynamics  4.00
ndSpatialVector.h
1 /* Copyright (c) <2003-2022> <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 __ND_SPATIAL_VECTOR_H__
23 #define __ND_SPATIAL_VECTOR_H__
24 
25 #include "ndCoreStdafx.h"
26 #include "ndTypes.h"
27 #include "ndVector.h"
28 
29 D_MSV_NEWTON_ALIGN_32
31 {
32  public:
33  D_OPERATOR_NEW_AND_DELETE
34 
35  inline ndSpatialVector()
36  {
37  }
38 
39  inline ndSpatialVector(const ndFloat64 a)
40  :m_data(a)
41  {
42  }
43 
44  inline ndSpatialVector(const ndSpatialVector& copy)
45  :m_data(copy.m_data)
46  {
47  }
48 
49  inline ndSpatialVector(const ndBigVector& low, const ndBigVector& high)
50  :m_data(low, high)
51  {
52  }
53 
54  inline ~ndSpatialVector()
55  {
56  }
57 
58  inline ndFloat64& operator[] (ndInt32 i)
59  {
60  ndAssert(i >= 0);
61  ndAssert(i < ndInt32(sizeof(m_f) / sizeof(m_f[0])));
62  return ((ndFloat64*)&m_f)[i];
63  }
64 
65  inline const ndFloat64& operator[] (ndInt32 i) const
66  {
67  ndAssert(i >= 0);
68  ndAssert(i < ndInt32 (sizeof(m_f) / sizeof(m_f[0])));
69  return ((ndFloat64*)&m_f)[i];
70  }
71 
72  inline ndSpatialVector operator+ (const ndSpatialVector& A) const
73  {
74  return ndSpatialVector(m_data.m_low + A.m_data.m_low, m_data.m_high + A.m_data.m_high);
75  }
76 
77  inline ndSpatialVector operator*(const ndSpatialVector& A) const
78  {
79  return ndSpatialVector(m_data.m_low * A.m_data.m_low, m_data.m_high * A.m_data.m_high);
80  }
81 
82  inline ndFloat64 DotProduct(const ndSpatialVector& v) const
83  {
84  ndAssert(m_f[6] == ndFloat32(0.0f));
85  ndAssert(m_f[7] == ndFloat32(0.0f));
86  ndBigVector tmp(m_data.m_low * v.m_data.m_low + m_data.m_high * v.m_data.m_high);
87  return tmp.AddHorizontal().GetScalar();
88  }
89 
90  inline ndSpatialVector Scale(ndFloat64 s) const
91  {
92  ndBigVector tmp(s);
93  return ndSpatialVector(m_data.m_low * tmp, m_data.m_high * tmp);
94  }
95 
96  struct ndData
97  {
98  inline ndData(const ndFloat64 a)
99  :m_low(a)
100  ,m_high(a)
101  {
102  }
103 
104  inline ndData(const ndData& data)
105  :m_low(data.m_low)
106  ,m_high(data.m_high)
107  {
108  }
109 
110  inline ndData(const ndBigVector& low, const ndBigVector& high)
111  :m_low(low)
112  ,m_high(high)
113  {
114  }
115 
116  ndBigVector m_low;
117  ndBigVector m_high;
118  };
119 
120  union
121  {
122  ndFloat64 m_f[8];
123  ndData m_data;
124  };
125 
126  D_CORE_API static ndSpatialVector m_zero;
127 } D_GCC_NEWTON_ALIGN_32;
128 
129 #endif
ndSpatialVector::ndData
Definition: ndSpatialVector.h:97
ndSpatialVector
Definition: ndSpatialVector.h:31
ndBigVector
Definition: ndVectorArmNeon.h:463