示例#1
0
        public void Render2D(Viewport2D viewport, MapObject o)
        {
            if (viewport.Zoom < 0.5m)
            {
                return;
            }

            var entityData = o.GetEntityData();

            if (entityData == null)
            {
                return;
            }

            var angles = entityData.GetPropertyCoordinate("angles");

            if (angles == null)
            {
                return;
            }

            //angles = new Coordinate(DMath.DegreesToRadians(angles.Z), DMath.DegreesToRadians(angles.X), DMath.DegreesToRadians(angles.Y));

            Matrix pitch = Matrix.Rotation(DataStructures.Geometric.Quaternion.EulerAngles(DMath.DegreesToRadians(angles.X), 0, 0));
            Matrix yaw   = Matrix.Rotation(DataStructures.Geometric.Quaternion.EulerAngles(0, 0, -DMath.DegreesToRadians(angles.Y)));
            Matrix roll  = Matrix.Rotation(DataStructures.Geometric.Quaternion.EulerAngles(0, DMath.DegreesToRadians(angles.Z), 0));

            var m = new UnitMatrixMult(yaw * roll * pitch);

            var min = Math.Min(o.BoundingBox.Width, Math.Min(o.BoundingBox.Height, o.BoundingBox.Length));
            var p1  = viewport.Flatten(o.BoundingBox.Center);
            var p2  = p1 + viewport.Flatten(m.Transform(Coordinate.UnitY)) * min * 0.4m;

            var multiplier = 4 / viewport.Zoom;
            var dir        = (p2 - p1).Normalise();
            var cp         = new Coordinate(-dir.Y, dir.X, 0).Normalise();

            GL.Color4(Color.FromArgb(255, o.Colour));

            GL.Begin(PrimitiveType.Lines);
            Coord(p1);
            Coord(p2);
            GL.End();

            GL.Begin(PrimitiveType.Triangles);
            Coord(p2 - (dir * 2 - cp) * multiplier);
            Coord(p2 - (dir * 2 + cp) * multiplier);
            Coord(p2);
            GL.End();
        }
示例#2
0
        public void Render2D(Viewport2D viewport, MapObject o)
        {
            if (viewport.Zoom < 0.5m)
            {
                return;
            }

            var entityData = o.GetEntityData();

            if (entityData == null)
            {
                return;
            }

            var angles = entityData.GetPropertyCoordinate("angles");

            if (angles == null)
            {
                return;
            }

            angles = new Coordinate(DMath.DegreesToRadians(angles.Z), DMath.DegreesToRadians(angles.X), DMath.DegreesToRadians(angles.Y));
            var m = new UnitMatrixMult(Matrix4.CreateRotationX((float)angles.X) * Matrix4.CreateRotationY((float)angles.Y) * Matrix4.CreateRotationZ((float)angles.Z));

            var min = Math.Min(o.BoundingBox.Width, Math.Min(o.BoundingBox.Height, o.BoundingBox.Length));
            var p1  = viewport.Flatten(o.BoundingBox.Center);
            //Extend direction
            //var p2 = p1 + viewport.Flatten(m.Transform(Coordinate.UnitX)) * min * 0.4m;
            var p2 = p1 + viewport.Flatten(m.Transform(Coordinate.UnitX)) * min * 7.5m;

            var multiplier = 4 / viewport.Zoom;
            var dir        = (p2 - p1).Normalise();
            var cp         = new Coordinate(-dir.Y, dir.X, 0).Normalise();

            GL.Color4(Color.FromArgb(255, o.Colour));

            GL.Begin(PrimitiveType.Lines);
            Coord(p1);
            Coord(p2);
            GL.End();

            GL.Begin(PrimitiveType.Triangles);
            Coord(p2 - (dir * 2 - cp) * multiplier);
            Coord(p2 - (dir * 2 + cp) * multiplier);
            Coord(p2);
            GL.End();
        }
