示例#1
0
 public bool OnCollision(gxtGeom geomA, gxtGeom geomB, gxtCollisionResult collisionResult)
 {
     float scalar = 35.0f;
     gxtDebugDrawer.Singleton.AddLine(geomA.Position, geomA.Position + collisionResult.Normal * scalar, Color.Orange, 0.0f);
     gxtDebugDrawer.Singleton.AddLine(geomB.Position, geomB.Position + collisionResult.Normal * scalar, Color.Orange, 0.0f);
     return true;
 }
示例#2
0
        public bool OnCollision(gxtGeom ga, gxtGeom gb, gxtCollisionResult collisionResult)
        {
            if (ga == geomF)
            {

            }
            //gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Collision between {0} and {1}", geomA.Id, geomB.Id);
            return true;
            /*
            float scalar = 35.0f;
            gxtDebugDrawer.Singleton.AddLine(geomA.Position, geomA.Position + collisionResult.Normal * scalar, Color.Orange, 0.0f);
            gxtDebugDrawer.Singleton.AddLine(geomB.Position, geomB.Position + collisionResult.Normal * scalar, Color.Orange, 0.0f);
            gxtDebugDrawer.Singleton.AddString(geomA.Id.ToString(), geomA.Position, Color.White, 0.0f);
            gxtDebugDrawer.Singleton.AddString(geomB.Id.ToString(), geomB.Position, Color.White, 0.0f);
            */
        }
示例#3
0
        private bool OnOneWayPlatformCollision(gxtGeom ga, gxtGeom gb, gxtCollisionResult cr)
        {
            float tolerance = 0.5f;
            if (ga == geomC)
            {
                //gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "here");
                float dot = Vector2.Dot(cr.Normal, Vector2.UnitY);
                if (dot >= tolerance)
                {
                    //if (gb.HasAttachedBody() && Vector2.Dot(gb.RigidBody.PrevAcceleration, Vector2.UnitY) <= 0.0f)
                        return false;
                }
                else
                {
                    gxtRayHit rayHit;
                    gxtRay downRay = new gxtRay();
                    downRay.Origin = gb.GetWorldCentroid() - new Vector2(0.0f, geomF.LocalAABB.Height * 0.45f);
                    downRay.Direction = Vector2.UnitY;
                    float halfHeight = geomF.LocalAABB.Height * 0.65f;
                    if (world.PhysicsWorld.RayCast(downRay, out rayHit, gxtCollisionGroup.ALL, halfHeight))
                    {

                        gxtRay adjRay = new gxtRay(downRay.Origin * gxtPhysicsWorld.PHYSICS_SCALE, downRay.Direction);
                        gxtDebugDrawer.Singleton.AddRay(adjRay, rayHit.Distance * gxtPhysicsWorld.PHYSICS_SCALE, Color.Green, 0.0f, TimeSpan.FromSeconds(5.0));
                        return false;
                    }
                    else
                    {
                        //return false;
                        gxtRay adjRay = new gxtRay(downRay.Origin * gxtPhysicsWorld.PHYSICS_SCALE, downRay.Direction);
                        gxtDebugDrawer.Singleton.AddRay(adjRay, halfHeight * gxtPhysicsWorld.PHYSICS_SCALE, Color.Green, 0.0f, TimeSpan.FromSeconds(5.0));
                        //return false;
                    }
                }
                //else if (gb.HasAttachedBody() && Vector2.Dot(gb.RigidBody.PrevAcceleration, Vector2.UnitY))
            } else
            {
                gxtDebug.Assert(false, "You didn't set up the swap properly");
            }
            /*
            else if (gb == geomC)
            {
                float dot = Vector2.Dot(cr.Normal, new Vector2(0.0f, -1.0f));
                if (dot >= tolerance)
                {
                    if (gb.HasAttachedBody() && Vector2.Dot(gb.RigidBody.PrevAcceleration, new Vector2(0.0f, -1.0f)) >= 0.0f)
                    return false;
                }
            }
            */
            return true;
        }
示例#4
0
 public bool OnCollision(gxtGeom playerGeom, gxtGeom otherGeom, gxtCollisionResult collisionResult)
 {
     incrementSeperationTime = false;
     //collidingWithWalkableGeom = true;
     return true;
 }
示例#5
0
 public abstract bool Collide(ref gxtPolygon polygonA, Vector2 centroidA, ref gxtPolygon polygonB, out gxtCollisionResult collisionResult);
