summaryrefslogtreecommitdiff
path: root/lib/hkStubs/Havok/Physics2012/Utilities/Collide/ShapeUtils/ShapeKeyPath/hkpShapeKeyPath.h
blob: 8b7c6e0a948143c27e09432e70bb22c63598828c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include <Havok/Common/Base/hkBase.h>
#include <Havok/Physics2012/Collide/Shape/hkpShape.h>
#include <Havok/Physics2012/Collide/Shape/hkpShapeBuffer.h>

class hkpContactPointEvent;
struct hkpRootCdPoint;
struct hkpShapeRayBundleCastOutput;
struct hkpWorldRayCastOutput;

class hkpShapeKeyPath {
public:
    HK_DECLARE_CLASS_ALLOCATOR(hkpShapeKeyPath)

    class Iterator;

    hkpShapeKeyPath(const hkpContactPointEvent& event, int bodyIdx);
    explicit hkpShapeKeyPath(const hkpWorldRayCastOutput& output);
    hkpShapeKeyPath(const hkpShape* shape, const hkpShapeRayCastOutput& output);

    hkpShapeKey getShapeKey(int keyIndex) const;

    Iterator getIterator() const;

    void getShapes(int maxShapesOut, hkpShapeBuffer* buffers, const hkpShape** shapesOut,
                   int& numShapesOut);

    class Iterator {
    public:
        HK_DECLARE_CLASS_ALLOCATOR(Iterator)

        friend class hkpShapeKeyPath;

        /// Returns nullptr if the iterator is invalid.
        const hkpShape* getShape() const;

        /// @warning This can invalidate the shape.
        void next();

        hkBool isValid() const;

    private:
        Iterator(const hkpShapeKeyPath* path, const hkpShape* rootShape);
        void nextImpl(hkpShapeBuffer* buf);

        const hkpShapeKeyPath* m_path;
        const hkpShape* m_currentShape;
        int m_currentKeyIdx;
        hkBool m_isValid;
        hkpShapeBuffer m_tempBuffer;
    };

private:
    void init(const hkpShape* shape, const hkpShapeKey* keys, int maxKeys);

    const hkpShape* m_rootShape;
    const hkpShapeKey* m_keys;
    int m_numKeys;
    hkBool m_isOrderLeafToRoot;
};

inline hkpShapeKeyPath::Iterator hkpShapeKeyPath::getIterator() const {
    return {this, m_rootShape};
}

inline const hkpShape* hkpShapeKeyPath::Iterator::getShape() const {
    return m_currentShape;
}

inline void hkpShapeKeyPath::Iterator::next() {
    return nextImpl(&m_tempBuffer);
}

inline hkBool hkpShapeKeyPath::Iterator::isValid() const {
    return m_isValid;
}