Exemple #1
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);
        }
 public override SegmentInterceptInfo SegmentIntersect(Ray raio, System.Func <IPhysicObject, bool> filter, float maxDistance)
 {
     BulletSharp.CollisionWorld.ClosestRayResultCallback RayResultCallback = new BulletSharp.CollisionWorld.ClosestRayResultCallback(raio.Position, raio.Direction * maxDistance);
     world.RayTest(raio.Position, raio.Direction * maxDistance, RayResultCallback);
     if (RayResultCallback.HasHit)
     {
         SegmentInterceptInfo SegmentInterceptInfo = new SegmentInterceptInfo();
         SegmentInterceptInfo.Distance       = RayResultCallback.ClosestHitFraction * maxDistance;
         SegmentInterceptInfo.PhysicObject   = RayResultCallback.CollisionObject.UserObject as IPhysicObject;
         SegmentInterceptInfo.ImpactNormal   = RayResultCallback.HitNormalWorld;
         SegmentInterceptInfo.ImpactPosition = RayResultCallback.HitPointWorld;
         return(SegmentInterceptInfo);
     }
     else
     {
         return(null);
     }
 }
Exemple #3
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);
        }
Exemple #4
0
        public override SegmentInterceptInfo SegmentIntersect(Microsoft.Xna.Framework.Ray raio, System.Func <IPhysicObject, bool> filter, float maxDistance)
        {
            SegmentInterceptInfo SegmentInterceptInfo = null;

            foreach (var hits in Scene.RaycastAllShapes(new StillDesign.PhysX.Ray(raio.Position.AsPhysX(), raio.Direction.AsPhysX()), ShapesType.All))
            {
                if (filter(hits.Shape.Actor.UserData as IPhysicObject))
                {
                    if (SegmentInterceptInfo == null || SegmentInterceptInfo.Distance > hits.Distance)
                    {
                        SegmentInterceptInfo                = new SegmentInterceptInfo();
                        SegmentInterceptInfo.Distance       = hits.Distance;
                        SegmentInterceptInfo.ImpactNormal   = hits.WorldNormal.AsXNA();
                        SegmentInterceptInfo.ImpactPosition = hits.WorldImpact.AsXNA();
                        SegmentInterceptInfo.PhysicObject   = hits.Shape.Actor.UserData as IPhysicObject;
                    }
                }
            }
            return(SegmentInterceptInfo);
        }
 void pick_OnPickedLeftButton(SegmentInterceptInfo SegmentInterceptInfo)
 {
     SimpleMap sm = new SimpleMap(wh.CurrentWaypointsCollection);
     AStar astar = new AStar(sm);
     path = astar.GetPath(start.WorldPos, SegmentInterceptInfo.ImpactPosition);
     ///the first will always be the start and the last should be the clicked position, not the last waypoint =P            
     path.AddLast(new Waypoint() { WorldPos = SegmentInterceptInfo.ImpactPosition });
     pathchanged = true;
     destiny = SegmentInterceptInfo.ImpactPosition;
 }
 void p_OnPickedLeftButton(SegmentInterceptInfo SegmentInterceptInfo)
 {
     destiny = VectorUtils.ToVector2(SegmentInterceptInfo.ImpactPosition);
     for (int i = 0; i < Simulator.getNumAgents(); i++)
     {
         Simulator.setAgentPrefVelocity(i, Vector2.Normalize( destiny - Simulator.getAgentPosition(i)));
     }
 }
        /// <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;
        }
 /// <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;            
 }
        /// <summary>
        /// Called when picking happens
        /// </summary>
        /// <param name="SegmentInterceptInfo">The segment intercept info.</param>
        void onPick(SegmentInterceptInfo SegmentInterceptInfo)
        {

            IObject obj = SegmentInterceptInfo.PhysicObject.ObjectOwner;
            if (obj != null)
            {
               
                this.ri = SegmentInterceptInfo;
                changed = true;
            }
        }
        public override SegmentInterceptInfo SegmentIntersect(Ray raio, System.Func<IPhysicObject, bool> filter, float maxDistance)
        {

            SceneQueryFlags outputFlags = SceneQueryFlags.Distance | SceneQueryFlags.Impact | SceneQueryFlags.Impact;
            RaycastHit[] hit = scene.RaycastMultiple(raio.Position.AsPhysX(), raio.Direction.AsPhysX(), maxDistance, outputFlags,256);
            foreach (var item in hit)
            {                           
                if(item.Shape.Actor.UserData is IPhysicObject)
                {
                    if (filter(item.Shape.Actor.UserData as IPhysicObject))
                    {
                        SegmentInterceptInfo SegmentInterceptInfo = new SegmentInterceptInfo();
                        SegmentInterceptInfo.Distance = item.Distance;
                        SegmentInterceptInfo.ImpactNormal = item.Normal.AsXNA();
                        SegmentInterceptInfo.ImpactPosition = item.Impact.AsXNA();
                        SegmentInterceptInfo.PhysicObject = item.Shape.Actor.UserData as IPhysicObject;
                        return SegmentInterceptInfo;
                    }
                }
            }            
            return null;
        }
 public override SegmentInterceptInfo SegmentIntersect(Ray raio, System.Func<IPhysicObject, bool> filter, float maxDistance)
 {
     BulletSharp.CollisionWorld.ClosestRayResultCallback RayResultCallback = new BulletSharp.CollisionWorld.ClosestRayResultCallback(raio.Position, raio.Direction * maxDistance);
     world.RayTest(raio.Position, raio.Direction * maxDistance, RayResultCallback);
     if (RayResultCallback.HasHit)
     {
         SegmentInterceptInfo SegmentInterceptInfo = new SegmentInterceptInfo();
         SegmentInterceptInfo.Distance = RayResultCallback.ClosestHitFraction * maxDistance;
         SegmentInterceptInfo.PhysicObject = RayResultCallback.CollisionObject.UserObject as IPhysicObject;
         SegmentInterceptInfo.ImpactNormal = RayResultCallback.HitNormalWorld;
         SegmentInterceptInfo.ImpactPosition = RayResultCallback.HitPointWorld;
         return SegmentInterceptInfo;
     }
     else
     {
         return null;
     }
 }
        public override SegmentInterceptInfo SegmentIntersect(Microsoft.Xna.Framework.Ray raio, System.Func<IPhysicObject, bool> filter, float maxDistance)
        {

            SegmentInterceptInfo SegmentInterceptInfo = null;
            foreach (var hits in Scene.RaycastAllShapes(new StillDesign.PhysX.Ray(raio.Position.AsPhysX(), raio.Direction.AsPhysX()), ShapesType.All))
            {
                if (filter(hits.Shape.Actor.UserData as IPhysicObject))
                {
                    if (SegmentInterceptInfo == null || SegmentInterceptInfo.Distance > hits.Distance)
                    {
                        SegmentInterceptInfo = new SegmentInterceptInfo();
                        SegmentInterceptInfo.Distance = hits.Distance;
                        SegmentInterceptInfo.ImpactNormal = hits.WorldNormal.AsXNA();
                        SegmentInterceptInfo.ImpactPosition = hits.WorldImpact.AsXNA();
                        SegmentInterceptInfo.PhysicObject = hits.Shape.Actor.UserData as IPhysicObject;                     
                    }
                }
            }
            return SegmentInterceptInfo;
        }
 void pick_OnPickedLeftButton(SegmentInterceptInfo SegmentInterceptInfo)
 {
     Waypoint cw = new Waypoint()
     {
         AditionalInfo = null,
         WayType = WAYPOINTTYPE.NORMAL,
         WorldPos =  SegmentInterceptInfo.ImpactPosition,               
       
     };
     wh.AddWaypointUnconnected(cw);
 }
 /// <summary>
 /// Called when picking happens
 /// </summary>
 /// <param name="SegmentInterceptInfo">The segment intercept info.</param>
 void onPick(SegmentInterceptInfo SegmentInterceptInfo)
 {
     sp1.Direction = Vector3.Normalize(SegmentInterceptInfo.ImpactPosition - cam.Position);
 }
 void pick_OnPickedGesture(SegmentInterceptInfo SegmentInterceptInfo, Microsoft.Xna.Framework.Input.Touch.TouchLocation TouchLocation)
 {
     result = "Position " + SegmentInterceptInfo.ImpactPosition + " - " + SegmentInterceptInfo.PhysicObject.ObjectOwner.Name;
 }
 /// <summary>
 /// Called when picking happens
 /// </summary>
 /// <param name="SegmentInterceptInfo">The segment intercept info.</param>
 void onPick(SegmentInterceptInfo SegmentInterceptInfo)
 {
     
     IObject obj = SegmentInterceptInfo.PhysicObject.ObjectOwner;
     if(obj != null)
     {                
         objName = obj.Name;
         shouldDraw = true;
         this.ri = SegmentInterceptInfo;
     }
 }