summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/RigidBody/Shape/Capsule/physCapsuleShape.h
blob: 5190f2127618b15f4e34a29d1b7a4aeb657937c8 (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
#pragma once

#include <Havok/Common/Base/hkBase.h>
#include <math/seadVector.h>
#include <prim/seadTypedBitFlag.h>
#include <thread/seadAtomic.h>
#include "KingSystem/Physics/RigidBody/Shape/physShape.h"
#include "KingSystem/Physics/RigidBody/physRigidBody.h"
#include "KingSystem/Physics/RigidBody/physRigidBodyParam.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Physics/physMaterialMask.h"

class hkpShape;

namespace ksys::phys {

class CapsuleParam;
struct CapsuleShape;

struct CapsuleShapeParam {
    sead::Vector3f vertex_a = -1 * sead::Vector3f::ey;
    sead::Vector3f vertex_b = +1 * sead::Vector3f::ey;
    f32 radius = 1.0;
    CommonShapeParam common;
};

struct CapsuleShape : Shape {
    SEAD_RTTI_OVERRIDE(CapsuleShape, Shape)
public:
    enum class Flag {
        Modified = 1 << 0,
    };

    static CapsuleShape* make(const CapsuleShapeParam& param, sead::Heap* heap);
    CapsuleShape* clone(sead::Heap* heap) const;

    CapsuleShape(const CapsuleShapeParam& shape_, hkpShape* hkp_shape_);
    ~CapsuleShape() override;

    ShapeType getType() const override { return ShapeType::Capsule; }
    float getVolume() const override;
    hkpShape* getHavokShape() override;
    const hkpShape* getHavokShape() const override;
    hkpShape* updateHavokShape() override;
    void setScale(float scale) override;

    f32 getRadius() const;
    void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const;
    bool setRadius(f32 r);
    bool setVertices(const sead::Vector3f& va, const sead::Vector3f& vb);
    void transformVertices(sead::Vector3f* veca, sead::Vector3f* vecb, const hkTransformf& rb_vec);
    void setMaterialMask(const MaterialMask& mask);
    const MaterialMask& getMaterialMask() const { return material_mask; }

    sead::Vector3f vertex_a;
    sead::TypedBitFlag<Flag, sead::Atomic<u32>> flags{};
    sead::Vector3f vertex_b;
    f32 radius;
    MaterialMask material_mask;
    hkpShape* shape;
};

class CapsuleParam : public RigidBodyInstanceParam, public CapsuleShapeParam {
    SEAD_RTTI_OVERRIDE(CapsuleParam, RigidBodyInstanceParam)
public:
    CapsuleParam() : RigidBodyInstanceParam(ShapeType::Capsule) {}
};

}  // namespace ksys::phys