private void InitForTerrain(VoxelTerrain terrain)
        {
            if (terrain == null)
            {
                m_initTerrain = null; return;
            }
            if (terrain.readable == null)
            {
                return;
            }
            if (terrain.writeable == null)
            {
                return;
            }

            m_initTerrain = terrain;

            if (terrain == null)
            {
                return;
            }

            m_rectBrush        = new RectBrush(terrain.voxelSize, terrain.readable.min, terrain.readable.max, terrain.readable.Sample, terrain.SetValue);
            m_rectBrush.width  = 1.0f;
            m_rectBrush.height = 1.0f;

            m_circleBrush        = new CircleBrush(terrain.voxelSize, terrain.readable.min, terrain.readable.max, terrain.readable.Sample, terrain.SetValue);
            m_circleBrush.radius = 0.5f;
        }
Exemplo n.º 2
0
        public override void LoadContent()
        {
            _circleBrush = new CircleBrush(64, Color.White, Color.Black);
            _circleBrush.Load(ScreenManager.GraphicsDevice);

            _circleBody          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 64, 1);
            _circleBody.Position = new Vector2(725, 384);
            _circleGeom          = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _circleBody, 64, 20);

            _rectangleBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 128, 1);
            _rectangleBody.Position = new Vector2(256, 384);
            _rectangleGeom          = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _rectangleBody, 128, 128);

            _rectangleBrush = new RectangleBrush(128, 128, Color.Gold, Color.Black);
            _rectangleBrush.Load(ScreenManager.GraphicsDevice);

            _p1 = ScreenManager.ScreenCenter;
            _p2 = _circleGeom.Position;

            _lineBrush = new LineBrush(1, Color.Black);
            _lineBrush.Load(ScreenManager.GraphicsDevice);

            _marker = new CircleBrush(3, Color.Red, Color.Red);
            _marker.Load(ScreenManager.GraphicsDevice);

            base.LoadContent();
        }
Exemplo n.º 3
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _circleBrush = new CircleBrush(_radius, _color, _borderColor);
            _circleBrush.Load(graphicsDevice);

            _circleBody = new Body[_count];
            _circleGeom = new Geom[_count];

            _circleBody[0] = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _radius, .5f);
            _circleBody[0].Position = _startPosition;
            for (int i = 1; i < _count; i++)
            {
                _circleBody[i] = BodyFactory.Instance.CreateBody(physicsSimulator, _circleBody[0]);
                _circleBody[i].Position = Vector2.Lerp(_startPosition, _endPosition, i/(float) (_count - 1));
            }

            _circleGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _circleBody[0], _radius, 10);
            _circleGeom[0].RestitutionCoefficient = .7f;
            _circleGeom[0].FrictionCoefficient = .2f;
            _circleGeom[0].CollisionCategories = _collisionCategories;
            _circleGeom[0].CollidesWith = _collidesWith;
            for (int j = 1; j < _count; j++)
            {
                _circleGeom[j] = GeomFactory.Instance.CreateGeom(physicsSimulator, _circleBody[j], _circleGeom[0]);
            }
        }
Exemplo n.º 4
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _circleBrush = new CircleBrush(_radius, _color, _borderColor);
            _circleBrush.Load(graphicsDevice);

            _circleBody = new Body[_count];
            _circleGeom = new Geom[_count];

            _circleBody[0]          = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _radius, .5f);
            _circleBody[0].Position = _startPosition;
            for (int i = 1; i < _count; i++)
            {
                _circleBody[i]          = BodyFactory.Instance.CreateBody(physicsSimulator, _circleBody[0]);
                _circleBody[i].Position = Vector2.Lerp(_startPosition, _endPosition, i / (float)(_count - 1));
            }

            _circleGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _circleBody[0], _radius, 10);
            _circleGeom[0].RestitutionCoefficient = .7f;
            _circleGeom[0].FrictionCoefficient    = .2f;
            _circleGeom[0].CollisionCategories    = _collisionCategories;
            _circleGeom[0].CollidesWith           = _collidesWith;
            for (int j = 1; j < _count; j++)
            {
                _circleGeom[j] = GeomFactory.Instance.CreateGeom(physicsSimulator, _circleBody[j], _circleGeom[0]);
            }
        }
        private void LoadSpringContent(GraphicsDevice graphicsDevice)
        {
            _springLineBrush   = new LineBrush(_springLineThickness, _springLineColor);
            _springCircleBrush = new CircleBrush(2, _springLineColor, _springLineColor);

            _springLineBrush.Load(graphicsDevice);
            _springCircleBrush.Load(graphicsDevice);
        }
