Beispiel #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();
        }
Beispiel #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();
        }
Beispiel #3
0
        private IEnumerable <MapObject> CreateCopy(IDGenerator gen, Coordinate origin, Coordinate rotation, List <string> names, TransformFlags transformFlags)
        {
            var box = new Box(_objectsToPaste.Select(x => x.BoundingBox));

            var mov       = Matrix.Translation(-box.Center);                                    // Move to zero
            var rot       = Matrix.Rotation(Quaternion.EulerAngles(rotation * DMath.PI / 180)); // Do rotation
            var fin       = Matrix.Translation(origin);                                         // Move to final origin
            var transform = new UnitMatrixMult(fin * rot * mov);

            foreach (var mo in _objectsToPaste)
            {
                // Copy, transform and fix entity names
                var copy = mo.Copy(gen);
                copy.Transform(transform, transformFlags);
                FixEntityNames(copy, names);
                yield return(copy);
            }
        }
        public void Transform()
        {
            if (_document.Selection.IsEmpty() || _document.Selection.InFaceSelection)
            {
                return;
            }
            var box = _document.Selection.GetSelectionBoundingBox();

            using (var td = new TransformDialog(box))
            {
                if (td.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var value = td.TransformValue;
                IUnitTransformation transform = null;
                switch (td.TransformType)
                {
                case TransformType.Rotate:
                    var mov = Matrix.Translation(-box.Center);                                 // Move to zero
                    var rot = Matrix.Rotation(Quaternion.EulerAngles(value * DMath.PI / 180)); // Do rotation
                    var fin = Matrix.Translation(box.Center);                                  // Move to final origin
                    transform = new UnitMatrixMult(fin * rot * mov);
                    break;

                case TransformType.Translate:
                    transform = new UnitTranslate(value);
                    break;

                case TransformType.Scale:
                    transform = new UnitScale(value, box.Center);
                    break;
                }

                if (transform == null)
                {
                    return;
                }

                var selected = _document.Selection.GetSelectedParents();
                _document.PerformAction("Transform selection", new Edit(selected, new TransformEditOperation(transform, _document.Map.GetTransformFlags())));
            }
        }
Beispiel #5
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);
            }));
        }
Beispiel #6
0
        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);
            }));
        }