1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #include "BsPhysXBoxCollider.h" |
4 | #include "BsPhysX.h" |
5 | #include "PxPhysics.h" |
6 | #include "BsFPhysXCollider.h" |
7 | |
8 | using namespace physx; |
9 | |
10 | namespace bs |
11 | { |
12 | PhysXBoxCollider::PhysXBoxCollider(PxPhysics* physx, PxScene* scene, const Vector3& position, |
13 | const Quaternion& rotation, const Vector3& extents) |
14 | :mExtents(extents) |
15 | { |
16 | PxBoxGeometry geometry(extents.x, extents.y, extents.z); |
17 | |
18 | PxShape* shape = physx->createShape(geometry, *gPhysX().getDefaultMaterial(), true); |
19 | shape->setLocalPose(toPxTransform(position, rotation)); |
20 | shape->userData = this; |
21 | |
22 | mInternal = bs_new<FPhysXCollider>(scene, shape); |
23 | applyGeometry(); |
24 | } |
25 | |
26 | PhysXBoxCollider::~PhysXBoxCollider() |
27 | { |
28 | bs_delete(mInternal); |
29 | } |
30 | |
31 | void PhysXBoxCollider::setScale(const Vector3& scale) |
32 | { |
33 | BoxCollider::setScale(scale); |
34 | applyGeometry(); |
35 | } |
36 | |
37 | void PhysXBoxCollider::setExtents(const Vector3& extents) |
38 | { |
39 | mExtents = extents; |
40 | applyGeometry(); |
41 | } |
42 | |
43 | Vector3 PhysXBoxCollider::getExtents() const |
44 | { |
45 | return mExtents; |
46 | } |
47 | |
48 | void PhysXBoxCollider::applyGeometry() |
49 | { |
50 | PxBoxGeometry geometry(std::max(0.01f, mExtents.x * mScale.x), |
51 | std::max(0.01f, mExtents.y * mScale.y), std::max(0.01f, mExtents.z * mScale.z)); |
52 | |
53 | getInternal()->_getShape()->setGeometry(geometry); |
54 | } |
55 | |
56 | FPhysXCollider* PhysXBoxCollider::getInternal() const |
57 | { |
58 | return static_cast<FPhysXCollider*>(mInternal); |
59 | } |
60 | } |