AGX Dynamics  2.37.2.0
Vec3.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 
18 #ifndef AGX_VEC3_H
19 #define AGX_VEC3_H
20 
21 #include <agx/Vec3Template.h>
22 #include <agxData/Type.h>
23 
24 namespace agx
25 {
26 
36  typedef Vec3T<Real> Vec3;
37 
38 
41 
42 
43  typedef Vec3T<Int> Vec3i;
44  typedef Vec3T<UInt> Vec3u;
45 
54 
55 #ifndef SWIG
56  const Vec3 X_AXIS( 1.0, 0.0, 0.0 );
57  const Vec3 Y_AXIS( 0.0, 1.0, 0.0 );
58  const Vec3 Z_AXIS( 0.0, 0.0, 1.0 );
59 #endif
60 
61  // Hash function
63  {
64  const agx::UInt32 p1 = 73856093UL;
65  const agx::UInt32 p2 = 19349663UL;
66  const agx::UInt32 p3 = 83492791UL;
67 
68  return (p1 * x) ^ (p2 * y) ^ (p3 * z);
69  }
70 
71  template <typename T>
72  struct HashFn< Vec3T<T> >
73  {
75  {
76  return agx::hash((agx::UInt32)id[0], (agx::UInt32)id[1], (agx::UInt32)id[2]);
77  }
78  };
79 
80  AGX_FORCE_INLINE Vec3i calculateCellId(Real x, Real y, Real z, Real invCellSize)
81  {
82  agx::Vec3i cell;
83  cell[0] = (Vec3i::Type)(x * invCellSize);
84  cell[1] = (Vec3i::Type)(y * invCellSize);
85  cell[2] = (Vec3i::Type)(z * invCellSize);
86 
87  if (x < Real(0.0)) cell[0]--;
88  if (y < Real(0.0)) cell[1]--;
89  if (z < Real(0.0)) cell[2]--;
90 
91  return cell;
92  }
93 
94  AGX_FORCE_INLINE Vec3i calculateCellId(Vec3 position, Real invCellSize)
95  {
96  return calculateCellId(position[0], position[1], position[2], invCellSize);
97  }
98 
99 } // end of namespace agx
100 
101 
104 
105 AGX_TYPE_BINDING(agx::Vec3i8 , "Vec3i")
109 
110 AGX_TYPE_BINDING(agx::Vec3u8 , "Vec3u")
114 
115 #endif
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
Vec3T< Real64 > Vec3d
Definition: Vec3.h:40
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
Vec2i calculateCellId(Real x, Real y, Real invCellSize)
Definition: Vec2.h:72
const Vec3 X_AXIS(1.0, 0.0, 0.0)
#define AGX_FORCE_INLINE
Definition: Object.h:59
Vec3T< UInt > Vec3u
Definition: Vec3.h:44
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< UInt8 > Vec3u8
Definition: Vec3.h:47
agx::UInt32 operator()(const Vec3T< T > &id) const
Definition: Vec3.h:74
Vec3T< UInt64 > Vec3u64
Definition: Vec3.h:53
Vec3T< Int8 > Vec3i8
Definition: Vec3.h:46
Vec3T< Int > Vec3i
Definition: Vec3.h:43
Vec3T< Real32 > Vec3f
Definition: Vec3.h:39
const Vec3 Y_AXIS(0.0, 1.0, 0.0)
const Vec3 Z_AXIS(0.0, 0.0, 1.0)
Vec3T< Int64 > Vec3i64
Definition: Vec3.h:52
double Real
Definition: Real.h:42
Vec3T< UInt32 > Vec3u32
Definition: Vec3.h:51
Vec3T< Int16 > Vec3i16
Definition: Vec3.h:48
uint32_t UInt32
Definition: Integer.h:40
Vec3T< UInt16 > Vec3u16
Definition: Vec3.h:49
Vec3T< Int32 > Vec3i32
Definition: Vec3.h:50