Showing the changes to interface/src/avatar/MyCharacterController.cpp (1 of 8 files). Show all
Unified · Split
| @@ -36,10 +36,10 @@ MyCharacterController::MyCharacterController(std::shared_ptr<MyAvatar> avatar) { · 35 unmodified lines | |||
| 36 | MyCharacterController::~MyCharacterController() { | 36 | MyCharacterController::~MyCharacterController() { |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void MyCharacterController::setDynamicsWorld(btDynamicsWorld* world) { | 39 | void MyCharacterController::addToWorld() { |
| 40 | CharacterController::setDynamicsWorld(world); | 40 | CharacterController::addToWorld(); |
| 41 | if (world && _rigidBody) { | 41 | if (_rigidBody) { |
| 42 | initRayShotgun(world); | 42 | initRayShotgun(_physicsEngine->getDynamicsWorld()); |
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
| @@ -204,7 +204,7 @@ bool MyCharacterController::testRayShotgun(const glm::vec3& position, const glm: · 158 unmodified lines | |||
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | int32_t MyCharacterController::computeCollisionMask() const { | 206 | int32_t MyCharacterController::computeCollisionMask() const { |
| 207 | int32_t collisionMask = BULLET_COLLISION_MASK_MY_AVATAR; | 207 | int32_t collisionMask = BULLET_COLLISION_MASK_MY_AVATAR; |
| 208 | if (_collisionless && _collisionlessAllowed) { | 208 | if (_collisionless && _collisionlessAllowed) { |
| 209 | collisionMask = BULLET_COLLISION_MASK_COLLISIONLESS; | 209 | collisionMask = BULLET_COLLISION_MASK_COLLISIONLESS; |
| 210 | } else if (!_collideWithOtherAvatars) { | 210 | } else if (!_collideWithOtherAvatars) { |
| @@ -216,16 +216,17 @@ int32_t MyCharacterController::computeCollisionMask() const { · 5 unmodified lines | |||
| 216 | void MyCharacterController::handleChangedCollisionMask() { | 216 | void MyCharacterController::handleChangedCollisionMask() { |
| 217 | if (_pendingFlags & PENDING_FLAG_UPDATE_COLLISION_MASK) { | 217 | if (_pendingFlags & PENDING_FLAG_UPDATE_COLLISION_MASK) { |
| 218 | // ATM the easiest way to update collision groups/masks is to remove/re-add the RigidBody | 218 | // ATM the easiest way to update collision groups/masks is to remove/re-add the RigidBody |
| 219 | if (_dynamicsWorld) { | 219 | // but we don't do it here. Instead we set some flags to remind us to do it later. |
| 220 | _dynamicsWorld->removeRigidBody(_rigidBody); | 220 | _pendingFlags |= (PENDING_FLAG_REMOVE_FROM_SIMULATION | PENDING_FLAG_ADD_TO_SIMULATION); |
| 221 | int32_t collisionMask = computeCollisionMask(); | ||
| 222 | _dynamicsWorld->addRigidBody(_rigidBody, BULLET_COLLISION_GROUP_MY_AVATAR, collisionMask); | ||
| 223 | } | ||
| 224 | _pendingFlags &= ~PENDING_FLAG_UPDATE_COLLISION_MASK; | 221 | _pendingFlags &= ~PENDING_FLAG_UPDATE_COLLISION_MASK; |
| 225 | updateCurrentGravity(); | 222 | updateCurrentGravity(); |
| 226 | } | 223 | } |
| 227 | } | 224 | } |
| 228 | 225 | ||
| 226 | bool MyCharacterController::needsSafeLandingSupport() const { | ||
| 227 | return _isStuck && 0 == (_numStuckFrames % NUM_FRAMES_FOR_SAFE_LANDING_RETRY); | ||
| 228 | } | ||
| 229 | |||
| 229 | btConvexHullShape* MyCharacterController::computeShape() const { | 230 | btConvexHullShape* MyCharacterController::computeShape() const { |
| 230 | // HACK: the avatar collides using convex hull with a collision margin equal to | 231 | // HACK: the avatar collides using convex hull with a collision margin equal to |
| 231 | // the old capsule radius. Two points define a capsule and additional points are | 232 | // the old capsule radius. Two points define a capsule and additional points are |
| @@ -447,12 +448,12 @@ public: · 215 unmodified lines | |||
| 447 | std::vector<MyCharacterController::RayAvatarResult> MyCharacterController::rayTest(const btVector3& origin, const btVector3& direction, | 448 | std::vector<MyCharacterController::RayAvatarResult> MyCharacterController::rayTest(const btVector3& origin, const btVector3& direction, |
| 448 | const btScalar& length, const QVector<uint>& jointsToExclude) const { | 449 | const btScalar& length, const QVector<uint>& jointsToExclude) const { |
| 449 | std::vector<RayAvatarResult> foundAvatars; | 450 | std::vector<RayAvatarResult> foundAvatars; |
| 450 | if (_dynamicsWorld) { | 451 | if (_physicsEngine) { |
| 451 | btVector3 end = origin + length * direction; | 452 | btVector3 end = origin + length * direction; |
| 452 | DetailedRayResultCallback rayCallback = DetailedRayResultCallback(); | 453 | DetailedRayResultCallback rayCallback = DetailedRayResultCallback(); |
| 453 | rayCallback.m_flags |= btTriangleRaycastCallback::kF_KeepUnflippedNormal; | 454 | rayCallback.m_flags |= btTriangleRaycastCallback::kF_KeepUnflippedNormal; |
| 454 | rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest; | 455 | rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest; |
| 455 | _dynamicsWorld->rayTest(origin, end, rayCallback); | 456 | _physicsEngine->getDynamicsWorld()->rayTest(origin, end, rayCallback); |
| 456 | if (rayCallback.m_hitFractions.size() > 0) { | 457 | if (rayCallback.m_hitFractions.size() > 0) { |
| 457 | foundAvatars.reserve(rayCallback.m_hitFractions.size()); | 458 | foundAvatars.reserve(rayCallback.m_hitFractions.size()); |
| 458 | for (int32_t i = 0; i < rayCallback.m_hitFractions.size(); i++) { | 459 | for (int32_t i = 0; i < rayCallback.m_hitFractions.size(); i++) { |