ignore other-avatar angularVelocity in physics simulation

This commit is contained in:
Andrew Meadows 2018-08-01 11:22:58 -07:00
parent 0d92e2de0a
commit c939699879
4 changed files with 30 additions and 6 deletions

View file

@ -19,6 +19,7 @@
AvatarMotionState::AvatarMotionState(AvatarSharedPointer avatar, const btCollisionShape* shape) : ObjectMotionState(shape), _avatar(avatar) {
assert(_avatar);
_type = MOTIONSTATE_TYPE_AVATAR;
cacheShapeDiameter();
}
void AvatarMotionState::handleEasyChanges(uint32_t& flags) {
@ -57,9 +58,6 @@ PhysicsMotionType AvatarMotionState::computePhysicsMotionType() const {
const btCollisionShape* AvatarMotionState::computeNewShape() {
ShapeInfo shapeInfo;
std::static_pointer_cast<Avatar>(_avatar)->computeShapeInfo(shapeInfo);
glm::vec3 halfExtents = shapeInfo.getHalfExtents();
halfExtents.y = 0.0f;
_diameter = 2.0f * glm::length(halfExtents);
return getShapeManager()->getShape(shapeInfo);
}
@ -141,7 +139,10 @@ glm::vec3 AvatarMotionState::getObjectLinearVelocity() const {
// virtual
glm::vec3 AvatarMotionState::getObjectAngularVelocity() const {
return _avatar->getWorldAngularVelocity();
// HACK: avatars use a capusle collision shape and their angularVelocity in the local simulation is unimportant.
// Therefore, as optimization toward support for larger crowds we ignore it and return zero.
//return _avatar->getWorldAngularVelocity();
return glm::vec3(0.0f);
}
// virtual
@ -174,3 +175,23 @@ float AvatarMotionState::getMass() const {
return std::static_pointer_cast<Avatar>(_avatar)->computeMass();
}
void AvatarMotionState::cacheShapeDiameter() {
if (_shape) {
// measure XZ diameter of capsule shape
btVector3 aabbMin, aabbMax;
btTransform transform;
transform.setIdentity();
_shape->getAabb(transform, aabbMin, aabbMax);
aabbMax -= aabbMin;
aabbMax.setY(0.0f);
const float SQRT_TWO = 1.414213562f;
_diameter = SQRT_TWO * aabbMax.length();
} else {
_diameter = 0.0f;
}
}
void AvatarMotionState::setShape(const btCollisionShape* shape) {
cacheShapeDiameter();
ObjectMotionState::setShape(shape);
}

View file

@ -74,6 +74,9 @@ public:
friend class Avatar;
protected:
void setShape(const btCollisionShape* shape) override;
void cacheShapeDiameter();
// the dtor had been made protected to force the compiler to verify that it is only
// ever called by the Avatar class dtor.
~AvatarMotionState();

View file

@ -64,9 +64,9 @@ ShapeManager* ObjectMotionState::getShapeManager() {
}
ObjectMotionState::ObjectMotionState(const btCollisionShape* shape) :
_shape(shape),
_lastKinematicStep(worldSimulationStep)
{
setShape(shape);
}
ObjectMotionState::~ObjectMotionState() {

View file

@ -181,7 +181,7 @@ protected:
MotionStateType _type { MOTIONSTATE_TYPE_INVALID }; // type of MotionState
PhysicsMotionType _motionType { MOTION_TYPE_STATIC }; // type of motion: KINEMATIC, DYNAMIC, or STATIC
const btCollisionShape* _shape;
const btCollisionShape* _shape { nullptr };
btRigidBody* _body { nullptr };
float _density { 1.0f };