Beispiel #1
0
        public Sound(String url, bool autoPlay = true, bool isLooped = true, bool is3D = false)
            : base()
        {
            _url = url;
            _autoPlay = autoPlay;
            _isLooped = isLooped;
            _is3D = is3D;

            if (Globals.EditorMode) AddNode(_lineDraw = new PrimitiveRenderer());
        }
        public static RayCastResult ClosestRayCast(Vector2 pointA, Vector2 pointB, Func<Fixture, Boolean> filter = null, PrimitiveRenderer lineDraw = null)
        {
            float minFrac = float.MaxValue;

            Fixture collisionFixture = null;
            Vector2 collisionPoint = pointB;
            bool hasCollision = false;
            Vector2 collisionNormal = Vector2.Zero;

            PhysicsComponent.World.RayCast((fixture, point, normal, fraction) =>
            {
                if (filter == null || filter(fixture))
                {
                    if (fraction < minFrac)
                    {
                        minFrac = fraction;
                        hasCollision = true;
                        collisionPoint = ConvertUnits.ToDisplayUnits(point);
                        collisionNormal = normal;
                        collisionFixture = fixture;
                    }
                }

                return 1;
            }, ConvertUnits.ToSimUnits(pointA), ConvertUnits.ToSimUnits(pointB));

            if (lineDraw != null)
            {
                lineDraw.DrawLine(pointA, pointB, Color.White);
                if (hasCollision) lineDraw.DrawLine(pointA, collisionPoint, Color.Red);

                if (hasCollision) lineDraw.DrawLine(collisionPoint, collisionPoint + (collisionNormal * 30), Color.Blue);
            }

            return new RayCastResult() { Collision = hasCollision, CollisionPoint = collisionPoint, Normal = collisionNormal, Fixture = collisionFixture };
        }