History

improved isStuck detection and MyAvatar::safeLanding() trigger

Andrew Meadows committed 7 years ago

Commit 32400a61 parent 9382fb88 files · +311 −189Browse files

Showing the changes to interface/src/avatar/MyCharacterController.cpp (1 of 8 files). Show all

Unified · Split

interface/src/avatar/MyCharacterController.cpp+13−12
@@ -36,10 +36,10 @@ MyCharacterController::MyCharacterController(std::shared_ptr<MyAvatar> avatar) { · 35 unmodified lines
36MyCharacterController::~MyCharacterController() {36MyCharacterController::~MyCharacterController() {
37}37}
38 38
39void MyCharacterController::setDynamicsWorld(btDynamicsWorld* world) {39void 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
206int32_t MyCharacterController::computeCollisionMask() const {206int32_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
216void MyCharacterController::handleChangedCollisionMask() {216void 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 RigidBody218 // 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
226bool MyCharacterController::needsSafeLandingSupport() const {
227 return _isStuck && 0 == (_numStuckFrames % NUM_FRAMES_FOR_SAFE_LANDING_RETRY);
228}
229
229btConvexHullShape* MyCharacterController::computeShape() const {230btConvexHullShape* MyCharacterController::computeShape() const {
230 // HACK: the avatar collides using convex hull with a collision margin equal to231 // 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 are232 // the old capsule radius. Two points define a capsule and additional points are
@@ -447,12 +448,12 @@ public: · 215 unmodified lines
447std::vector<MyCharacterController::RayAvatarResult> MyCharacterController::rayTest(const btVector3& origin, const btVector3& direction,448std::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++) {