Exemple #1
0
        public void RenderIcons(PerspectiveCamera viewPoint, GBuffer gBuffer)
        {
            this.Effect.World      = Matrix.Identity;
            this.Effect.View       = Matrix.Identity;
            this.Effect.Projection = Matrix.Identity;
            this.Effect.DepthMap   = gBuffer.DepthTarget;

            this.Device.PostProcessState();

            foreach ((var entity, var component, var info, var property, var attribute) in this.EnumerateAttributes <IconAttribute>())
            {
                var position = (Vector3)property.GetGetMethod().Invoke(component, null);

                if (viewPoint.Frustum.Contains(position) != ContainmentType.Disjoint)
                {
                    var screenPosition = ProjectionMath.WorldToView(position, viewPoint.ViewProjection);

                    this.Effect.World                 = Matrix.CreateScale(new Vector3(Scale / viewPoint.AspectRatio, Scale, Scale)) * Matrix.CreateTranslation(new Vector3(screenPosition, 0));
                    this.Effect.Texture               = this.Library.GetIcon(attribute.Type);
                    this.Effect.WorldPosition         = position;
                    this.Effect.CameraPosition        = viewPoint.Position;
                    this.Effect.InverseViewProjection = viewPoint.InverseViewProjection;
                    this.Effect.VisibleTint           = info.VisibileIconTint;
                    this.Effect.ClippedTint           = info.ClippedIconTint;

                    this.Effect.Apply(TextureEffectTechniques.TexturePointDepthTest);

                    this.Quad.Render();
                }
            }
        }
Exemple #2
0
        public void RenderIcons(PerspectiveCamera viewPoint, GBuffer gBuffer)
        {
            this.Effect.World      = Matrix.Identity;
            this.Effect.View       = Matrix.Identity;
            this.Effect.Projection = Matrix.Identity;
            this.Effect.DepthMap   = gBuffer.DepthTarget;

            this.Device.PostProcessState();

            for (var i = 0; i < this.Components.Count; i++)
            {
                var component = this.Components[i];
                var pose      = this.Poses.Get(component.Entity);
                var position  = pose.Position;

                if (viewPoint.Frustum.Contains(position) != ContainmentType.Disjoint)
                {
                    var screenPosition = ProjectionMath.WorldToView(position, viewPoint.ViewProjection);

                    this.Effect.World                 = Matrix.CreateScale(new Vector3(IconScale / viewPoint.AspectRatio, IconScale, IconScale)) * Matrix.CreateTranslation(new Vector3(screenPosition, 0));
                    this.Effect.Texture               = this.Library.GetIcon(component.Icon);
                    this.Effect.WorldPosition         = position;
                    this.Effect.CameraPosition        = viewPoint.Position;
                    this.Effect.InverseViewProjection = viewPoint.InverseViewProjection;
                    this.Effect.VisibleTint           = component.BoundaryVisibleTint;
                    this.Effect.ClippedTint           = component.BoundaryClippedTint;

                    this.Effect.Apply(TextureEffectTechniques.TexturePointDepthTest);

                    this.Quad.Render();
                }
            }
        }
        public static BoundingRectangle CreateFromProjectedBoundingBox(BoundingBox box, IViewPoint viewPoint)
        {
            var minX = float.MaxValue;
            var maxX = float.MinValue;

            var minY = float.MaxValue;
            var maxY = float.MinValue;

            var corners = box.GetCorners();

            for (var i = 0; i < corners.Length; i++)
            {
                var corner          = corners[i];
                var projectedCorner = ProjectionMath.WorldToView(corner, viewPoint.View * viewPoint.Projection);

                minX = Math.Min(minX, projectedCorner.X);
                maxX = Math.Max(maxX, projectedCorner.X);

                minY = Math.Min(minY, projectedCorner.Y);
                maxY = Math.Max(maxY, projectedCorner.Y);
            }

            return(new BoundingRectangle(minX, maxX, minY, maxY));
        }