示例#1
0
        private void DrawLight(ILight l)
        {
            if (l is PointLight)
            {
                PointLight pl = l as PointLight;
                Vector2 center = new Vector2(pl.Position.X, pl.Position.Z);
                double crossSize = 500.0 / areaSize;
                Vector2 pc = VectorToPixel(center);

                g.DrawLine(Pens.Black, pc.X - crossSize, pc.Y - crossSize, pc.X + crossSize, pc.Y + crossSize);
                g.DrawLine(Pens.Black, pc.X - crossSize, pc.Y + crossSize, pc.X + crossSize, pc.Y - crossSize);
                Rectangle rect = new Rectangle((int)(pc.X - crossSize * 0.6), (int)(pc.Y - crossSize * 0.6), (int)(crossSize * 1.2), (int)(crossSize * 1.2));
                g.FillEllipse(new SolidBrush(pl.Color.ToColor()), rect);
                g.DrawEllipse(Pens.Black, rect);
            }

            if (l is AreaLight)
            {
                AreaLight al = l as AreaLight;
                Vector2 center = new Vector2(al.Position.X, al.Position.Z);
                double crossSize = 500.0 / areaSize;
                Vector2 pc = VectorToPixel(center);

                g.DrawLine(Pens.Black, pc.X, pc.Y - crossSize, pc.X, pc.Y + crossSize);
                g.DrawLine(Pens.Black, pc.X - crossSize, pc.Y, pc.X + crossSize, pc.Y);
                Rectangle rect = new Rectangle((int)(pc.X - crossSize * 0.6), (int)(pc.Y - crossSize * 0.6), (int)(crossSize * 1.2), (int)(crossSize * 1.2));
                g.FillEllipse(new SolidBrush(al.Color.ToColor()), rect);
                g.DrawEllipse(Pens.Black, rect);
            }

            if (l is SpotLight)
            {
                SpotLight sl = l as SpotLight;
                Vector2 center = new Vector2(sl.Position.X, sl.Position.Z);
                double crossSize = 500.0 / areaSize;
                Vector2 pc = VectorToPixel(center);

                g.DrawLine(Pens.Black, pc.X - crossSize, pc.Y - crossSize, pc.X + crossSize, pc.Y + crossSize);
                g.DrawLine(Pens.Black, pc.X - crossSize, pc.Y + crossSize, pc.X + crossSize, pc.Y - crossSize);
                Rectangle rect = new Rectangle((int)(pc.X - crossSize * 0.6), (int)(pc.Y - crossSize * 0.6), (int)(crossSize * 1.2), (int)(crossSize * 1.2));
                g.FillEllipse(new SolidBrush(sl.Color.ToColor()), rect);
                g.DrawEllipse(Pens.Black, rect);
                Vector2 dir = new Vector2(sl.Direction.X, sl.Direction.Z);
                if (dir.Length == 0.0)
                    return;
                dir.Normalize();
                Vector2 orth = new Vector2(-dir.Y, dir.X) * Math.Tan(sl.Angle.ToRadians());

                Vector2 left = dir - orth;
                Vector2 right = dir + orth;

                DrawLine(Pens.Blue, center, center + left * 50.0);
                DrawLine(Pens.Blue, center, center + right * 50.0);
            }
        }
示例#2
0
        private bool IsLightVisible(Vector3 point, ILight light)
        {
            if (light is PointLight)
            {
                PointLight plight = light as PointLight;
                return !PointObstructed(point, plight.Position);
            }

            if (light is SpotLight)
            {
                SpotLight slight = light as SpotLight;
                if (!slight.PointLighted(point))
                    return false;

                return !PointObstructed(point, slight.Position);
            }

            return false;
        }