public void Collide(ref DyBone.Particle p) { //p transform Collider space p.Position = Vector3.TransformCoordinate(p.Position, InvertTransform); switch (Flags) { case EColliderType.OutSideCapsule: { OutsideCapsule(ref p.Position, p.Radius, BVCapsule.P0, BVCapsule.P1, BVCapsule.Radius); } break; case EColliderType.InSideCapsule: { InsideCapsule(ref p.Position, p.Radius, BVCapsule.P0, BVCapsule.P1, BVCapsule.Radius); } break; case EColliderType.OutSideSphere: { var dir = p.Position - BVSphere.Center; var dist = dir.Length(); float touchDist = p.Radius + BVSphere.Radius; if (dist > touchDist) { break; } dir /= dist; p.Position = BVSphere.Center + dir * touchDist; } break; case EColliderType.InSideSphere: { var dir = p.Position - BVSphere.Center; var dist = dir.Length(); float touchDist = BVSphere.Radius - p.Radius; if (dist < touchDist) { break; } dir /= dist; p.Position = BVSphere.Center + dir * touchDist; } break; } //p transform world space p.Position = Vector3.TransformCoordinate(p.Position, Transform); }
public void Collide(ref DyBone.Particle p) { for (int i = 0; i < 64; i++) { if (Colliders[i].Flags == EColliderType.Unknonw) { continue; } if (p.PVS != 0) { if ((p.PVS & ((UInt64)(1 << i))) == 0) { continue; } } Colliders[i].Collide(ref p); } }