示例#6
0
 public override bool Collide(ref gxtPolygon polygonA, Vector2 centroidA, ref gxtPolygon polygonB, out gxtCollisionResult collisionResult)
 {
     throw new NotImplementedException();
 }
示例#7
0
文件: RayTestGame.cs 项目: Loko/GXT
 public bool OnCollision(gxtGeom geomA, gxtGeom geomB, gxtCollisionResult collisionResult)
 {
     return true;
 }
示例#8
0
        /// <summary>
        /// Returns extensive collision information about the given polygons
        /// Will determine if intersecting by running the GJK algorithm
        /// It saves the terminating simplex and further uses it for the 
        /// EPA algorithm.  Returns the intersection depth and collision normal as 
        /// part of the gxtCollisionResult return struct.  The normal and depth will 
        /// not be calculated, and thus such information is not realiable, if the intersection 
        /// is false
        /// </summary>
        /// <param name="polyA">Polygon A</param>
        /// <param name="centroidA">Centroid of polygon A</param>
        /// <param name="polyB">Polygon B</param>
        /// <param name="centroidB">Centroid of polygon B</param>
        /// <returns>Collision Result</returns>
        public static gxtCollisionResult Collide(gxtPolygon polyA, Vector2 centroidA, gxtPolygon polyB, Vector2 centroidB)
        {
            // optimal search direction
            Vector2 direction = centroidB - centroidA;
            // simplex vector2 collection
            List<Vector2> simplex;
            List<Vector2> pointsOnA;
            List<Vector2> pointsOnB;
            // the result structure for the collision
            gxtCollisionResult result = new gxtCollisionResult();

            // finishes with terminating simplex from gjk
            // boolean return for intersection
            if (!BuildSimplex(ref polyA, ref polyB, direction, out simplex, out pointsOnA, out pointsOnB))
            {
                result.Intersection = false;
                return result;
            }
            else
            {
                result.Intersection = true;
            }


            // iterations
            int iterations = 0;

            // holder edge information
            Vector2 normal;
            float distance;
            int index;
            Vector2 cpA, cpB;

            /*
            FindClosestPointsSpecial(simplex, pointsOnA, pointsOnB, out cpA, out cpB);
            
            #if (GXT_DEBUG_DRAW_CONTACTS)
            gxtDebugDrawer.Singleton.AddPt(cpA * gxtPhysicsWorld.PHYSICS_SCALE, Color.GreenYellow, 0.0f);
            gxtDebugDrawer.Singleton.AddPt(cpB * gxtPhysicsWorld.PHYSICS_SCALE, Color.GreenYellow, 0.0f);
            #endif

            result.ContactPointA = cpA;
            result.ContactPointB = cpB;
            */

            // calc ordering once, reusable in loop
            int winding = GetWinding(simplex);

            // epa loop
            while (iterations < MAX_ITERATIONS)
            {
                // find closest edge to origin info
                // returns true if it is a vertex

                FindClosestFeature(simplex, winding, out index, out distance, out normal);
                /*
                if (FindClosestFeature(simplex, winding, out index, out distance, out normal))
                {
                    result.Normal = normal;
                    result.Depth = distance;

                    int nextIndex = (index + 1) % simplex.Count;
                    FindClosestPointsHelper(simplex[index], simplex[nextIndex], pointsOnA[index], pointsOnA[nextIndex], pointsOnB[index], pointsOnB[nextIndex], out cpA, out cpB);

                    result.ContactPointA = cpA;
                    result.ContactPointB = cpB;

                    #if (GXT_DEBUG_DRAW_CONTACTS)
                    gxtDebugDrawer.Singleton.AddPt(cpA * gxtPhysicsWorld.PHYSICS_SCALE, Color.Red, 0.0f);
                    gxtDebugDrawer.Singleton.AddPt(cpB * gxtPhysicsWorld.PHYSICS_SCALE, Color.Red, 0.0f);
                    #endif

                    #if GXT_DEBUG_DRAW_SIMPLEX
                    DebugDrawSimplex(simplex, Color.Blue, 0.0f);
                    #endif
                    
                    return result;
                }
                */

                // TODO: COMPARE TO VERTEX VALUES
                // REALLY LOOKING FOR CLOSEST *FEATURE*

                // support point to (possibly) add to the simplex
                //Vector2 pt = SupportPt(ref polyA, ref polyB, normal);
                Vector2 ptA, ptB;
                Vector2 pt = SupportPt(ref polyA, out ptA, ref polyB, out ptB, normal); 

                float d = Vector2.Dot(pt, normal);
                // if less than our tolerance
                // will return this information
                if (d - distance < EPA_TOLERANCE)
                {
                    result.Normal = normal;
                    result.Depth = distance;

                    FindClosestPointsSpecial2(simplex, pointsOnA, pointsOnB, out cpA, out cpB);
                    result.ContactPointA = cpA;
                    result.ContactPointB = cpB;

                    //result.EdgeIndex = index;
                    
                    #if GXT_DEBUG_DRAW_SIMPLEX
                    DebugDrawSimplex(simplex, Color.Green, 0.0f);
                    #endif

                    #if (GXT_DEBUG_DRAW_CONTACTS)
                    gxtDebugDrawer.Singleton.AddPt(cpA * gxtPhysicsWorld.PHYSICS_SCALE, Color.Red, 0.0f);
                    gxtDebugDrawer.Singleton.AddPt(cpB * gxtPhysicsWorld.PHYSICS_SCALE, Color.Red, 0.0f);
                    #endif
                    
                    return result;
                }
                // otherwise add to the simplex
                else
                {
                    simplex.Insert(index, pt);
                    // could remove
                    pointsOnA.Insert(index, ptA);
                    pointsOnB.Insert(index, ptB);
                    iterations++;
                }
            }

            return result;
        }
