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 #2
0
        public void Draw3D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            if (_document.TextureCollection.LightmapTextureOutdated)
            {
                _document.TextureCollection.UpdateLightmapTexture();
                List <Face> faces = new List <Face>();
                foreach (Solid solid in _document.Map.WorldSpawn.Find(x => x is Solid).OfType <Solid>())
                {
                    foreach (Face tface in solid.Faces)
                    {
                        faces.Add(tface);
                    }
                }
                UpdatePartial(faces);
            }

            var type = ((Viewport3D)context).Type;
            var opts = new Viewport3DRenderOptions
            {
                Viewport        = viewport,
                Camera          = camera,
                ModelView       = modelView,
                ShowGrid        = Document.Map.Show3DGrid,
                GridSpacing     = Document.Map.GridSpacing,
                Shaded          = type == Viewport3D.ViewType.Shaded || type == Viewport3D.ViewType.Textured || type == Viewport3D.ViewType.Lightmapped,
                Textured        = type == Viewport3D.ViewType.Textured || type == Viewport3D.ViewType.Lightmapped,
                Wireframe       = type == Viewport3D.ViewType.Wireframe,
                LightmapEnabled = type == Viewport3D.ViewType.Lightmapped
            };

            var cam      = ((Viewport3D)context).Camera;
            var location = new Coordinate((decimal)cam.Location.X, (decimal)cam.Location.Y, (decimal)cam.Location.Z);
            var lookAt   = new Coordinate((decimal)cam.LookAt.X, (decimal)cam.LookAt.Y, (decimal)cam.LookAt.Z);

            if (!opts.Wireframe)
            {
                _mapObject3DShader.Bind(opts);
                _mapObject3DShader.SelectionTransform        = _selectionTransform;
                _mapObject3DShader.SelectionColourMultiplier = Document.Map.HideFaceMask &&
                                                               Document.Selection.InFaceSelection
                                                                   ? new Vector4(1, 1, 1, 1)
                                                                   : new Vector4(1, 0.5f, 0.5f, 1);

                // Render textured polygons
                _array.RenderTextured(context.Context, _document.TextureCollection.LightmapTexture);

                // Render textured models
                if (!CBRE.Settings.View.DisableModelRendering)
                {
                    foreach (var tuple in _models)
                    {
                        var arr    = _modelArrays[tuple.Item2];
                        var origin = tuple.Item1.Origin;
                        if (tuple.Item1.HideDistance() <= (location - origin).VectorMagnitude())
                        {
                            continue;
                        }

                        var scale = tuple.Item1.EntityData.GetPropertyCoordinate("scale", Coordinate.One);
                        scale = new Coordinate(scale.X, scale.Z, scale.Y);
                        var    angles = tuple.Item1.EntityData.GetPropertyCoordinate("angles", Coordinate.Zero);
                        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));
                        if (tuple.Item1.IsSelected)
                        {
                            origin *= _selectionTransformMat;
                            // TODO: rotation/angles
                        }
                        var tform = (yaw * roll * pitch * Matrix.Scale(scale)).Translate(origin);
                        _mapObject3DShader.Transformation = tform.ToGLSLMatrix4();
                        arr.RenderTextured(context.Context);
                    }
                    _mapObject3DShader.Transformation = Matrix4.Identity;
                }

                // Render untextured polygons
                _mapObject3DShader.IsTextured = false;
                _array.RenderUntextured(context.Context, location);

                // todo Render sprites

                _mapObject3DShader.Unbind();
            }

            // Render wireframe
            _mapObject2DShader.Bind(opts);
            _mapObject2DShader.SelectedColour = new Vector4(1, 1, 0, 1);

            if (opts.Wireframe)
            {
                _mapObject2DShader.SelectedOnly       = false;
                _mapObject2DShader.SelectionTransform = _selectionTransform;
                _array.RenderWireframe(context.Context);
                _decalArray.RenderWireframe(context.Context);
            }

            if (!Document.Selection.InFaceSelection || !Document.Map.HideFaceMask)
            {
                _mapObject2DShader.SelectedOnly       = true;
                _mapObject2DShader.SelectionTransform = Matrix4.Identity;
                _array.RenderWireframe(context.Context);
                _decalArray.RenderWireframe(context.Context);
            }

            _mapObject2DShader.Unbind();

            if (!opts.Wireframe)
            {
                // Render transparent
                _mapObject3DShader.Bind(opts);
                _decalArray.RenderTransparent(context.Context, location);
                _array.RenderTransparent(context.Context, x => _mapObject3DShader.IsTextured = x && opts.Textured, location, lookAt);
                _mapObject3DShader.Unbind();
            }
        }
Beispiel #3
0
 public decimal Dot(Quaternion c)
 {
     return(Vector.Dot(c.Vector) + Scalar * c.Scalar);
 }