Ejemplo n.º 1
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;
        }