示例#9
0
        /// <summary>
        /// Returns extensive collision information about the given polygons
        /// Will determine if intersecting by running the GJK algorithm
        /// It saves the terminating simplex and further uses it for the 
        /// EPA algorithm.  Returns the intersection depth and collision normal as 
        /// part of the gxtCollisionResult return struct.  The normal and depth will 
        /// not be calculated, and thus such information is not realiable, if the intersection 
        /// is false
        /// </summary>
        /// <param name="polyA">Polygon A</param>
        /// <param name="centroidA">Centroid of polygon A</param>
        /// <param name="polyB">Polygon B</param>
        /// <param name="centroidB">Centroid of polygon B</param>
        /// <returns>Collision Result</returns>
        public static gxtCollisionResult CollideOld(gxtPolygon polyA, Vector2 centroidA, gxtPolygon polyB, Vector2 centroidB)
        {
            // optimal search direction
            Vector2 direction = centroidB - centroidA;
            // simplex vector2 collection
            List<Vector2> simplex;
            // the result structure for the collision
            gxtCollisionResult result = new gxtCollisionResult();
            
            // finishes with terminating simplex from gjk
            // boolean return for intersection
            if (!BuildSimplex(ref polyA, ref polyB, direction, out simplex))
            {
                result.Intersection = false;
                return result;
            }
            else
            {
                result.Intersection = true;
            }

            // iterations
            int iterations = 0;

            // holder edge information
            Vector2 normal;
            float distance;
            int index;
            
            // calculate the ordering (CW/CCW)
            // of the simplex.  only calc once
            // reusable in loop
            int winding = GetWinding(simplex);

            // epa loop
            while (iterations < MAX_ITERATIONS)
            {
                // find closest edge to origin info
                //FindClosestEdge(simplex, out index, out distance, out normal);
                if (FindClosestFeature(simplex, winding, out index, out distance, out normal))
                {
                    //gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "vertex collision");
                    result.Normal = normal;
                    result.Depth = distance;
                    //result.EdgeIndex = index;
                    //DebugDrawSimplex(simplex, Color.Blue, 0.0f);
                    return result;
                }

                // TODO: COMPARE TO VERTEX VALUES
                // REALLY LOOKING FOR CLOSEST *FEATURE*

                
                // support point to (possibly) add to the simplex
                Vector2 pt = SupportPt(ref polyA, ref polyB, normal);

                float d = Vector2.Dot(pt, normal);
                // if less than our tolerance
                // will return this information
                if (d - distance < EPA_TOLERANCE)
                {
                    result.Normal = normal;
                    result.Depth = distance;
                    //result.EdgeIndex = index;
                    // TEMPORARY
                    //DebugDrawSimplex(simplex, Color.Green, 0.0f);
                    //gxtDebugDrawer.Singleton.AddLine(Vector2.Zero, result.Normal * 30, Color.Gray, 0.0f);
                    return result;
                }
                // otherwise add to the simplex
                else
                {
                    simplex.Insert(index, pt);
                    iterations++;
                }
            }

            return result;
        }