Represents a Collision Shape.
Ejemplo n.º 1
0
        public void Remove(Collider collider)
        {
            lock (_lockObject)
            {
                _allTriggersAndColliders.Remove(collider);

                if (collider.IsTrigger)
                {
                    _allTriggers.Remove(collider);
                }
                else
                {
                    _allColliders.Remove(collider);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a clone of another collider.
 /// </summary>
 /// <param name="other">Collider to clone</param>
 public Collider Clone()
 {
     var collider = new Collider();
     collider.IsActive = IsActive;
     collider.BoundingBox = BoundingBox;
     collider.IsTrigger = IsTrigger;
     collider._offsetToCenter = _offsetToCenter;
     collider._position = _position;
     collider.Type = Type;
     return collider;
 }
Ejemplo n.º 3
0
 public bool Intersects(Collider other)
 {
     return BoundingBox.Intersects(other.BoundingBox);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Checks collision to another object.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public CollisionResult CheckCollision(Collider other)
 {
     return BoundingBox.CollidesWithSat(other.BoundingBox);
 }
Ejemplo n.º 5
0
 public void HandleTrigger(Collider other)
 {
     _currentFrameTouched.Add(other);
     if (!_lastFrameTouched.Contains(other))
     {
         OnTriggerEnter?.Invoke(other);
         _lastFrameTouched.Add(other);
     }
 }
Ejemplo n.º 6
0
        private void DrawBoundingBox(Camera observer, Collider collider)
        {
            var scale = -collider.BoundingBox.Min + collider.BoundingBox.Max;
            var position = collider.BoundingBox.Min + scale*0.5f;
            var worldViewProjection = Matrix.CreateScale(scale)*Matrix.CreateTranslation(position)*observer.ViewMatrix*
                                      observer.ProjectionMatrix;

            _worldViewProjection.SetValue(worldViewProjection);
            _modulateColor.SetValue(collider.IsTrigger ? ColorTrigger : ColorCollider);

            _lineDrawEffect.CurrentTechnique.Passes[0].Apply();
            _boundingBoxMesh.Draw();
        }
Ejemplo n.º 7
0
        public CollisionResult[] CheckCollision(Collider collider)
        {
            lock (_lockObject)
            {
                _colliderList.Clear();
                foreach (var possibleCollider in _allColliders)
                {
                    if (collider == possibleCollider) continue;
                    if (!possibleCollider.IsActive) continue;

                    var result = possibleCollider.CheckCollision(collider);
                    if (result.Collides)
                    {
                        _colliderList.Add(result);
                    }
                }

                return _colliderList.ToArray();
            }
        }
Ejemplo n.º 8
0
 public CollisionEntityComponent(Entity referringEntity, Vector3 collisionSize, Vector3 collisionOffset, string tag, bool resolvesPosition = false) : base(referringEntity)
 {
     ResolvesPosition = resolvesPosition;
     Collider = new Collider(collisionSize, collisionOffset) {Tag = tag};
 }
Ejemplo n.º 9
0
 public CollisionEntityComponent(EntityComponentDataCreationStruct structData) : base(structData)
 {
     Collider = new Collider(GetData<Vector3>("CollisionSize"), GetData<Vector3>("CollisionOffset"));
 }