AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
agx/Vec3.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
24namespace agx
25{
26
37
38
41
42
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 template<typename T>
62 struct HashFn<Vec3T<T>>
63 {
64 inline UInt32 operator()(const Vec3T<T>& id) const
65 {
66 return hash((UInt32)id[0], (UInt32)id[1], (UInt32)id[2]);
67 }
68 };
69
70 template<>
72 {
73 inline UInt32 operator()( const Vec3T<UInt64>& id ) const
74 {
75 return hash( id.x(), id.y(), id.z() );
76 }
77 };
78
79 inline Vec3u64 hash( const Vec3d& v, Real eps )
80 {
81 return { spatialHash( v.x(), eps ), spatialHash( v.y(), eps ), spatialHash( v.z(), eps ) };
82 }
83
84 inline UInt64 hash64( const Vec3u64& v )
85 {
86 return hash64( v.x(), v.y(), v.z() );
87 }
88
89 inline UInt32 hash( const Vec3u64& v )
90 {
91 return hash( v.x(), v.y(), v.z() );
92 }
93
95 {
96 agx::Vec3i cell;
97 cell[0] = (Vec3i::Type)(x * invCellSize);
98 cell[1] = (Vec3i::Type)(y * invCellSize);
99 cell[2] = (Vec3i::Type)(z * invCellSize);
100
101 if (x < Real(0.0)) cell[0]--;
102 if (y < Real(0.0)) cell[1]--;
103 if (z < Real(0.0)) cell[2]--;
104
105 return cell;
106 }
107
109 {
110 return calculateCellId(position[0], position[1], position[2], invCellSize);
111 }
112
113} // end of namespace agx
114
115
117AGX_TYPE_BINDING(agx::Vec3d, "Vec3")
118
119AGX_TYPE_BINDING(agx::Vec3i8 , "Vec3i")
120AGX_TYPE_BINDING(agx::Vec3i16, "Vec3i")
121AGX_TYPE_BINDING(agx::Vec3i32, "Vec3i")
122AGX_TYPE_BINDING(agx::Vec3i64, "Vec3i")
123
124AGX_TYPE_BINDING(agx::Vec3u8 , "Vec3u")
125AGX_TYPE_BINDING(agx::Vec3u16, "Vec3u")
126AGX_TYPE_BINDING(agx::Vec3u32, "Vec3u")
127AGX_TYPE_BINDING(agx::Vec3u64, "Vec3u")
128
129#endif
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:46
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< UInt16 > Vec3u16
Definition: agx/Vec3.h:49
UInt32 hash(const T &key)
Definition: HashFunction.h:165
const Vec3 Y_AXIS(0.0, 1.0, 0.0)
Vec3T< Int16 > Vec3i16
Definition: agx/Vec3.h:48
Vec3T< UInt32 > Vec3u32
Definition: agx/Vec3.h:51
uint32_t UInt32
Definition: Integer.h:32
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
uint64_t UInt64
Definition: Integer.h:33
Vec3T< Real64 > Vec3d
Definition: agx/Vec3.h:40
Vec3T< UInt64 > Vec3u64
Definition: agx/Vec3.h:53
Vec3T< Int32 > Vec3i32
Definition: agx/Vec3.h:50
UInt64 hash64(UInt64 x, UInt64 y, UInt64 z)
Definition: HashFunction.h:76
Vec3T< Int64 > Vec3i64
Definition: agx/Vec3.h:52
const Vec3 Z_AXIS(0.0, 0.0, 1.0)
Vec3T< Int > Vec3i
Definition: agx/Vec3.h:43
double Real
Definition: Real.h:41
UInt64 spatialHash(double x, double eps)
Hash function suitable for spatial hashing with configurable grid spacing eps.
Definition: HashFunction.h:98
Vec2i calculateCellId(Real x, Real y, Real invCellSize)
Definition: Vec2.h:72
const Vec3 X_AXIS(1.0, 0.0, 0.0)
Vec3T< Real32 > Vec3f
Definition: agx/Vec3.h:39
Vec3T< Int8 > Vec3i8
Definition: agx/Vec3.h:46
Vec3T< UInt8 > Vec3u8
Definition: agx/Vec3.h:47
Vec3T< UInt > Vec3u
Definition: agx/Vec3.h:44
UInt32 operator()(const Vec3T< T > &id) const
Definition: agx/Vec3.h:64
UInt32 operator()(const Vec3T< UInt64 > &id) const
Definition: agx/Vec3.h:73