Exemplo n.º 6
0
 public CircleBrush AddCircleToCanvas(Body body, float radius)
 {
     CircleBrush circle = new CircleBrush();
     circle.Radius = radius;
     circle.Extender.Body = body;
     Children.Add(circle);
     drawingList.Add(circle);
     return circle;
 }
Exemplo n.º 7
0
        public CircleBrush AddCircleToCanvas(Body body, float radius)
        {
            CircleBrush circle = new CircleBrush();

            circle.Radius        = radius;
            circle.Extender.Body = body;
            _simulatorCanvas.Children.Add(circle);
            drawingList.Add(circle);
            return(circle);
        }
Exemplo n.º 8
0
        private void GenerateTunnels(Vector2 start, float maxLength = 2000.0f, float turnStrength = 0.2f)
        {
            //1234
            //12345
            //498764867
            //582764
            var         random = new FastRandom(498764867);
            const float step   = 2.0f;

            var terrainHeight = _terrain.TerrainSize.Y / 2.0f;
            var maxSize       = new Vector2(30.0f);

            var currentPosition  = start;
            var currentDirection = Vector2.UnitX;

            var length = 0.0f;

            while (length < maxLength)
            {
                var currentSize = maxSize + new Vector2(Math.Max(0.0f, length + 200.0f - maxLength)) * 1.0f;

                var brushSize = new Vector2(random.NextFloat() * currentSize.X, random.NextFloat() * currentSize.Y);
                var brush     = new CircleBrush(
                    (brushSize.X + brushSize.Y) / 4.0f,
                    currentPosition + new Vector2(random.NextRangedFloat(), random.NextRangedFloat()));

                _terrain.SetQuads(brush, false, true);

                // Add rotation.
                var rotationDir = random.NextRangedFloat();

                // Prevent going outside terrain or going back.
                if (currentPosition.Y > terrainHeight - 200.0f ||
                    (currentDirection.X < 0.0f && currentDirection.Y > 0.0f))
                {
                    rotationDir = (rotationDir - 1.0f) * 0.1f;
                }
                else if (currentPosition.Y < -(terrainHeight + 200.0f) ||
                         (currentDirection.X < 0.0f && currentDirection.Y < 0.0f))
                {
                    rotationDir = (rotationDir + 1.0f) * 0.1f;
                }

                // Apply rotation.
                var rotation = rotationDir * turnStrength;
                currentDirection = new Vector2(
                    currentDirection.X * MathCore.Cos(rotation) + -currentDirection.Y * MathCore.Sin(rotation),
                    currentDirection.Y * MathCore.Cos(rotation) + currentDirection.X * MathCore.Sin(rotation));

                currentPosition += currentDirection * step;
                length          += step;
            }

            _terrain.Refresh();
        }
Exemplo n.º 9
0
    /// <inheritdoc />
    public override void Draw()
    {
        var size        = Size;
        var enabled     = EnabledInHierarchy;
        var circleColor = _isPressed ? ColorPressed : Color;

        if (!enabled)
        {
            circleColor *= 0.5f;
        }
        var pressedScale = 0.3f;
        var normalSize   = 0.5f;
        var circleBounds = _isPressed ? new Rectangle(Vector2.Clamp(_inputLocation, size * (pressedScale / 2), size * (1 - pressedScale / 2)) - size * (pressedScale / 2), size * pressedScale) : new Rectangle(size * (0.5f - normalSize * 0.5f), size * normalSize);

        CircleBrush?.Draw(circleBounds, circleColor);
    }
    private void UseTool(MarchingTerrain terrain)
    {
        if (!IsReady())
        {
            return;
        }

        switch (m_terrainEditorUtility.currentProps.currentToolType)
        {
        case ToolType.CircleBrush: CircleBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break;

        case ToolType.SphereBrush: SphereBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break;

        case ToolType.Smooth: SmoothBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break;

        case ToolType.Noise: NoiseBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break;

        case ToolType.Paint: PaintBrush.Execute(terrain, m_terrainEditorUtility.currentProps, m_hotkeyUtility.IsInvertedMode()); break;
        }
    }
