summaryrefslogtreecommitdiff
path: root/src/KingSystem/Physics/System/physClosestPointQuery.cpp
blob: c27220a0ef5e1ae32e961b961c5802fc41ebb01c (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
#include "KingSystem/Physics/System/physClosestPointQuery.h"
#include "KingSystem/Physics/RigidBody/physRigidBody.h"
#include "KingSystem/Physics/System/physQueryContactPointInfo.h"
#include "KingSystem/Physics/physDefines.h"
#include "KingSystem/Physics/physLayerMaskBuilder.h"

namespace ksys::phys {

ClosestPointQuery::ClosestPointQuery(RigidBody* body, QueryContactPointInfo* contact_point_info)
    : mBody(body), mContactPointInfo(contact_point_info) {
    reset();
}

ClosestPointQuery::~ClosestPointQuery() = default;

void ClosestPointQuery::reset() {
    mIsSuccess = false;
    _18 = 0;
}

void ClosestPointQuery::setLayerMasks(const LayerMaskBuilder& builder) {
    auto* info = mContactPointInfo;
    for (int i = 0; i < NumContactLayerTypes; ++i) {
        info->mSubscribedLayers[i] = builder.getMasks()[i].layers;
        info->mLayerMask2[i] = builder.getMasks()[i].layers2;
    }
}

bool ClosestPointQuery::isSuccess() const {
    return mIsSuccess;
}

void ClosestPointQuery::setLayerMasksAndBodyCollisionFilterInfo(const LayerMaskBuilder& builder) {
    EntityCollisionMask mask;
    mask.data.query_custom_receiver_layer_mask =
        builder.getMasks()[int(ContactLayerType::Entity)].layers;
    mask.data.layer = ContactLayer::EntityQueryCustomReceiver;
    mBody->setCollisionFilterInfo(mask.raw);

    setLayerMasks(builder);
}

}  // namespace ksys::phys