예제 #1
0
        public void CreateDepths(Camera inputCamera)
        {
            if (inputCamera == null)
            {
                return;
            }

            BoundingFrustum frust   = inputCamera.GetFrustum();
            BoundingBox     box     = MathFunctions.GetBoundingBox(frust.GetCorners());
            Vector3         forward = frust.Near.Normal;

            Vector3 z = Vector3.Zero;

            foreach (InstanceData instance in Data)
            {
                z = instance.Transform.Translation - inputCamera.Position;
                instance.Depth = z.LengthSquared();

                if (instance.Depth < CullDistance)
                {
                    // Half plane test. Faster. Much less accurate.
                    //if (Vector3.Dot(z, forward) > 0)
                    if (box.Contains(instance.Transform.Translation) != ContainmentType.Contains)
                    {
                        instance.Depth *= 100;
                    }
                }
                else
                {
                    instance.Depth *= 100;
                }
            }
        }
예제 #2
0
        public PolygonDrawCommand(Camera camera, IEnumerable <Vector3> points, bool isClosed, Color lineColor, int lineWidth, Viewport viewport)
        {
            Points = new List <Vector2>();

            BoundingFrustum cameraFrustrum = camera.GetFrustum();

            foreach (Vector3 point in points)
            {
                if (cameraFrustrum.Contains(point) == ContainmentType.Contains)
                {
                    Vector3 screenVec = viewport.Project(point, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);
                    Points.Add(new Vector2(screenVec.X, screenVec.Y));
                }
            }

            IsClosed  = isClosed;
            LineColor = lineColor;
            LineWidth = lineWidth;
        }