///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { instancedMesh = entryA as InstancedMesh; convex = entryB as ConvexCollidable; if (instancedMesh == null || convex == null) { instancedMesh = entryB as InstancedMesh; convex = entryA as ConvexCollidable; if (instancedMesh == null || convex == null) throw new Exception("Inappropriate types used to initialize pair."); } //Contact normal goes from A to B. broadPhaseOverlap.entryA = convex; broadPhaseOverlap.entryB = instancedMesh; UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, instancedMesh.material); base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mobileMesh = entryA as MobileMeshCollidable; convex = entryB as ConvexCollidable; if (mobileMesh == null || convex == null) { mobileMesh = entryB as MobileMeshCollidable; convex = entryA as ConvexCollidable; if (mobileMesh == null || convex == null) throw new ArgumentException("Inappropriate types used to initialize pair."); } //Contact normal goes from A to B. broadPhaseOverlap.entryA = convex; broadPhaseOverlap.entryB = mobileMesh; //It's possible that the convex does not have an entity if it is a proxy for a non-entity collidable. //Similarly, the mesh could be a query object. UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, mobileMesh.entity != null ? mobileMesh.entity.material : null); base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { terrain = entryA as Terrain; convex = entryB as ConvexCollidable; if (terrain == null || convex == null) { terrain = entryB as Terrain; convex = entryA as ConvexCollidable; if (terrain == null || convex == null) throw new ArgumentException("Inappropriate types used to initialize pair."); } //Contact normal goes from A to B. broadPhaseOverlap.entryA = convex; broadPhaseOverlap.entryB = terrain; UpdateMaterialProperties(convex.entity != null ? convex.entity.material : null, terrain.material); base.Initialize(entryA, entryB); }
public override void Remove(BroadPhaseEntry entry) { base.Remove(entry); entriesX.Remove(entry); entriesY.Remove(entry); entriesZ.Remove(entry); }
/// <summary> /// Adds an entry to the broad phase. /// </summary> /// <param name="entry">Entry to add.</param> public override void Add(BroadPhaseEntry entry) { base.Add(entry); //Entities do not set up their own bounding box before getting stuck in here. If they're all zeroed out, the tree will be horrible. Vector3 offset; Vector3.Subtract(ref entry.boundingBox.Max, ref entry.boundingBox.Min, out offset); if (offset.X * offset.Y * offset.Z == 0) entry.UpdateBoundingBox(); //binary search for the approximately correct location. This helps prevent large first-frame sort times. int minIndex = 0; //inclusive int maxIndex = entries.Count; //exclusive int index = 0; while (maxIndex - minIndex > 0) { index = (maxIndex + minIndex) / 2; if (entries.Elements[index].boundingBox.Min.X > entry.boundingBox.Min.X) maxIndex = index; else if (entries.Elements[index].boundingBox.Min.X < entry.boundingBox.Min.X) minIndex = ++index; else break; //Found an equal value! } entries.Insert(index, entry); }
public bool IgnoreThis(BroadPhaseEntry entry) { if (entry is EntityCollidable && ((EntityCollidable)entry).Entity == Entity) { return false; } return Collision.ShouldCollide(entry); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { //Child initialization is responsible for setting up the entries. //Child initialization is responsible for setting up the manifold, if any. manifoldConstraintGroup.Initialize(EntityA, EntityB); base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { compoundInfoB = entryB as CompoundCollidable; if (compoundInfoB == null) { throw new ArgumentException("Inappropriate types used to initialize pair."); } base.Initialize(entryA, entryB); }
public bool DontLandOnPlanes(BroadPhaseEntry bpe) { if (bpe is EntityCollidable) { EntityCollidable ec = bpe as EntityCollidable; if (ec.Entity != null && (ec.Entity.Tag is PlayerEntity || ec.Entity.Tag is PlaneEntity)) { return false; } } return true; }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { //Child initialization is responsible for setting up the entries. ContactManifold.Initialize(CollidableA, CollidableB); ContactConstraint.Initialize(EntityA, EntityB, this); base.Initialize(entryA, entryB); }
public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { base.Initialize(entryA, entryB); convex = entryA as ConvexCollidable; if (convex == null) { convex = entryB as ConvexCollidable; if (convex == null) { throw new ArgumentException("Incorrect types passed to pair handler."); } } }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mesh = entryA as InstancedMesh; if (mesh == null) { mesh = entryB as InstancedMesh; if (mesh == null) { throw new ArgumentException("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { convexInfo = entryA as ConvexCollidable; if (convexInfo == null) { convexInfo = entryB as ConvexCollidable; if (convexInfo == null) { throw new Exception("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
public override void Add(BroadPhaseEntry entry) { base.Add(entry); //binary search for the approximately correct location. This helps prevent large first-frame sort times. //X Axis: int minIndex = 0; //inclusive int maxIndex = entriesX.Count; //exclusive int index = 0; while (maxIndex - minIndex > 0) { index = (maxIndex + minIndex) / 2; if (entriesX.Elements[index].boundingBox.Min.X > entry.boundingBox.Min.X) maxIndex = index; else if (entriesX.Elements[index].boundingBox.Min.X < entry.boundingBox.Min.X) minIndex = ++index; else break; //Found an equal value! } entriesX.Insert(index, entry); //Y Axis: minIndex = 0; //inclusive maxIndex = entriesY.Count; //exclusive while (maxIndex - minIndex > 0) { index = (maxIndex + minIndex) / 2; if (entriesY.Elements[index].boundingBox.Min.Y > entry.boundingBox.Min.Y) maxIndex = index; else if (entriesY.Elements[index].boundingBox.Min.Y < entry.boundingBox.Min.Y) minIndex = ++index; else break; //Found an equal value! } entriesY.Insert(index, entry); //Z Axis: minIndex = 0; //inclusive maxIndex = entriesZ.Count; //exclusive while (maxIndex - minIndex > 0) { index = (maxIndex + minIndex) / 2; if (entriesZ.Elements[index].boundingBox.Min.Z > entry.boundingBox.Min.Z) maxIndex = index; else if (entriesZ.Elements[index].boundingBox.Min.Z < entry.boundingBox.Min.Z) minIndex = ++index; else break; //Found an equal value! } entriesZ.Insert(index, entry); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { //Other member of the pair is initialized by the child. staticGroup = entryA as StaticGroup; if (staticGroup == null) { staticGroup = entryB as StaticGroup; if (staticGroup == null) { throw new Exception("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { //Other member of the pair is initialized by the child. mobileMesh = entryA as MobileMeshCollidable; if (mobileMesh == null) { mobileMesh = entryB as MobileMeshCollidable; if (mobileMesh == null) { throw new ArgumentException("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mesh = entryA as MobileMeshCollidable; if (mesh == null) { mesh = entryB as MobileMeshCollidable; if (mesh == null) { throw new Exception("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { terrain = entryA as Terrain; if (terrain == null) { terrain = entryB as Terrain; if (terrain == null) { throw new ArgumentException("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { //Other member of the pair is initialized by the child. compoundInfo = entryA as CompoundCollidable; if (compoundInfo == null) { compoundInfo = entryB as CompoundCollidable; if (compoundInfo == null) { throw new Exception("Inappropriate types used to initialize pair."); } } base.Initialize(entryA, entryB); }
public bool Test(BroadPhaseEntry test) { // TODO: P2: We want to be able to bash objects and terrain to create dust, decals, sounds, smash crates, etc. bool isFoe = false; EntityCollidable ec = test as EntityCollidable; if (ec != null && ec.Entity != null && ec.Entity.Tag != null) { int viewedActorId = (int)(ec.Entity.Tag); isFoe = mLookForPlayers ? GameResources.ActorManager.IsPlayer(viewedActorId) : GameResources.ActorManager.IsMob(viewedActorId); } return isFoe; }
/// <summary> /// Adds an entry to the broad phase. /// </summary> /// <param name="entry">Entry to add.</param> public override void Add(BroadPhaseEntry entry) { base.Add(entry); //Entities do not set up their own bounding box before getting stuck in here. If they're all zeroed out, the tree will be horrible. Vector3 offset; Vector3.Subtract(ref entry.boundingBox.Max, ref entry.boundingBox.Min, out offset); if (offset.X * offset.Y * offset.Z == 0) entry.UpdateBoundingBox(); var newEntry = entryPool.Take(); newEntry.Initialize(entry); entries.Add(newEntry); //Add the object to the grid. for (int i = newEntry.previousMin.Y; i <= newEntry.previousMax.Y; i++) { for (int j = newEntry.previousMin.Z; j <= newEntry.previousMax.Z; j++) { var index = new Int2 {Y = i, Z = j}; cellSet.Add(ref index, newEntry); } } }
void RemoveFriction(EntityCollidable sender, BroadPhaseEntry other, NarrowPhasePair pair) { var collidablePair = pair as CollidablePairHandler; if (collidablePair != null) { //The default values for InteractionProperties is all zeroes- zero friction, zero bounciness. //That's exactly how we want the character to behave when hitting objects. collidablePair.UpdateMaterialProperties(new InteractionProperties()); } }
bool IgnoreEverythingButWater(BroadPhaseEntry entry) { return entry.CollisionRules.Group == CollisionUtil.Water; }
///<summary> /// Initializes the pair handler. ///</summary> ///<param name="entryA">First entry in the pair.</param> ///<param name="entryB">Second entry in the pair.</param> public override void Initialize(BroadPhaseEntry entryA, BroadPhaseEntry entryB) { mesh = (MobileMeshCollidable)entryB; base.Initialize(entryA, entryB); }
bool SupportRayFilterFunction(BroadPhaseEntry entry) { //Only permit an object to be used as a support if it fully collides with the character. return CollisionRules.CollisionRuleCalculator(entry, characterBody.CollisionInformation) == CollisionRule.Normal; }
public bool IgnoreEntities(BroadPhaseEntry entry) { return !(entry is EntityCollidable); }
internal void Initialize(BroadPhaseEntry entry) { this.item = entry; Grid2DSortAndSweep.ComputeCell(ref entry.boundingBox.Min, out previousMin); Grid2DSortAndSweep.ComputeCell(ref entry.boundingBox.Max, out previousMax); }
bool RayCastFilter(BroadPhaseEntry entry) { return entry != ChasedEntity.CollisionInformation && (entry.CollisionRules.Personal <= CollisionRule.Normal); }
private static bool CameraClipFilter(BroadPhaseEntry test) { return (GameResources.ActorManager.CameraClippingSimObjects.Contains(test.GetHashCode())); }
/// <summary> /// Removes an entry from the broad phase. /// </summary> /// <param name="entry">Entry to remove.</param> public override void Remove(BroadPhaseEntry entry) { base.Remove(entry); for (int i = 0; i < entries.Count; i++) { if (entries.Elements[i].item == entry) { var gridEntry = entries.Elements[i]; entries.RemoveAt(i); //Remove the object from any cells that it is held by. for (int j = gridEntry.previousMin.Y; j <= gridEntry.previousMax.Y; j++) { for (int k = gridEntry.previousMin.Z; k <= gridEntry.previousMax.Z; k++) { var index = new Int2 {Y = j, Z = k}; cellSet.Remove(ref index, gridEntry); } } gridEntry.item = null; entryPool.GiveBack(gridEntry); return; } } }