Exemplo n.º 1
0
        /// <summary>
        /// Detects the collisions.
        /// </summary>
        /// <param name="po">The po.</param>
        /// <param name="col">The col.</param>
        public override void DetectCollisions(IPhysicObject po, List <IPhysicObject> col)
        {
            System.Diagnostics.Debug.Assert(col != null);
            System.Diagnostics.Debug.Assert(po != null);
            col.Clear();

            CollidableCollection CollidableCollection;

            if (po is TriangleMeshObject)
            {
                CollidableCollection = (po as TriangleMeshObject).StaticMesh.OverlappedCollidables;
            }
            else
            {
                CollidableCollection = (po as BepuEntityObject).Entity.CollisionInformation.OverlappedCollidables;
            }

            foreach (var item in CollidableCollection)
            {
                IPhysicObject candidate = BepuEntityObject.RecoverIPhysicObjectFromCollidable(item);
                if (candidate != null)
                {
                    col.Add(candidate);
                }
            }
        }
        /// <summary>
        /// Collision happened
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="other"></param>
        /// <param name="pair"></param>
        void Events_InitialCollisionDetected(BEPUphysics.Collidables.MobileCollidables.EntityCollidable sender, BEPUphysics.Collidables.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
        {
            IObject send = BepuEntityObject.RecoverObjectFromEntity(sender.Entity);
            IObject obj  = BepuEntityObject.RecoverObjectFromCollidable(other);

            ///Verifica se esta bola ja foi considerada
            ///Consider just the first collision
            if (alreadProcessed.Contains(obj.GetId()))
            {
                return;
            }

            alreadProcessed.Add(obj.GetId());

            ///se o objeto colidido for diferente do cenario
            ///dont consider the island model (triangle meshes in general)
            if (obj.PhysicObject.PhysicObjectTypes != PhysicObjectTypes.TRIANGLEMESHOBJECT)
            {
                shouldDraw = true;

                ///Envia uma mensagem para o canal de comunicacao CUBO
                ///Send a message to the channel
                Message m = new Message(send.GetId(), PrincipalConstants.InvalidId, "cubo", Priority.MEDIUM, -1, SenderType.OBJECT, null, "CHANGECOLOR");
                MessageDeliver.SendMessage(m);

                ///Esta mensagem foi enviada sem Sender (Quem receber a mensagem nao sabera quem enviou)
                ///Envia uma mensagem para o "CUBO QUE VAI MUDAR DE COR" (lembre que o id dele eh 77 !!)
                ///Send a message to the specific  id (first cube)
                m = new Message(PrincipalConstants.InvalidId, 77, null, Priority.MEDIUM, -1, SenderType.OBJECT, null, "CHANGECOLOR");
                MessageDeliver.SendMessage(m);
            }

            objNameTemp = obj.Name;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Raycast (Closest Result)
        /// </summary>
        /// <param name="raio">The raio.</param>
        /// <param name="filter"></param>
        /// <param name="maxDistance">The max distance.</param>
        /// <returns></returns>
        public override SegmentInterceptInfo SegmentIntersect(Ray raio, Func <IPhysicObject, bool> filter, float maxDistance)
        {
            RayCastResult result;

            if (space.RayCast(raio, maxDistance, (a) => { return(filter(BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(a))); }, out result))
            {
                SegmentInterceptInfo resp = new SegmentInterceptInfo();
                resp.Distance       = Vector3.Distance(result.HitData.Location, raio.Position);
                resp.ImpactNormal   = result.HitData.Normal;
                resp.ImpactPosition = result.HitData.Location;
                resp.PhysicObject   = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(result.HitObject);
                return(resp);
            }
            return(null);
        }
Exemplo n.º 4
0
        public override void GetPhysicsObjectsInRange(Vector3 position, float distance, CullerConditionAvaliator <IPhysicObject, IObject> CullerAvaliator, List <IPhysicObject> resp)
        {
            resp.Clear();
            List <BroadPhaseEntry> ent = new List <BroadPhaseEntry>();

            space.BroadPhase.QueryAccelerator.GetEntries(new BoundingSphere(position, distance), ent);
            foreach (var item in ent)
            {
                IPhysicObject phyObj = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(item);
                if (phyObj != null)
                {
                    if (CullerAvaliator(phyObj, phyObj.ObjectOwner))
                    {
                        resp.Add(phyObj);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the Iobjects in range.
        /// </summary>
        /// <param name="frustrum">The frustrum.</param>
        /// <param name="condition">The condition.</param>
        /// <param name="resp">The resp.</param>
        public void GetIObjectsInRange(BoundingFrustum frustrum, CullerConditionAvaliator <IPhysicObject, IObject> condition, List <IObject> resp)
        {
            resp.Clear();
            List <BroadPhaseEntry> ent = new List <BroadPhaseEntry>();

            space.BroadPhase.QueryAccelerator.GetEntries(frustrum, ent);
            foreach (var item in ent)
            {
                IPhysicObject phyObj = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(item);
                if (phyObj != null)
                {
                    if (condition(phyObj, phyObj.ObjectOwner))
                    {
                        resp.Add(phyObj.ObjectOwner);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Raycast (Multiples Results)
        /// </summary>
        /// <param name="raio">The raio.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="maxDistance">The max distance.</param>
        /// <returns></returns>
        public List <SegmentInterceptInfo> SegmentIntersectMultiple(Ray raio, Func <IPhysicObject, bool> filter, float maxDistance)
        {
            List <SegmentInterceptInfo> rp = new List <SegmentInterceptInfo>();

            List <RayCastResult> result = new List <RayCastResult>();

            if (space.RayCast(raio, maxDistance, (a) => { return(filter(BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(a))); }, result))
            {
                for (int i = 0; i < result.Count; i++)
                {
                    SegmentInterceptInfo resp = new SegmentInterceptInfo();
                    resp.Distance       = Vector3.Distance(result[i].HitData.Location, raio.Position);
                    resp.ImpactNormal   = result[i].HitData.Normal;
                    resp.ImpactPosition = result[i].HitData.Location;
                    resp.PhysicObject   = BepuEntityObject.RecoverIPhysicObjectFromBroadPhase(result[i].HitObject);
                    rp.Add(resp);
                }
            }
            return(rp);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Removes the object.
        /// </summary>
        /// <param name="obj">The obj.</param>
        public override void RemoveObject(IPhysicObject obj)
        {
            if (obj.PhysicObjectTypes == PhysicObjectTypes.TRIANGLEMESHOBJECT)
            {
                TriangleMeshObject bo = (TriangleMeshObject)obj;
                bo.StaticMesh.Tag = null;
                space.Remove(bo.StaticMesh);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.InstancedTriangleMeshObject)
            {
                InstancedTriangleMeshObject bo = (InstancedTriangleMeshObject)obj;
                bo.InstancedMesh.Tag = null;
                space.Remove(bo.InstancedMesh);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.MobilePhysicObject)
            {
                MobileMeshObject bo = (MobileMeshObject)obj;
                bo.MobileMesh.Tag = null;
                space.Remove(bo.MobileMesh);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.SPECIALIZEDMOVER)
            {
                ObjectMover m = (ObjectMover)obj;
                space.Remove(m.BepuEntityObject.Entity);
                m.BepuEntityObject.Entity.CollisionInformation.Tag = null;
                space.Remove(m.Mover);
                space.Remove(m.Rotator);
                objs.Remove(m.BepuEntityObject);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.DETECTOROBJECT)
            {
                DetectorVolumeObject m = (DetectorVolumeObject)obj;
                space.Remove(m.DetectorVolume);
            }

            else if (obj.PhysicObjectTypes == PhysicObjectTypes.TERRAIN)
            {
                TerrainObject t = obj as TerrainObject;
                space.Remove(t.Terrain);
                t.Terrain.Tag = null;
                objs.Remove(obj);
            }

            else if (obj.PhysicObjectTypes == PhysicObjectTypes.CHARACTEROBJECT)
            {
                CharacterObject cc = (CharacterObject)obj;
                cc.CharacterController.Body.CollisionInformation.Tag = null;
                space.Remove(cc.CharacterController);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.FULLCHARACTEROBJECT)
            {
                FullCharacterObject cc = (FullCharacterObject)obj;
                cc.CharacterController.Body.CollisionInformation.Tag = null;
                space.Remove(cc.CharacterController);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.SPHERECHARACTEROBJECT)
            {
                SphereCharacterObject cc = (SphereCharacterObject)obj;
                cc.CharacterController.Body.CollisionInformation.Tag = null;
                space.Remove(cc.CharacterController);
                objs.Remove(obj);
            }
            else if (obj.PhysicObjectTypes == PhysicObjectTypes.GHOST)
            {
                //if (obj is AgregatedPhysicObject)
                //{
                //    objs.Remove(obj);
                //    AgregatedPhysicObject ag = obj as AgregatedPhysicObject;
                //    foreach (var item in ag.PhysicsObjects)
                //    {
                //        item.ObjectOwner = null;
                //        this.RemoveObject(item);
                //    }
                //}
                //else
                //{
                objs.Remove(obj);
                //}
            }
            else
            {
                BepuEntityObject bo = (BepuEntityObject)obj;
                bo.Entity.CollisionInformation.Tag = null;
                space.Remove(bo.Entity);
                objs.Remove(obj);
            }
        }
Exemplo n.º 8
0
 public virtual void SetupCollisionModel(BepuEntityObject collisionModel)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 void detectorVolume_VolumeStopsContainingEntity(DetectorVolume volume, BEPUphysics.Entities.Entity entity)
 {
     contactEntity = BepuEntityObject.RecoverObjectFromEntity(entity);
     evt.Code      = FireEndsContaining;
     evt.FireEvent(this);
 }
Exemplo n.º 10
0
 void detectorVolume_EntityBeginsTouching(BEPUphysics.Entities.Entity toucher, DetectorVolume volume)
 {
     contactEntity = BepuEntityObject.RecoverObjectFromEntity(toucher);
     evt.Code      = FireBeginsTouching;
     evt.FireEvent(this);
 }