コード例 #1
0
        public static SharpDX.RectangleF Project(this SharpDX.BoundingBox bounds, Helix.RenderContext context)
        {
            var corners = bounds.GetCorners();

            for (int i = 0; i < corners.Length; i++)
            {
                corners[i] = SharpDX.Vector3.Project(corners[i], 0, 0, context.ActualWidth, context.ActualHeight, 0, 1, context.GlobalTransform.ViewProjection);
            }

            return(new SharpDX.RectangleF
            {
                Left = corners.Min(v => v.X),
                Top = corners.Min(v => v.Y),
                Right = corners.Max(v => v.X),
                Bottom = corners.Max(v => v.Y),
            });
        }
コード例 #2
0
        public static GTABoundingBox2 ComputeBoundingBox(Entity entity)
        {
            var m = entity.Model;

            (Vector3 gmin, Vector3 gmax) = m.Dimensions;

            var bbox = new SharpDX.BoundingBox(new SharpDX.Vector3(gmin.X, gmin.Y, gmin.Z), new SharpDX.Vector3(gmax.X, gmax.Y, gmax.Z));

            var res = new GTABoundingBox2
            {
                Min = new Vector2(float.PositiveInfinity, float.PositiveInfinity),
                Max = new Vector2(float.NegativeInfinity, float.NegativeInfinity)
            };

            foreach (var corner in bbox.GetCorners())
            {
                var cornerVector = new Vector3(corner.X, corner.Y, corner.Z);

                cornerVector = entity.GetOffsetPosition(cornerVector);
                Vector2 position = HashFunctions.Convert3dTo2d(cornerVector);

                if (position.X == .1f || position.Y == .1f || position.X == .9f || position.Y == .9f)
                {
                    return(new GTABoundingBox2
                    {
                        Min = new Vector2(float.PositiveInfinity, float.PositiveInfinity),
                        Max = new Vector2(float.NegativeInfinity, float.NegativeInfinity),
                        Quality = DataQuality.Low
                    });
                }

                res = new GTABoundingBox2
                {
                    Min     = new Vector2(Math.Min(res.Min.X, position.X), Math.Min(res.Min.Y, position.Y)),
                    Max     = new Vector2(Math.Max(res.Max.X, position.X), Math.Max(res.Max.Y, position.Y)),
                    Quality = DataQuality.High
                };
            }

            if (res.Max.X == res.Min.X || res.Max.Y == res.Min.Y)
            {
                res.Quality = DataQuality.Low;
            }

            return(res);
        }