예제 #1
0
        private void EnableCollisionConstraint(int index, ref ConcatInfo concatInfo, ref RigidbodyDesc rigidbody, int entityId)
        {
            constraintTypes[index] |= ConstraintType.Collision;

            var collisionConstraintInfo = new CollisionConstraintInfo()
            {
                concatPosition = concatInfo.position + concatInfo.normal * 0.05f,
                normal         = concatInfo.normal
            };
            var m1 = rigidbody.mass;

            if (m1 > 0)
            {
                var bounciness = rigidbody.bounciness;
                var m0         = masses[index];
                var v0         = (predictPositions[index] - positions[index]) / dt;
                var v0Normal   = math.dot(v0, concatInfo.normal) * concatInfo.normal;
                var v1Normal   = math.dot(rigidbody.velocity, concatInfo.normal) * concatInfo.normal;

                var v0NormalNew = (bounciness + 1) * m1 * v1Normal + v0Normal * (m0 - bounciness * m1);
                var v1NormalNew = (bounciness + 1) * m0 * v0Normal + v1Normal * (m1 - bounciness * m0);

                v0NormalNew /= (m0 + m1);
                v1NormalNew /= (m0 + m1);

                rigidBodyForceApplies.AddNoResize(new RigidBodyForceApply()
                {
                    entityId = entityId,
                    velocity = v1NormalNew - v1Normal
                });
                collisionConstraintInfo.velocity = (v0 - v0Normal + v0NormalNew);
            }

            collisionConstraints[index] = collisionConstraintInfo;
        }
 public void AddBox(BoxDesc box, RigidbodyDesc rigidbodyDesc, int entityId)
 {
     _boxes.Add(new RigidbodyColliderDesc <BoxDesc>()
     {
         entityId  = entityId,
         collider  = box,
         rigidbody = rigidbodyDesc,
     });
 }
 public void AddCapsule(CapsuleDesc capsule, RigidbodyDesc rigidbodyDesc, int entityId)
 {
     _capsules.Add(new RigidbodyColliderDesc <CapsuleDesc>()
     {
         entityId  = entityId,
         collider  = capsule,
         rigidbody = rigidbodyDesc,
     });
 }
 public void AddSphere(SphereDesc sphere, RigidbodyDesc rigidbodyDesc, int entityId)
 {
     _spheres.Add(new RigidbodyColliderDesc <SphereDesc>()
     {
         entityId  = entityId,
         collider  = sphere,
         rigidbody = rigidbodyDesc
     });
 }
예제 #5
0
        public override void FillColliderDesc(CollidersGroup collidersGroup)
        {
            RigidbodyDesc rigidbodyDesc = default(RigidbodyDesc);
            float         mass          = 0;

            if (_rigidbody && !_rigidbody.isKinematic)
            {
                mass = _rigidbody.mass;
                rigidbodyDesc.mass     = _rigidbody.mass;
                rigidbodyDesc.velocity = _rigidbody.velocity;
            }

            collidersGroup.AddCapsule(this.desc, rigidbodyDesc, this.entityId);
        }