/// <summary> /// Returns information on what a line trace would collide with, if anything. /// </summary> /// <param name="start">The start of the line.</param> /// <param name="end">The end of the line.</param> /// <param name="filter">The collision filter, input a BEPU BroadPhaseEntry and output whether collision should be allowed.</param> /// <returns>The collision details.</returns> public CollisionResult RayTrace(Location start, Location end, Func <BroadPhaseEntry, bool> filter = null) { double len = (end - start).Length(); Ray ray = new Ray(start.ToBVector(), ((end - start) / len).ToBVector()); RayCastResult rcr; bool hit; if (filter == null) { hit = World.RayCast(ray, (double)len, out rcr); } else { hit = World.RayCast(ray, (double)len, filter, out rcr); } CollisionResult cr = new CollisionResult(); cr.Hit = hit; if (hit) { cr.Normal = new Location(rcr.HitData.Normal); cr.Position = new Location(rcr.HitData.Location); if (rcr.HitObject is EntityCollidable) { cr.HitEnt = ((EntityCollidable)rcr.HitObject).Entity; } else { cr.HitEnt = null; // Impacted static world } } else { cr.Normal = Location.Zero; cr.Position = end; cr.HitEnt = null; } return(cr); }
/// <summary> /// Returns information on what a cuboid-shaped line trace would collide with, if anything. /// </summary> /// <param name="start">The start of the line.</param> /// <param name="end">The end of the line.</param> /// <param name="filter">The collision filter, input a BEPU BroadPhaseEntry and output whether collision should be allowed.</param> /// <returns>The collision details.</returns> public CollisionResult CuboidLineTrace(ConvexShape shape, Location start, Location end, Func <BroadPhaseEntry, bool> filter = null) { Vector3 e = new Vector3((double)(end.X - start.X), (double)(end.Y - start.Y), (double)(end.Z - start.Z)); RigidTransform rt = new RigidTransform(new Vector3((double)start.X, (double)start.Y, (double)start.Z)); RayCastResult rcr; bool hit; if (filter == null) { hit = World.ConvexCast(shape, ref rt, ref e, out rcr); } else { hit = World.ConvexCast(shape, ref rt, ref e, filter, out rcr); } CollisionResult cr = new CollisionResult(); cr.Hit = hit; if (hit) { cr.Normal = new Location(rcr.HitData.Normal); cr.Position = new Location(rcr.HitData.Location); if (rcr.HitObject is EntityCollidable) { cr.HitEnt = ((EntityCollidable)rcr.HitObject).Entity; } else { cr.HitEnt = null; // Impacted static world } } else { cr.Normal = Location.Zero; cr.Position = end; cr.HitEnt = null; } return(cr); }
/// <summary> /// Returns information on what a line trace would collide with, if anything. /// </summary> /// <param name="start">The start of the line.</param> /// <param name="end">The end of the line.</param> /// <param name="filter">The collision filter, input a BEPU BroadPhaseEntry and output whether collision should be allowed.</param> /// <returns>The collision details.</returns> public CollisionResult RayTrace(Location start, Location end, Func<BroadPhaseEntry, bool> filter = null) { double len = (end - start).Length(); Ray ray = new Ray(start.ToBVector(), ((end - start) / len).ToBVector()); RayCastResult rcr; bool hit; if (filter == null) { hit = World.RayCast(ray, (double)len, out rcr); } else { hit = World.RayCast(ray, (double)len, filter, out rcr); } CollisionResult cr = new CollisionResult(); cr.Hit = hit; if (hit) { cr.Normal = new Location(rcr.HitData.Normal); cr.Position = new Location(rcr.HitData.Location); if (rcr.HitObject is EntityCollidable) { cr.HitEnt = ((EntityCollidable)rcr.HitObject).Entity; } else { cr.HitEnt = null; // Impacted static world } } else { cr.Normal = Location.Zero; cr.Position = end; cr.HitEnt = null; } return cr; }
public CollisionEventArgs(CollisionResult cr) { Info = cr; }
/// <summary> /// Returns information on what a cuboid-shaped line trace would collide with, if anything. /// </summary> /// <param name="start">The start of the line.</param> /// <param name="end">The end of the line.</param> /// <param name="filter">The collision filter, input a BEPU BroadPhaseEntry and output whether collision should be allowed.</param> /// <returns>The collision details.</returns> public CollisionResult CuboidLineTrace(ConvexShape shape, Location start, Location end, Func<BroadPhaseEntry, bool> filter = null) { Vector3 e = new Vector3((double)(end.X - start.X), (double)(end.Y - start.Y), (double)(end.Z - start.Z)); RigidTransform rt = new RigidTransform(new Vector3((double)start.X, (double)start.Y, (double)start.Z)); RayCastResult rcr; bool hit; if (filter == null) { hit = World.ConvexCast(shape, ref rt, ref e, out rcr); } else { hit = World.ConvexCast(shape, ref rt, ref e, filter, out rcr); } CollisionResult cr = new CollisionResult(); cr.Hit = hit; if (hit) { cr.Normal = new Location(rcr.HitData.Normal); cr.Position = new Location(rcr.HitData.Location); if (rcr.HitObject is EntityCollidable) { cr.HitEnt = ((EntityCollidable)rcr.HitObject).Entity; } else { cr.HitEnt = null; // Impacted static world } } else { cr.Normal = Location.Zero; cr.Position = end; cr.HitEnt = null; } return cr; }