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 "Components/BsCBoxCollider.h" |
4 | #include "Scene/BsSceneObject.h" |
5 | #include "Components/BsCRigidbody.h" |
6 | #include "Private/RTTI/BsCBoxColliderRTTI.h" |
7 | #include "Scene/BsSceneManager.h" |
8 | |
9 | namespace bs |
10 | { |
11 | CBoxCollider::CBoxCollider() |
12 | { |
13 | setName("BoxCollider"); |
14 | } |
15 | |
16 | CBoxCollider::CBoxCollider(const HSceneObject& parent, const Vector3& extents) |
17 | : CCollider(parent), mExtents(extents) |
18 | { |
19 | setName("BoxCollider"); |
20 | } |
21 | |
22 | void CBoxCollider::setExtents(const Vector3& extents) |
23 | { |
24 | Vector3 clampedExtents = Vector3::max(extents, Vector3(0.01f, 0.01f, 0.01f)); |
25 | |
26 | if (mExtents == clampedExtents) |
27 | return; |
28 | |
29 | mExtents = clampedExtents; |
30 | |
31 | if (mInternal != nullptr) |
32 | { |
33 | _getInternal()->setExtents(clampedExtents); |
34 | |
35 | if (mParent != nullptr) |
36 | mParent->_updateMassDistribution(); |
37 | } |
38 | } |
39 | |
40 | void CBoxCollider::setCenter(const Vector3& center) |
41 | { |
42 | if (mLocalPosition == center) |
43 | return; |
44 | |
45 | mLocalPosition = center; |
46 | |
47 | if (mInternal != nullptr) |
48 | updateTransform(); |
49 | } |
50 | |
51 | SPtr<Collider> CBoxCollider::createInternal() |
52 | { |
53 | const SPtr<SceneInstance>& scene = SO()->getScene(); |
54 | const Transform& tfrm = SO()->getTransform(); |
55 | |
56 | SPtr<Collider> collider = BoxCollider::create(*scene->getPhysicsScene(), mExtents, tfrm.getPosition(), |
57 | tfrm.getRotation()); |
58 | collider->_setOwner(PhysicsOwnerType::Component, this); |
59 | |
60 | return collider; |
61 | } |
62 | |
63 | RTTITypeBase* CBoxCollider::getRTTIStatic() |
64 | { |
65 | return CBoxColliderRTTI::instance(); |
66 | } |
67 | |
68 | RTTITypeBase* CBoxCollider::getRTTI() const |
69 | { |
70 | return CBoxCollider::getRTTIStatic(); |
71 | } |
72 | } |
73 |