protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (!(target is MarioCharacter mario)) { return; } if (!mario.Active) { return; } if (top) { ChangeLives(); } eventInfo = EventArgs.Empty; ScorePoints(Const.SCORE_FLAG_MAX * height / maxHeight); World.Add(new PopingUpPoints(World, Boundary.Location, Const.SCORE_FLAG_MAX * height / maxHeight)); flag.PullDown(); mario.FlagPole(); HandlerTimeScore?.Invoke(this, eventInfo); }
// Constructors. public BodyModule() { collidesWith = CollisionMode.Nothing; position = Vector3.zero; velocity = Vector3.zero; rotation = Quaternion.identity; }
public BodyModule(BodyModule other) { collidesWith = other.collidesWith; position = other.position; velocity = other.velocity; rotation = other.rotation; }
private void ChangeCollisionMode(CollisionMode mode) { this.mode = mode; ResetSimulation(); switch (mode) { case CollisionMode.SPHERE: ChangeActivityOfGaltonBoard(CollisionMode.SPHERE, true); break; case CollisionMode.AABB: ChangeActivityOfGaltonBoard(CollisionMode.AABB, true); break; case CollisionMode.OBB: ChangeActivityOfGaltonBoard(CollisionMode.OBB, true); break; case CollisionMode.MESH: ChangeActivityOfGaltonBoard(CollisionMode.MESH, true); break; } }
protected override bool IntersectsImpl(CollisionMode thisCollisionMode, IExtent otherExtent, CollisionMode otherCollisionMode) { switch (CollisionChecker.GetCollisionInteractionType(thisCollisionMode, otherCollisionMode)) { case CollisionInteractionType.ExtentVsInnerCircle: case CollisionInteractionType.InnerCircleVsInnerCircle: return(ExtentIntersector.AreInIntersectionCircleVsCircle(this, otherExtent)); case CollisionInteractionType.ExtentVsExtent: case CollisionInteractionType.InnerCircleVsExtent: return(ExtentIntersector.AreInIntersectionCircleVsExtent(this, otherExtent)); case CollisionInteractionType.ExtentVsPoint: case CollisionInteractionType.InnerCircleVsPoint: return(ExtentIntersector.AreInIntersectionExtentVsPoint(this, otherExtent)); case CollisionInteractionType.PointVsCircle: case CollisionInteractionType.PointVsExtent: return(ExtentIntersector.AreInIntersectionExtentVsPoint(otherExtent, this)); case CollisionInteractionType.PointVsPoint: case CollisionInteractionType.Invalid: default: return(false); } }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { switch (target) { case Mario mario: OnCollisionMario(mario, mode, corner); break; case Brick brick when brick.State is Hidden: break; case Question question when question.State is Blocks.QuestionStates.Hidden: break; case IGameObject _ when target is Brick || target is Question || target is Floor || target is Pipeline || target is Stair: if (mode == CollisionMode.Left) { Bounce(mode, new Vector2(), 1); ChangeFacing(FacingMode.right); } else if (mode == CollisionMode.Right) { Bounce(mode, new Vector2(), 1); ChangeFacing(FacingMode.left); } else if (mode == CollisionMode.Bottom) { Bounce(mode, new Vector2()); } break; case FireBall _: Defeat(); break; case Koopa koopa: if (koopa.State is MovingShell || koopa.State is NewlyMovingShell) { Defeat(); } break; case Beetle beetle: if (beetle.State is BeetleStates.MovingShell || beetle.State is BeetleStates.NewlyMovingShell) { Defeat(); } break; } }
protected override void OnCollideWorld(CollisionMode mode, CollisionMode modePassive) { Bounce(mode, new Vector2()); if (mode == CollisionMode.InnerTop) { onFloor = false; } }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { }
public CollisionMessage(Entity target, Entity hit, bool isTrigger, CollisionMode mode) { Target = target; Hit = hit; IsTrigger = isTrigger; Mode = mode; }
/// <summary> /// Change the mesh collision mode of all frames /// </summary> /// <param name="collisionMode">The CollisonMode to change to</param> public void ChangeCollisionMode(CollisionMode collisionMode) { CollisionMode = collisionMode; foreach (Frame frame in Frames) { frame.GenerateMeshColliders(); } }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { switch (target.GetType().Name) { case "MarioCharacter": Mario mario = (Mario)target; if (mario.ProtectionState is Starred) { Defeat(); } break; case "Brick": if (((Brick)target).State is Hidden) { break; } goto case "Stair"; case "Question": if (((Question)target).State is Blocks.QuestionStates.Hidden) { break; } goto case "Stair"; case "Floor": onFloor = true; break; case "Pipeline": case "Stair": if (mode == CollisionMode.Left) { Bounce(mode, new Vector2(), 1); ChangeFacing(FacingMode.right); } else if (mode == CollisionMode.Right) { Bounce(mode, new Vector2(), 1); ChangeFacing(FacingMode.left); } else if (mode == CollisionMode.Bottom) { Bounce(mode, new Vector2()); } break; } }
public bool Intersects(CollisionMode thisCollisionMode, IExtent otherExtent, CollisionMode otherCollisionMode) { if ((null == otherExtent) || (thisCollisionMode == CollisionMode.None || otherCollisionMode == CollisionMode.None) || (thisCollisionMode == CollisionMode.CenterPoint && otherCollisionMode == CollisionMode.CenterPoint)) { return(false); } return(IntersectsImpl(thisCollisionMode, otherExtent, otherCollisionMode)); }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (target is Mario && state is Normal) { Collect(); } }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (target is Mario && state is StarStates.Normal) { Collect(); } if (state is StarStates.Normal) { switch (target) { case Brick brick when brick.State is Hidden: break; case Question question when question.State is Blocks.QuestionStates.Hidden: break; case IGameObject _ when target is Brick || target is Question || target is Floor || target is Pipeline || target is Stair: if (mode == CollisionMode.Top) { Bounce(mode, new Vector2()); } if (mode == CollisionMode.Left || mode == CollisionMode.InnerLeft && corner == CornerMode.Center) { Bounce(mode, new Vector2(), 1); Facing = FacingMode.right; } else if (mode == CollisionMode.Right || mode == CollisionMode.InnerRight && corner == CornerMode.Center) { Bounce(mode, new Vector2(), 1); Facing = FacingMode.left; } if (mode == CollisionMode.Bottom || mode == CollisionMode.InnerBottom && corner == CornerMode.Center) { Bounce(mode, new Vector2()); SetVerticalVelocity(-Const.VELOCITY_STAR_V); } break; } } }
public Buffering(List<Particle> SeedList, double Prec, double Soft, double MaxV, double Grav, bool Coll, double CollD, CollisionMode CM, UniverseBoundaryType BT, double Size) { InitializeComponent(); ParticleList = SeedList; Precision = Prec; SofteningValue = Soft; MaxVelocity = MaxV; GravityConstant = Grav; Collisions = Coll; CollisionsDivider = CollD; CollisionType = CM; BoundaryType = BT; UniverseSize = Size; }
private void ChangeActivityOfGaltonBoard(CollisionMode mode, bool activity) { switch (mode) { case CollisionMode.SPHERE: if (galtonSphere != null) { galtonSphere.SetActive(activity); } else { Debug.LogWarning("Couldn't find \"GaltonBoardSphere\" object."); } break; case CollisionMode.AABB: if (galtonAABB != null) { galtonAABB.SetActive(activity); } else { Debug.LogWarning("Couldn't find \"GaltonBoardAABB\" object."); } break; case CollisionMode.OBB: if (galtonOBB != null) { galtonOBB.SetActive(activity); } else { Debug.LogWarning("Couldn't find \"GaltonBoardOBB\" object."); } break; case CollisionMode.MESH: if (galtonMesh != null) { galtonMesh.SetActive(activity); } else { Debug.LogWarning("Couldn't find \"GaltonBoardMesh\" object."); } break; } }
private void OnCollisionMario(Mario mario, CollisionMode mode, CornerMode corner) { if (mario.MovementState is Crouching && !(mario.ProtectionState is Starred) && (state is MovingShell || state is NewlyMovingShell)) { Wear(mario); } else if (mario.ProtectionState is Starred) { Defeat(); } else if ((state is BeetleStates.Normal || state is MovingShell) && !(mario.ProtectionState is Dead)) { if (mode == CollisionMode.Top) { JumpOn(); } else { mario.Downgrade(); } } else if (state is Defeated && !(mario.ProtectionState is Dead)) { switch (mode) { case CollisionMode.Left: ChangeFacing(FacingMode.right); Pushed(); break; case CollisionMode.Right: ChangeFacing(FacingMode.left); Pushed(); break; case CollisionMode.Top when corner == CornerMode.Left: ChangeFacing(FacingMode.right); Pushed(); break; case CollisionMode.Top when corner == CornerMode.Right: ChangeFacing(FacingMode.left); Pushed(); break; } } }
void RecreateTilemap(string name, int order, CollisionMode mode, int layer) { name = $"L{order}_{name}"; var tilemap = GetComponentsInChildren <Tilemap>() .FirstOrDefault(t => t.name == name); if (!tilemap) { tilemap = new GameObject(name).AddComponent <Tilemap>(); tilemap.transform.parent = transform; } tilemap.gameObject.isStatic = true; tilemap.gameObject.layer = layer; var renderer = tilemap.gameObject.GetOrAddComponent <TilemapRenderer>(); renderer.sortingOrder = order; renderer.material = spriteMaterial; switch (mode) { case CollisionMode.None: break; case CollisionMode.Collider: { var collider = tilemap.gameObject.GetOrAddComponent <TilemapCollider>(); break; } case CollisionMode.Trigger: { var collider = tilemap.gameObject.GetOrAddComponent <TilemapCollider2D>(); var composite = tilemap.gameObject.GetOrAddComponent <CompositeCollider2D>(); var rigidbody = tilemap.gameObject.GetOrAddComponent <Rigidbody2D>(); collider.isTrigger = true; collider.usedByComposite = true; composite.isTrigger = true; composite.generationType = CompositeCollider2D.GenerationType.Synchronous; composite.geometryType = CompositeCollider2D.GeometryType.Polygons; rigidbody.bodyType = RigidbodyType2D.Static; break; } default: break; } UnityEditor.EditorUtility.SetDirty(tilemap); }
public WWorld() { m_dtStopwatch = new System.Diagnostics.Stopwatch(); m_persistentLines = new WLineBatcher(); m_undoStack = new WUndoStack(); //m_actorEditor = new WActorEditor(this); m_ActorMode = new ActorMode(this); m_CollisionMode = new CollisionMode(this); CurrentMode = m_ActorMode; m_sceneViews = new List <WSceneView>(); WSceneView perspectiveView = new WSceneView(); m_sceneViews.AddRange(new[] { perspectiveView }); }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (target is FireBall) { Defeat(); } if (target is Koopa koopa) { if (koopa.State is MovingShell || koopa.State is NewlyMovingShell) { Defeat(); } } }
public Physics(string name, GameComponent parent, Matrix localTransform, Vector3 boundingBoxExtents, Vector3 boundingBoxPos, float mass, float i, float linearDamping, float angularDamping, Vector3 gravity, OrientMode orientation = OrientMode.Fixed) : base(parent.Manager, name, parent, localTransform, boundingBoxExtents, boundingBoxPos) { Mass = mass; Velocity = Vector3.Zero; AngularVelocity = Vector3.Zero; I = i; LinearDamping = linearDamping; AngularDamping = angularDamping; Gravity = gravity; Restitution = 0.01f; Friction = 0.99f; IsSleeping = false; PreviousPosition = LocalTransform.Translation; PreviousVelocity = Vector3.Zero; IsInLiquid = false; CollisionType = CollisionManager.CollisionType.Dynamic; CollideMode = CollisionMode.All; Orientation = orientation; SleepTimer = new Timer(5.0f, true); CurrentVoxel = new Voxel(); }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (target is Mario mario && mode is CollisionMode.Top) { if (mario.MovementState is Crouching && Database.IsEntrance(this)) { //TODO:Add warping state to model to allow sound controller play warping sound //SoundManager.Pipe.Play(); switch (Type) { case "LeftIn": if (mario.Boundary.Center.X > Boundary.Center.X) { // TODO // switchingPlayer = mario; } break; case "RightIn": if (mario.Boundary.Center.X < Boundary.Center.X) { // TODO // switchingPlayer = mario; } break; } // TODO: mario.freeze } } }
protected override void OnCollideWorld(CollisionMode mode, CollisionMode modePassive) { //throw new NotImplementedException(); }
void DrawBoundingVolume(CustomCollider one, Color color, bool forceDraw = false, CustomCollider.ColliderType cType = CustomCollider.ColliderType.Box, CollisionMode mode = CollisionMode.SAT) { if (showBoundingVolumes.isOn || forceDraw) { if (mode == CollisionMode.AABB) { var xMin1 = one.transform.position.x + one.colliderOffset.x - (one.colliderSize.x * one.transform.lossyScale.x) / 2; var xMax1 = one.transform.position.x + one.colliderOffset.x + (one.colliderSize.x * one.transform.lossyScale.x) / 2; var yMin1 = one.transform.position.y + one.colliderOffset.y - (one.colliderSize.y * one.transform.lossyScale.y) / 2; var yMax1 = one.transform.position.y + one.colliderOffset.y + (one.colliderSize.y * one.transform.lossyScale.y) / 2; var zMin1 = one.transform.position.z + one.colliderOffset.z - (one.colliderSize.z * one.transform.lossyScale.z) / 2; var zMax1 = one.transform.position.z + one.colliderOffset.z + (one.colliderSize.z * one.transform.lossyScale.z) / 2; GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMin1), new Vector3(xMax1, yMin1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMin1, yMin1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMax1, yMin1, zMax1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMin1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMin1, zMax1), new Vector3(xMin1, yMax1, zMax1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMin1), new Vector3(xMax1, yMax1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMin1), new Vector3(xMax1, yMax1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMax1), new Vector3(xMin1, yMax1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMin1, yMax1, zMax1), new Vector3(xMax1, yMax1, zMax1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMax1, yMax1, zMax1), new Vector3(xMax1, yMax1, zMin1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMax1, zMax1), color, Time.deltaTime, true); GLDebug.DrawLine(new Vector3(xMax1, yMin1, zMax1), new Vector3(xMax1, yMax1, zMax1), color, Time.deltaTime, true); } else { if (one.colliderType == CustomCollider.ColliderType.Box) { var box = ((CustomBoxCollider)one).GetOrientedBoxBounds(); GLDebug.DrawLine(box.dot1, box.dot2, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot2, box.dot6, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot5, box.dot6, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot5, box.dot1, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot4, box.dot8, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot3, box.dot7, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot4, box.dot3, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot8, box.dot7, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot1, box.dot4, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot2, box.dot3, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot6, box.dot7, color, Time.deltaTime, true); GLDebug.DrawLine(box.dot5, box.dot8, color, Time.deltaTime, true); } else if (one.colliderType == CustomCollider.ColliderType.Sphere) { var sphere = ((CustomSphereCollider)one); Vector3 previousDirection = sphere.U().normalized; for (int x = 0; x <= 20; x++) { Vector3 start = sphere.transform.position + previousDirection * sphere.radius; Vector3 newDirection = Quaternion.Euler(0, x * (360 / 20), 0) * sphere.U(); Vector3 end = sphere.transform.position + newDirection.normalized * sphere.radius; previousDirection = newDirection; GLDebug.DrawLine(start, end, color, Time.deltaTime, true); } previousDirection = sphere.V().normalized; for (int x = 0; x <= 20; x++) { Vector3 start = sphere.transform.position + previousDirection * sphere.radius; Vector3 newDirection = Quaternion.Euler(0, 0, x * (360 / 20)) * sphere.V(); Vector3 end = sphere.transform.position + newDirection.normalized * sphere.radius; previousDirection = newDirection; GLDebug.DrawLine(start, end, color, Time.deltaTime, true); } previousDirection = sphere.W().normalized; for (int x = 0; x <= 20; x++) { Vector3 start = sphere.transform.position + previousDirection * sphere.radius; Vector3 newDirection = Quaternion.Euler(x * (360 / 20), 0, 0) * sphere.W(); Vector3 end = sphere.transform.position + newDirection.normalized * sphere.radius; previousDirection = newDirection; GLDebug.DrawLine(start, end, color, Time.deltaTime, true); } } } } }
protected override void OnCollideWorld(CollisionMode mode, CollisionMode modePassive) { }
public static CollisionInteractionType GetCollisionInteractionType(CollisionMode a, CollisionMode b) { CollisionInteractionType type = CollisionInteractionType.Invalid; switch (a) { case CollisionMode.CenterPoint: switch (b) { case CollisionMode.CenterPoint: type = CollisionInteractionType.PointVsPoint; break; case CollisionMode.InnerCenterCircle: type = CollisionInteractionType.PointVsCircle; break; case CollisionMode.Extent: type = CollisionInteractionType.PointVsExtent; break; default: break; } break; case CollisionMode.InnerCenterCircle: switch (b) { case CollisionMode.CenterPoint: type = CollisionInteractionType.InnerCircleVsPoint; break; case CollisionMode.InnerCenterCircle: type = CollisionInteractionType.InnerCircleVsInnerCircle; break; case CollisionMode.Extent: type = CollisionInteractionType.InnerCircleVsExtent; break; default: break; } break; case CollisionMode.Extent: switch (b) { case CollisionMode.CenterPoint: type = CollisionInteractionType.ExtentVsPoint; break; case CollisionMode.InnerCenterCircle: type = CollisionInteractionType.ExtentVsInnerCircle; break; case CollisionMode.Extent: type = CollisionInteractionType.ExtentVsExtent; break; default: break; } break; default: type = CollisionInteractionType.Invalid; break; } return(type); }
/// <summary> /// Change the mesh collision mode of all frames /// </summary> /// <param name="collisionMode">The CollisonMode to change to</param> public void ChangeCollisionMode(CollisionMode collisionMode) { CollisionMode = collisionMode; foreach (Frame frame in Frames) frame.GenerateMeshColliders(); }
protected abstract bool IntersectsImpl(CollisionMode thisCollisionMode, IExtent otherExtent, CollisionMode otherCollisionMode);
public NiCollisionData() { propagationMode = (PropagationMode)0; collisionMode = (CollisionMode)0; useAbv = (byte)0; }
private void OnCollisionMario(Mario mario, CollisionMode mode, CornerMode corner) { if (mode == CollisionMode.Top && corner == CornerMode.Top && !(mario.ProtectionState is Dead) || mario.ProtectionState is Starred) { Defeat(); } else if ((state is KoopaStates.Normal || state is MovingShell) && !(mario.ProtectionState is Dead)) { if (mode == CollisionMode.Top) { JumpOn(); } else { mario.Downgrade(); } } else if (state is Defeated && !(mario.ProtectionState is Dead)) { switch (mode) { case CollisionMode.Left: ChangeFacing(FacingMode.right); Pushed(); break; case CollisionMode.Right: ChangeFacing(FacingMode.left); Pushed(); break; case CollisionMode.Top when corner == CornerMode.Left: ChangeFacing(FacingMode.right); Pushed(); break; case CollisionMode.Top when corner == CornerMode.Right: ChangeFacing(FacingMode.left); Pushed(); break; case CollisionMode.Bottom: break; case CollisionMode.InnerLeft: break; case CollisionMode.InnerRight: break; case CollisionMode.InnerTop: break; case CollisionMode.InnerBottom: break; default: throw new ArgumentOutOfRangeException(nameof(mode), mode, null); } } }
protected override void OnCollision( IGameObject target, CollisionMode mode, CollisionMode modePassive, CornerMode corner, CornerMode cornerPassive) { if (ProtectionState is Dead) { return; } switch (target.GetType().Name) { //TODO: add cases when collision mode is OutLeftTop/OutRightTop that Mario will be squeezed to side of the brick //NOTE: if collision mode is OutLeftTop/OutRightTop, be careful that if there are blocks surronding the target, no squeeze will happen!! case "Brick": case "Question": bool isHidden; bool isBumping; Brick brick = target as Brick; Question question = target as Question; if (brick != null) { if (brick.State is Destroyed) { break; } isHidden = brick.State is Hidden; isBumping = brick.State is Bumped; } else if (question != null) { isHidden = question.State is Blocks.QuestionStates.Hidden; isBumping = question.State is Blocks.QuestionStates.Bumped; } else { // never reach isHidden = false; isBumping = false; } if (mode == CollisionMode.Top) { bool bumped = Bounce(mode, new Vector2(), 1); if (isBumping) { //Move(new Point(0, 1)); } else if (bumped) { if (brick != null) { brick.Bump(this); } else if (question != null) { question.Bump(this); } } } else if (!isHidden) { goto case "Stair"; } break; case "Pipeline": if (MovementState is Crouching && Database.IsEntrance((Pipeline)target)) { string type = (target as Pipeline).Type; if (type == "LeftIn") { if (Boundary.Center.X > target.Boundary.Center.X) { Bounce(CollisionMode.Left, new Vector2()); Bounce(CollisionMode.Right, new Vector2()); } else { goto case "Floor"; } } else if (type == "RightIn") { if (Boundary.Center.X < target.Boundary.Center.X) { Bounce(CollisionMode.Left, new Vector2()); Bounce(CollisionMode.Right, new Vector2()); } else { goto case "Floor"; } } } else { goto case "Floor"; } break; case "CompressedBlock": case "Floor": case "Stair": case "Flag": Bounce(mode, new Vector2()); if (mode == CollisionMode.Bottom) { ApplyHorizontalFriction(Const.ACCEL_F_GROUND); MovementState.Land(); } break; case "Goomba": if (target is Goomba goomba && mode != CollisionMode.Bottom) { if (goomba.State is Enemies.GoombaStates.Normal && !(ProtectionState is Starred)) { Downgrade(); } } else if (!(protectionState is Starred)) { Bounce(mode, new Vector2(), 0.5f); } break;
bool CheckCollision(CustomCollider one_, CustomCollider two_, out CustomCollisionInfo hitInfo, CollisionMode mode = CollisionMode.SAT)// AABB - AABB collision { hitInfo = new CustomCollisionInfo(); if (one_.colliderType == CustomCollider.ColliderType.Box && two_.colliderType == CustomCollider.ColliderType.Box) { CustomBoxCollider one = one_ as CustomBoxCollider; CustomBoxCollider two = two_ as CustomBoxCollider; if (mode == CollisionMode.SAT) { List <Vector3> box1Points = one.GetOrientedBoxBounds().GetPoints(); List <Vector3> box2Points = two.GetOrientedBoxBounds().GetPoints(); var P1 = GetMinMaxObj(box1Points, one.V()); var P2 = GetMinMaxObj(box2Points, one.V()); var Q1 = GetMinMaxObj(box1Points, one.U()); var Q2 = GetMinMaxObj(box2Points, one.U()); var R1 = GetMinMaxObj(box1Points, one.W()); var R2 = GetMinMaxObj(box2Points, one.W()); var S1 = GetMinMaxObj(box1Points, two.V()); var S2 = GetMinMaxObj(box2Points, two.V()); var T1 = GetMinMaxObj(box1Points, two.U()); var T2 = GetMinMaxObj(box2Points, two.U()); var U1 = GetMinMaxObj(box1Points, two.W()); var U2 = GetMinMaxObj(box2Points, two.W()); bool P = P1.max < P2.min || P2.max < P1.min; bool Q = Q1.max < Q2.min || Q2.max < Q1.min; bool R = R1.max < R2.min || R2.max < R1.min; bool S = S1.max < S2.min || S2.max < S1.min; bool T = T1.max < T2.min || T2.max < T1.min; bool U = U1.max < U2.min || U2.max < U1.min; //Check if seperated bool res = P || Q || R || S || T || U; if (!res) { hitInfo.intersectionSize.x = Mathf.Max(Mathf.Min(two.GetOrientedBoxBounds().max.x, one.GetOrientedBoxBounds().max.x), 0); hitInfo.intersectionSize.y = Mathf.Max(Mathf.Min(two.GetOrientedBoxBounds().max.y, one.GetOrientedBoxBounds().max.x), 0); hitInfo.intersectionSize.z = Mathf.Max(Mathf.Min(two.GetOrientedBoxBounds().max.z, one.GetOrientedBoxBounds().max.x), 0); DrawBoundingVolume(one, Color.red, true); DrawBoundingVolume(two, Color.red, true); } return(!res); } else { var xMin1 = one.GetOrientedBoxBounds().min.x; var xMax1 = one.GetOrientedBoxBounds().max.x; var yMin1 = one.GetOrientedBoxBounds().min.y; var yMax1 = one.GetOrientedBoxBounds().max.y; var zMin1 = one.GetOrientedBoxBounds().min.z; var zMax1 = one.GetOrientedBoxBounds().max.z; var xMin2 = two.GetOrientedBoxBounds().min.x; var xMax2 = two.GetOrientedBoxBounds().max.x; var yMin2 = two.GetOrientedBoxBounds().min.y; var yMax2 = two.GetOrientedBoxBounds().max.y; var zMin2 = two.GetOrientedBoxBounds().min.z; var zMax2 = two.GetOrientedBoxBounds().max.z; bool res = xMin1 <= xMax2 && xMax1 >= xMin2 && yMin1 <= yMax2 && yMax1 >= yMin2 && zMin1 <= zMax2 && zMax1 >= zMin2; if (res) { hitInfo.intersectionSize.x = Mathf.Max(Mathf.Min(xMax2, xMax1), 0); hitInfo.intersectionSize.y = Mathf.Max(Mathf.Min(yMax2, yMax1), 0); hitInfo.intersectionSize.z = Mathf.Max(Mathf.Min(zMax2, zMax1), 0); DrawBoundingVolume(one, Color.red, true); DrawBoundingVolume(two, Color.red, true); } return(res); } } if (one_.colliderType == CustomCollider.ColliderType.Sphere && two_.colliderType == CustomCollider.ColliderType.Box) { return(BoxVsSphereCollision((CustomBoxCollider)two_, (CustomSphereCollider)one_, out hitInfo)); } else if (one_.colliderType == CustomCollider.ColliderType.Box && two_.colliderType == CustomCollider.ColliderType.Sphere) { return(BoxVsSphereCollision((CustomBoxCollider)one_, (CustomSphereCollider)two_, out hitInfo)); } return(false); }
/// <summary> /// Checks a list of particles for collisions and combines particles as neccessary. /// </summary> public static List<Particle> CheckCollisions(List<Particle> InputList, double Precision, double CollisionDivider, CollisionMode CollisionType) { if (CollisionType == CollisionMode.PerfectlyInelastic) return CheckCollisions_PIE(InputList, Precision, CollisionDivider); if (CollisionType == CollisionMode.PerfectlyElastic) return CheckCollisions_PE(InputList, Precision, CollisionDivider); return null; }