示例#3
0
        public static void FindLights(Map map, out List <Light> lightEntities)
        {
            lightEntities = new List <Light>();
            lightEntities.AddRange(map.WorldSpawn.Find(q => q.ClassName == "light").OfType <Entity>()
                                   .Select(x =>
            {
                float range = 100.0f;
                float.TryParse(x.EntityData.GetPropertyValue("range"), NumberStyles.Float, CultureInfo.InvariantCulture, out range);
                float intensity = 1.0f;
                float.TryParse(x.EntityData.GetPropertyValue("intensity"), NumberStyles.Float, CultureInfo.InvariantCulture, out intensity);
                bool hasSprite = true;
                bool.TryParse(x.EntityData.GetPropertyValue("hassprite") ?? "true", out hasSprite);

                return(new Light()
                {
                    Origin = new CoordinateF(x.Origin),
                    Range = range,
                    Color = new CoordinateF(x.EntityData.GetPropertyCoordinate("color")),
                    Intensity = intensity,
                    HasSprite = hasSprite,
                    Direction = null,
                    innerCos = null,
                    outerCos = null
                });
            }));
            lightEntities.AddRange(map.WorldSpawn.Find(q => q.ClassName == "spotlight").OfType <Entity>()
                                   .Select(x =>
            {
                float range = 100.0f;
                float.TryParse(x.EntityData.GetPropertyValue("range"), NumberStyles.Float, CultureInfo.InvariantCulture, out range);
                float intensity = 1.0f;
                float.TryParse(x.EntityData.GetPropertyValue("intensity"), NumberStyles.Float, CultureInfo.InvariantCulture, out intensity);
                bool hasSprite = true;
                bool.TryParse(x.EntityData.GetPropertyValue("hassprite") ?? "true", out hasSprite);
                float innerCos = 0.5f;
                float.TryParse(x.EntityData.GetPropertyValue("innerconeangle"), NumberStyles.Float, CultureInfo.InvariantCulture, out innerCos);
                innerCos       = (float)Math.Cos(innerCos * (float)Math.PI / 180.0f);
                float outerCos = 0.75f;
                float.TryParse(x.EntityData.GetPropertyValue("outerconeangle"), NumberStyles.Float, CultureInfo.InvariantCulture, out outerCos);
                outerCos = (float)Math.Cos(outerCos * (float)Math.PI / 180.0f);

                Light light = new Light()
                {
                    Origin    = new CoordinateF(x.Origin),
                    Range     = range,
                    Color     = new CoordinateF(x.EntityData.GetPropertyCoordinate("color")),
                    Intensity = intensity,
                    HasSprite = hasSprite,
                    Direction = null,
                    innerCos  = innerCos,
                    outerCos  = outerCos
                };

                Coordinate angles = x.EntityData.GetPropertyCoordinate("angles");

                Matrix pitch = Matrix.Rotation(Quaternion.EulerAngles(DMath.DegreesToRadians(angles.X), 0, 0));
                Matrix yaw   = Matrix.Rotation(Quaternion.EulerAngles(0, 0, -DMath.DegreesToRadians(angles.Y)));
                Matrix roll  = Matrix.Rotation(Quaternion.EulerAngles(0, DMath.DegreesToRadians(angles.Z), 0));

                var m = new UnitMatrixMult(yaw * roll * pitch);

                light.Direction = new CoordinateF(m.Transform(Coordinate.UnitY));
                //TODO: make sure this matches 3dws

                return(light);
            }));
        }
示例#4
0
文件: Light.cs 项目: juanjp600/cbre
        public static void FindLights(Map map, out List <Light> lightEntities)
        {
            Predicate <string> parseBooleanProperty = (prop) => {
                return(prop.Equals("yes", StringComparison.OrdinalIgnoreCase) || prop.Equals("true", StringComparison.OrdinalIgnoreCase));
            };

            lightEntities = new List <Light>();
            lightEntities.AddRange(map.WorldSpawn.Find(q => q.ClassName == "light").OfType <Entity>()
                                   .Select(x => {
                float range;
                if (!float.TryParse(x.EntityData.GetPropertyValue("range"), out range))
                {
                    range = 100.0f;
                }
                float intensity;
                if (!float.TryParse(x.EntityData.GetPropertyValue("intensity"), out intensity))
                {
                    intensity = 1.0f;
                }
                bool hasSprite = parseBooleanProperty(x.EntityData.GetPropertyValue("hassprite") ?? "true");

                // TODO: RGB\A color
                Color c = x.EntityData.GetPropertyColor("color", System.Drawing.Color.Black);

                return(new Light()
                {
                    Origin = new CoordinateF(x.Origin),
                    Range = range,
                    Color = new CoordinateF(c.R, c.G, c.B),
                    Intensity = intensity,
                    HasSprite = hasSprite,
                    Direction = null,
                    innerCos = null,
                    outerCos = null
                });
            }));
            lightEntities.AddRange(map.WorldSpawn.Find(q => q.ClassName == "spotlight").OfType <Entity>()
                                   .Select(x => {
                float range;
                if (!float.TryParse(x.EntityData.GetPropertyValue("range"), out range))
                {
                    range = 100.0f;
                }
                float intensity;
                if (!float.TryParse(x.EntityData.GetPropertyValue("intensity"), out intensity))
                {
                    intensity = 1.0f;
                }
                bool hasSprite = parseBooleanProperty(x.EntityData.GetPropertyValue("hassprite") ?? "true");
                float innerCos = 0.5f;
                if (float.TryParse(x.EntityData.GetPropertyValue("innerconeangle"), out innerCos))
                {
                    innerCos = (float)Math.Cos(innerCos * (float)Math.PI / 180.0f);
                }
                float outerCos = 0.75f;
                if (float.TryParse(x.EntityData.GetPropertyValue("outerconeangle"), out outerCos))
                {
                    outerCos = (float)Math.Cos(outerCos * (float)Math.PI / 180.0f);
                }

                Color c = x.EntityData.GetPropertyColor("color", System.Drawing.Color.Black);

                Light light = new Light()
                {
                    Origin    = new CoordinateF(x.Origin),
                    Range     = range,
                    Color     = new CoordinateF(c.R, c.G, c.B),
                    Intensity = intensity,
                    HasSprite = hasSprite,
                    Direction = null,
                    innerCos  = innerCos,
                    outerCos  = outerCos
                };

                Coordinate angles = x.EntityData.GetPropertyCoordinate("angles");

                Matrix pitch = Matrix.Rotation(Quaternion.EulerAngles(DMath.DegreesToRadians(angles.X), 0, 0));
                Matrix yaw   = Matrix.Rotation(Quaternion.EulerAngles(0, 0, -DMath.DegreesToRadians(angles.Y)));
                Matrix roll  = Matrix.Rotation(Quaternion.EulerAngles(0, DMath.DegreesToRadians(angles.Z), 0));

                var m = new UnitMatrixMult(yaw * pitch * roll);

                light.Direction = new CoordinateF(m.Transform(Coordinate.UnitY));
                //TODO: make sure this matches 3dws

                return(light);
            }));
        }