Exemplo n.º 11
0
        public override void LoadContent()
        {
            _circleBrush = new CircleBrush(64, Color.White, Color.Black);
            _circleBrush.Load(ScreenManager.GraphicsDevice);

            _circleBody = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 64, 1);
            _circleBody.Position = new Vector2(725, 384);
            _circleGeom = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _circleBody, 64, 20);

            _rectangleBody = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 128, 1);
            _rectangleBody.Position = new Vector2(256, 384);
            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _rectangleBody, 128, 128);

            _rectangleBrush = new RectangleBrush(128, 128, Color.Gold, Color.Black);
            _rectangleBrush.Load(ScreenManager.GraphicsDevice);

            base.LoadContent();
        }
Exemplo n.º 12
0
 private void LoadVerticeContent(GraphicsDevice graphicsDevice)
 {
     _verticeCircleBrush = new CircleBrush(_verticeRadius, _verticeColor, _verticeColor);
     _verticeCircleBrush.Load(graphicsDevice);
 }
Exemplo n.º 13
0
        private void LoadSpringContent(GraphicsDevice graphicsDevice)
        {
            _springLineBrush = new LineBrush(_springLineThickness, _springLineColor);
            _springCircleBrush = new CircleBrush(2, _springLineColor, _springLineColor);

            _springLineBrush.Load(graphicsDevice);
            _springCircleBrush.Load(graphicsDevice);
        }
Exemplo n.º 14
0
 private void LoadContactContent(GraphicsDevice graphicsDevice)
 {
     _contactCircleBrush = new CircleBrush(_contactRadius, _contactColor, _contactColor);
     _contactCircleBrush.Load(graphicsDevice);
 }
Exemplo n.º 15
0
 private void LoadVerticeContent(GraphicsDevice graphicsDevice)
 {
     _verticeCircleBrush = new CircleBrush(_verticeRadius, _verticeColor, _verticeColor);
     _verticeCircleBrush.Load(graphicsDevice);
 }
Exemplo n.º 16
0
 private void LoadContactContent(GraphicsDevice graphicsDevice)
 {
     _contactCircleBrush = new CircleBrush(_contactRadius, _contactColor, _contactColor);
     _contactCircleBrush.Load(graphicsDevice);
 }
Exemplo n.º 17
0
 private void LoadGridContent(GraphicsDevice graphicsDevice)
 {
     _gridCircleBrush = new CircleBrush(_gridRadius, _gridColor, _gridColor);
     _gridCircleBrush.Load(graphicsDevice);
 }
Exemplo n.º 18
0
 public CircleBrush AddCircleToCanvas(Color color, float radius)
 {
     CircleBrush circle = new CircleBrush();
     circle.Radius = radius;
     circle.Extender.Color = color;
     Children.Add(circle);
     return circle;
 }
Exemplo n.º 19
0
        public void Load(SimulatorView view, PhysicsSimulator physicsSimulator)
        {
            int radius;

            if (_attachPoint == 0 | _attachPoint == 2)
            {
                radius = _rectangleHeight;
            }
            else
            {
                radius = _rectangleWidth;
            }

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            _angleSpringleverBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                             _rectangleHeight, 1f);
            view.AddRectangleToCanvas(_angleSpringleverBody, Colors.White,
                                      new Vector2(_rectangleWidth, _rectangleHeight));

            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _angleSpringleverBody,
                                                                      _rectangleWidth, _rectangleHeight);
            _rectangleGeom.FrictionCoefficient = .5f;
            _rectangleGeom.CollisionGroup      = _collisionGroup;

            Vector2 offset = Vector2.Zero;

            switch (_attachPoint)
            {
            case 0:
            {
                offset = new Vector2(-_rectangleWidth / 2f, 0);       //offset to rectangle to left
                break;
            }

            case 1:
            {
                offset = new Vector2(0, -_rectangleHeight / 2f);       //offset to rectangle to top
                break;
            }

            case 2:
            {
                offset = new Vector2(_rectangleWidth / 2f, 0);       //offset to rectangle to right
                break;
            }

            case 3:
            {
                offset = new Vector2(0, _rectangleHeight / 2f);       //offset to rectangle to bottom
                break;
            }
            }

            _angleSpringleverBody.Position = _position - offset;
            CircleBrush circle = view.AddCircleToCanvas(null, Colors.White, 20);

            circle.Extender.Position = _position;
            _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20,
                                                                offset, 0);
            _circleGeom.FrictionCoefficient = .5f;
            _circleGeom.CollisionGroup      = _collisionGroup;

            JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody,
                                                           _position);
            SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody,
                                                          _springConstant, _dampningConstant);
        }