Exemple #1
0
        private void DrawChildren(IDeviceContextHolder contextHolder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            if (!IsEnabled || filter?.Invoke(this) == false)
            {
                return;
            }
            if (mode == SpecialRenderMode.Reflection && !IsReflectable)
            {
                return;
            }
            if (camera != null && BoundingBox != null && !camera.Visible(BoundingBox.Value))
            {
                return;
            }

            UpdateLookAt();

            var c = Count;

            for (var i = 0; i < c; i++)
            {
                var child = this[i];
                if (child.IsEnabled)
                {
                    child.Draw(contextHolder, camera, mode, filter);
                }
            }

            if (HighlightBoundingBoxes && mode == SpecialRenderMode.SimpleTransparent)
            {
                if (_box == null)
                {
                    var box = GeometryGenerator.CreateLinesBox(new Vector3(1f));
                    _box = new DebugLinesObject(Matrix.Identity,
                                                box.Vertices.Select(x => new InputLayouts.VerticePC(x.Position, new Color4(1f, 1f, 0.5f, 0f))).ToArray(),
                                                box.Indices.ToArray());
                }

                for (var i = 0; i < c; i++)
                {
                    var child = this[i];
                    if (child.IsEnabled && child.BoundingBox.HasValue)
                    {
                        var bb = child.BoundingBox.Value;
                        _box.ParentMatrix = Matrix.Scaling(bb.GetSize()) * Matrix.Translation(bb.GetCenter());
                        _box.Draw(contextHolder, camera, SpecialRenderMode.Simple);
                    }
                }
            }
        }
Exemple #2
0
        public virtual void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            DrawChildren(holder, camera, mode, filter);
            if (HighlightDummy && mode == SpecialRenderMode.SimpleTransparent)
            {
                if (_lines == null)
                {
                    _lines = new DebugLinesObject(Matrix.Identity, new[] {
                        new InputLayouts.VerticePC(new Vector3(0f, 0f, 0f), new Color4(0, 1, 0)),
                        new InputLayouts.VerticePC(new Vector3(0f, 0.02f, 0f), new Color4(0, 1, 0)),
                        new InputLayouts.VerticePC(new Vector3(0f, 0f, 0f), new Color4(1, 0, 0)),
                        new InputLayouts.VerticePC(new Vector3(0.02f, 0f, 0f), new Color4(1, 0, 0)),
                        new InputLayouts.VerticePC(new Vector3(0f, 0f, 0f), new Color4(0, 0, 1)),
                        new InputLayouts.VerticePC(new Vector3(0f, 0f, 0.02f), new Color4(0, 0, 1)),
                    });
                }

                _lines.ParentMatrix = Matrix;
                _lines.Draw(holder, camera, SpecialRenderMode.Simple);
            }
        }
Exemple #3
0
        public void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            const float arrowSize  = 0.08f;
            const float circleSize = 0.06f;
            const float boxSize    = 0.14f;

            if (_arrowX == null)
            {
                _arrowX = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), arrowSize);
                _arrowY = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), arrowSize);
                _arrowZ = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), arrowSize);

                if (_rotationAxis.HasFlag(MoveableRotationAxis.X))
                {
                    _circleX = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), radius: circleSize);
                }

                if (_rotationAxis.HasFlag(MoveableRotationAxis.Y))
                {
                    _circleY = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), radius: circleSize);
                }

                if (_rotationAxis.HasFlag(MoveableRotationAxis.Z))
                {
                    _circleZ = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), radius: circleSize);
                }

                if (_allowScaling)
                {
                    _scale = DebugLinesObject.GetLinesBox(Matrix.Identity, new Vector3(boxSize), new Color4(0f, 1f, 1f, 0f));
                }
            }

            var matrix = ParentMatrix.GetTranslationVector().ToFixedSizeMatrix(camera);

            if (_arrowX.ParentMatrix != matrix)
            {
                _arrowX.ParentMatrix = matrix;
                _arrowY.ParentMatrix = matrix;
                _arrowZ.ParentMatrix = matrix;

                _arrowX.UpdateBoundingBox();
                _arrowY.UpdateBoundingBox();
                _arrowZ.UpdateBoundingBox();

                if (_circleX != null)
                {
                    _circleX.ParentMatrix = matrix;
                    _circleX.UpdateBoundingBox();
                }

                if (_circleY != null)
                {
                    _circleY.ParentMatrix = matrix;
                    _circleY.UpdateBoundingBox();
                }

                if (_circleZ != null)
                {
                    _circleZ.ParentMatrix = matrix;
                    _circleZ.UpdateBoundingBox();
                }

                if (_scale != null)
                {
                    _scale.ParentMatrix = matrix;
                    _scale.UpdateBoundingBox();
                }
            }

            if (_keepHighlight)
            {
                _arrowX.Draw(holder, camera, _arrowHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _arrowY.Draw(holder, camera, _arrowHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _arrowZ.Draw(holder, camera, _arrowHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleX?.Draw(holder, camera, _circleHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleY?.Draw(holder, camera, _circleHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleZ?.Draw(holder, camera, _circleHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _scale?.Draw(holder, camera, _scaleHighlighted ? SpecialRenderMode.Outline : SpecialRenderMode.Simple);
            }
            else
            {
                var mousePosition = holder.TryToGet <IMousePositionProvider>()?.GetRelative();
                var rayN          = mousePosition == null ? null : (camera as CameraBase)?.GetPickingRay(mousePosition.Value, new Vector2(1f, 1f));
                if (!rayN.HasValue)
                {
                    return;
                }

                var ray = rayN.Value;
                _arrowHighlighted = new Vector3(
                    _arrowX.DrawHighlighted(ray, holder, camera) ? 1f : 0f,
                    _arrowY.DrawHighlighted(ray, holder, camera) ? 1f : 0f,
                    _arrowZ.DrawHighlighted(ray, holder, camera) ? 1f : 0f);

                if (_arrowHighlighted == Vector3.Zero)
                {
                    _circleHighlighted = new Vector3(
                        _circleX?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f,
                        _circleY?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f,
                        _circleZ?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f);
                }
                else
                {
                    _circleHighlighted = Vector3.Zero;
                    _circleX?.Draw(holder, camera, SpecialRenderMode.Simple);
                    _circleY?.Draw(holder, camera, SpecialRenderMode.Simple);
                    _circleZ?.Draw(holder, camera, SpecialRenderMode.Simple);
                }

                if (_arrowHighlighted == Vector3.Zero && _circleHighlighted == Vector3.Zero)
                {
                    _scaleHighlighted = _scale?.DrawHighlighted(ray, holder, camera) ?? false;
                }
                else
                {
                    _scaleHighlighted = false;
                    _scale?.Draw(holder, camera, SpecialRenderMode.Simple);
                }
            }
        }