| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "Components/BsCCapsuleCollider.h"
- #include "Scene/BsSceneObject.h"
- #include "Components/BsCRigidbody.h"
- #include "RTTI/BsCCapsuleColliderRTTI.h"
- namespace bs
- {
- CCapsuleCollider::CCapsuleCollider(const HSceneObject& parent, float radius, float halfHeight)
- : CCollider(parent), mRadius(radius), mHalfHeight(halfHeight)
- {
- setName("CapsuleCollider");
- }
- void CCapsuleCollider::setNormal(const Vector3& normal)
- {
- if (mNormal == normal)
- return;
- mNormal = normal;
- mNormal.normalize();
- mLocalRotation = Quaternion::getRotationFromTo(Vector3::UNIT_X, normal);
- if (mInternal != nullptr)
- updateTransform();
- }
- void CCapsuleCollider::setCenter(const Vector3& center)
- {
- if (mLocalPosition == center)
- return;
- mLocalPosition = center;
- if (mInternal != nullptr)
- updateTransform();
- }
- void CCapsuleCollider::setHalfHeight(float halfHeight)
- {
- float clampedHalfHeight = std::max(halfHeight, 0.01f);
- if (mHalfHeight == clampedHalfHeight)
- return;
- mHalfHeight = clampedHalfHeight;
- if (mInternal != nullptr)
- {
- _getInternal()->setHalfHeight(clampedHalfHeight);
- if (mParent != nullptr)
- mParent->_updateMassDistribution();
- }
- }
- void CCapsuleCollider::setRadius(float radius)
- {
- float clampedRadius = std::max(radius, 0.01f);
- if (mRadius == clampedRadius)
- return;
- mRadius = clampedRadius;
- if (mInternal != nullptr)
- {
- _getInternal()->setRadius(clampedRadius);
- if (mParent != nullptr)
- mParent->_updateMassDistribution();
- }
- }
- SPtr<Collider> CCapsuleCollider::createInternal()
- {
- const Transform& tfrm = SO()->getTransform();
- SPtr<Collider> collider = CapsuleCollider::create(mRadius, mHalfHeight, tfrm.getPosition(),
- tfrm.getRotation());
- collider->_setOwner(PhysicsOwnerType::Component, this);
- return collider;
- }
- RTTITypeBase* CCapsuleCollider::getRTTIStatic()
- {
- return CCapsuleColliderRTTI::instance();
- }
- RTTITypeBase* CCapsuleCollider::getRTTI() const
- {
- return CCapsuleCollider::getRTTIStatic();
- }
- }
|