33 OrientedBox2d() : m_forward_length(0.0f), m_left_length(0.0f), m_height(0.0f) {}
37 m_corner(corner), m_forward_length(forward_length), m_left_length(left_length), m_height(height)
39 forward.GetNormalized(m_forward_dir2d);
44 bool IsValid() {
return m_forward_dir2d !=
Vec2f::Zero(); }
51 KY_DEBUG_ASSERTN(forward_dir2d.GetLength() ==
Vec2f(forward_dir2d).Normalize(), (
"Wrong OrientedBox2d.Set() parameters, forward_dir2d should be normalized"));
54 m_forward_dir2d = forward_dir2d;
55 m_forward_length = forward_length;
56 m_left_length = left_length;
64 bool IsInside2d(
const Vec3f& pos);
66 Box3f ComputeAABB()
const;
71 Vec2f m_forward_dir2d;
79 Vec2f dir2d = Q.Get2d() - P.Get2d();
80 KyFloat32 length = dir2d.GetNormalized(m_forward_dir2d);
85 m_forward_length = length + 2.0f * radius;
86 m_left_length = 2.0f * radius;
87 m_corner.x = P.x - m_forward_dir2d.x * radius + m_forward_dir2d.y * radius;
88 m_corner.y = P.y - m_forward_dir2d.y * radius - m_forward_dir2d.x * radius;
93 inline bool OrientedBox2d::IsInside2d(
const Vec3f& P)
95 const Vec2f& AP = P.Get2d() - m_corner.Get2d();
96 KyFloat32 along_dir = DotProduct(AP, m_forward_dir2d);
98 if (along_dir < 0.0f || along_dir > m_forward_length || ortho_dir < 0.0f || ortho_dir > m_left_length)
104 inline Box3f OrientedBox2d::ComputeAABB()
const
106 Vec2f leftDir = m_forward_dir2d.
PerpCCW();
107 Vec3f B = m_corner + m_forward_dir2d * m_forward_length;
108 Vec3f C = B + leftDir * m_left_length;
109 Vec3f D = m_corner + leftDir * m_left_length;
113 aabb.ExpandByPos(m_corner);
#define KyFloat32MAXVAL
KyFloat32 max value
Definition: types.h:71
OrientedBox2d is a 3d box with rotation constrained to be along Z.
Definition: orientedbox2d.h:26
void Set(const Vec3f &corner, const Vec2f &forward_dir2d, KyFloat32 forward_length, KyFloat32 left_length, KyFloat32 height)
Init OrientedBox2d. dir2d must be normalized.
Definition: orientedbox2d.h:49
static Vec2f UnitX()
Returns {1.0f, 0.0f}.
Definition: vec2f.h:97
static Vec3f Zero()
Returns {0.0f, 0.0f, 0.0f}.
Definition: vec3f.h:99
void InitAs2dInflatedSegment(const Vec3f &start, const Vec3f &dest, KyFloat32 radius)
Creates a new OrientedBox2d that will be an inflate of the segment going from start to dest of radius...
Definition: orientedbox2d.h:77
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
OrientedBox2d()
Construct a zero size OrientedBox2d.
Definition: orientedbox2d.h:33
3d axis aligned box of 32bits floating points
Definition: box3f.h:16
Vec2f PerpCCW() const
Rotates by 90 degrees counter-clockwise.
Definition: vec2f.h:79
2d vector using KyFloat32.
Definition: vec2f.h:18
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
OrientedBox2d(const Vec3f &corner, const Vec2f &forward, KyFloat32 forward_length, KyFloat32 left_length, KyFloat32 height)
Construct OrientedBox2d. forward will be normalized.
Definition: orientedbox2d.h:36
static Vec2f Zero()
Returns {0.0f, 0.0f}.
Definition: vec2f.h:93
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16