28 #include "dgSimd_Instrutions.h" 30 #define dgCheckVector(x) (dgCheckFloat(x[0]) && dgCheckFloat(x[1]) && dgCheckFloat(x[2]) && dgCheckFloat(x[3])) 37 dgTemplateVector(
const T *ptr);
38 constexpr dgTemplateVector(T m_x, T m_y, T m_z, T m_w);
39 dgTemplateVector Scale(T s)
const;
40 dgTemplateVector Scale4(T s)
const;
42 T &operator[](dgInt32 i);
43 const T &operator[](dgInt32 i)
const;
45 dgTemplateVector operator+ (
const dgTemplateVector &A)
const;
46 dgTemplateVector operator- (
const dgTemplateVector &A)
const;
47 dgTemplateVector &operator+= (
const dgTemplateVector &A);
48 dgTemplateVector &operator-= (
const dgTemplateVector &A);
51 T operator% (
const dgTemplateVector &A)
const;
54 dgTemplateVector operator* (
const dgTemplateVector &B)
const;
57 dgTemplateVector Add4(
const dgTemplateVector &A)
const;
58 dgTemplateVector Sub4(
const dgTemplateVector &A)
const;
59 T DotProduct4(
const dgTemplateVector &A)
const;
60 dgTemplateVector CrossProduct4(
const dgTemplateVector &A,
const dgTemplateVector &B)
const;
63 dgTemplateVector CompProduct(
const dgTemplateVector &A)
const;
66 dgTemplateVector CompProduct4(
const dgTemplateVector &A)
const;
71 dgTrace((
"%f %f %f %f\n", m_x, m_y, m_z, m_w));
75 DG_CLASS_ALLOCATOR(allocator)
85 DG_MSC_VECTOR_ALIGMENT
89 #ifdef DG_BUILD_SIMD_CODE 94 constexpr
dgVector(dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w);
97 dgFloat32 DotProductSimd(
const dgVector &A)
const;
98 dgVector CrossProductSimd(
const dgVector &A)
const;
99 dgVector CompProductSimd(
const dgVector &A)
const;
101 } DG_GCC_VECTOR_ALIGMENT;
103 DG_MSC_VECTOR_ALIGMENT
110 #ifndef __USE_DOUBLE_PRECISION__ 113 dgBigVector(dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w);
114 } DG_GCC_VECTOR_ALIGMENT;
119 : m_x(ptr[0]), m_y(ptr[1]), m_z(ptr[2]), m_w(0.0f) {
125 : m_x(x), m_y(y), m_z(z), m_w(w) {
131 NEWTON_ASSERT(i < 4);
132 NEWTON_ASSERT(i >= 0);
138 NEWTON_ASSERT(i < 4);
139 NEWTON_ASSERT(i >= 0);
178 NEWTON_ASSERT(dgCheckVector((*
this)));
185 return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z;
192 m_z * B.m_x - m_x * B.m_z,
193 m_x * B.m_y - m_y * B.m_x, m_w);
210 return m_x * A.m_x + m_y * A.m_y + m_z * A.m_z + m_w * A.m_w;
219 for (dgInt32 i = 0; i < 4; i ++) {
223 array[3][i] = T(1.0f);
228 for (dgInt32 i = 0; i < 4; i ++) {
230 for (dgInt32 j = 0; j < 3; j ++) {
232 for (dgInt32 k = 0; k < 4; k ++) {
234 cofactor[j][k0] = array[j][k];
239 T x = cofactor[0][0] * (cofactor[1][1] * cofactor[2][2] - cofactor[1][2] * cofactor[2][1]);
240 T y = cofactor[0][1] * (cofactor[1][2] * cofactor[2][0] - cofactor[1][0] * cofactor[2][2]);
241 T z = cofactor[0][2] * (cofactor[1][0] * cofactor[2][1] - cofactor[1][1] * cofactor[2][0]);
244 normal[i] = sign * det;
267 NEWTON_ASSERT(dgCheckVector((*
this)));
270 DG_INLINE dgVector::dgVector(
const dgFloat32 *ptr)
272 NEWTON_ASSERT(dgCheckVector((*
this)));
277 NEWTON_ASSERT(dgCheckVector((*
this)));
280 #ifdef DG_BUILD_SIMD_CODE 281 DG_INLINE dgVector::dgVector(
const simd_type &val) {
282 NEWTON_ASSERT((dgUnsigned64(
this) & 0x0f) == 0);
283 (simd_type &) *
this = val;
284 NEWTON_ASSERT(dgCheckVector((*
this)));
288 constexpr DG_INLINE dgVector::dgVector(dgFloat32 x, dgFloat32 y, dgFloat32 z, dgFloat32 w)
292 DG_INLINE dgFloat32 dgVector::DotProductSimd(
const dgVector &A)
const {
293 #ifdef DG_BUILD_SIMD_CODE 297 (simd_type &) tmp = simd_mul_v((simd_type &) *
this, (simd_type &)A);
301 return tmp.m_x + tmp.m_y + tmp.m_z;
303 return dgFloat32(0.0f);
308 #ifdef DG_BUILD_SIMD_CODE 310 return dgVector(simd_mul_sub_v(simd_mul_v(simd_permut_v((simd_type &)e21, (simd_type &)e21, PURMUT_MASK(3, 0, 2, 1)), simd_permut_v((simd_type &)e10, (simd_type &)e10, PURMUT_MASK(3, 1, 0, 2))),
311 simd_permut_v((simd_type &)e21, (simd_type &)e21, PURMUT_MASK(3, 1, 0, 2)), simd_permut_v((simd_type &)e10, (simd_type &)e10, PURMUT_MASK(3, 0, 2, 1))));
313 return dgVector(dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(0.0f));
320 #ifdef DG_BUILD_SIMD_CODE 321 return dgVector(simd_mul_v((simd_type &) *
this, (simd_type &)A));
323 return dgVector(dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(0.0f), dgFloat32(0.0f));
327 DG_INLINE dgBigVector::dgBigVector()
331 DG_INLINE dgBigVector::dgBigVector(
const dgVector &v)
333 NEWTON_ASSERT(dgCheckVector((*
this)));
338 NEWTON_ASSERT(dgCheckVector((*
this)));
341 DG_INLINE dgBigVector::dgBigVector(
const dgFloat32 *ptr)
343 NEWTON_ASSERT(dgCheckVector((*
this)));
346 #ifndef __USE_DOUBLE_PRECISION__ 347 DG_INLINE dgBigVector::dgBigVector(
const dgFloat64 *ptr)
349 NEWTON_ASSERT(dgCheckVector((*
this)));
353 DG_INLINE dgBigVector::dgBigVector(dgFloat64 x, dgFloat64 y, dgFloat64 z, dgFloat64 w)
355 NEWTON_ASSERT(dgCheckVector((*
this)));
Definition: dgVector.h:86
Definition: dgVector.h:34
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: dgVector.h:104