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 "BsPhysXSphereCollider.h" |
4 | #include "BsPhysX.h" |
5 | #include "PxPhysics.h" |
6 | #include "BsFPhysXCollider.h" |
7 | |
8 | using namespace physx; |
9 | |
10 | namespace bs |
11 | { |
12 | PhysXSphereCollider::PhysXSphereCollider(PxPhysics* physx, PxScene* scene, const Vector3& position, |
13 | const Quaternion& rotation, float radius) |
14 | :mRadius(radius) |
15 | { |
16 | PxSphereGeometry geometry(radius); |
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 | PhysXSphereCollider::~PhysXSphereCollider() |
27 | { |
28 | bs_delete(mInternal); |
29 | } |
30 | |
31 | void PhysXSphereCollider::setScale(const Vector3& scale) |
32 | { |
33 | SphereCollider::setScale(scale); |
34 | applyGeometry(); |
35 | } |
36 | |
37 | void PhysXSphereCollider::setRadius(float radius) |
38 | { |
39 | mRadius = radius; |
40 | applyGeometry(); |
41 | } |
42 | |
43 | float PhysXSphereCollider::getRadius() const |
44 | { |
45 | return mRadius; |
46 | } |
47 | |
48 | void PhysXSphereCollider::applyGeometry() |
49 | { |
50 | float radius = std::max(0.01f, mRadius * std::max(std::max(mScale.x, mScale.y), mScale.z)); |
51 | PxSphereGeometry geometry(radius); |
52 | |
53 | getInternal()->_getShape()->setGeometry(geometry); |
54 | } |
55 | |
56 | FPhysXCollider* PhysXSphereCollider::getInternal() const |
57 | { |
58 | return static_cast<FPhysXCollider*>(mInternal); |
59 | } |
60 | } |