예제 #1
0
 /// <summary>
 /// Discard all buffer data.
 /// </summary>
 public void Dispose()
 {
     foreach (Batch batch in Batches)
     {
         batch.Dispose();
     }
     Batches.Clear();
     nodes.Clear();
 }
예제 #2
0
        //Draws the pendulum bobs.
        public override void Draw(State state)
        {
            //Sets width and height to canvas height and width propeties depending on
            //if the canvas is initialised.
            var width  = Canvas.ActualWidth > 0 ? Canvas.ActualWidth : Canvas.Width;
            var height = Canvas.ActualHeight > 0 ? Canvas.ActualHeight : Canvas.Height;

            //Calaculate bob position.
            BobPosition.X = Length * Math.Sin(state.Displacement);
            BobPosition.Y = Length * Math.Cos(state.Displacement);

            PivotPosition = new Vec2
            {
                X = width / 2,
                Y = height / 2
            };

            Batches.Add(DrawingMethods.FilledCircle(PivotPosition, 4, Brushes.Black));

            //Calculate bob position relative to the canvas coordinates.
            BobPosCanvas.X = PivotPosition.X + BobPosition.X * PixelsPerMeter;
            BobPosCanvas.Y = PivotPosition.Y + BobPosition.Y * PixelsPerMeter;


            //Create line objects for pendulum arm.
            var arm = new LightLine
            {
                X1 = PivotPosition.X,
                Y1 = PivotPosition.Y,
                X2 = BobPosCanvas.X - BobRadius * Math.Sin(state.Displacement),
                Y2 = BobPosCanvas.Y - BobRadius * Math.Cos(state.Displacement)
            };

            var armLineBatch = new LineBatch {
                LineThickness = 2
            };

            armLineBatch.Add(arm);
            Batches.Add(armLineBatch);

            //Draw origin circles depending on whether interaction is taking place.
            Batches.Add(IsInteracting
                ? DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Red)
                : DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Blue));

            //Render the batches.
            foreach (var batch in Batches)
            {
                batch.Render(Canvas);
                batch.Clear();
            }

            Batches.Clear();
        }
예제 #3
0
 /// <summary>
 /// Called when [get diagnostics batches completed].
 /// </summary>
 /// <param name="items">The items.</param>
 /// <remarks></remarks>
 public void OnGetDiagnosticsBatchesCompleted(DiagnosticsBatchViewItem[] items)
 {
     IsEmpty = true;
     IsBusy  = false;
     if (items == null)
     {
         return;
     }
     IsEmpty = (items.Count() == 0);
     Batches.Clear();
     foreach (var diagnosticsBatchViewItem in items)
     {
         Batches.Add(diagnosticsBatchViewItem);
     }
     RaisePropertyChanged(Property.Batches);
 }
예제 #4
0
        /// <summary>
        /// Prepare to accept data for processing.
        /// </summary>
        /// <param name="indexPatterns">
        /// The order in which indices are added to the index buffers. Must
        /// have element length equal to 4. Note that the number of index
        /// patterns passed will determine the number of index buffers created
        /// (one per pattern).
        /// </param>
        public void Init(int stride, params byte[][] indexPatterns)
        {
#if DEBUG
            foreach (var pattern in indexPatterns)
            {
                Debug.Assert(pattern.Length == 4);
                //ToDo (DZ): Consider creating a IndexPattern struct. This
                // may make the indexPatterns argument more readable and
                // since the index pattern should always be of length 4 a
                // dynamic size array is unnecessary.
            }
#endif
            Stride        = stride;
            IndexPatterns = indexPatterns;
            IndexBuffers  = new IndexBuffer[NumBuffers];

            _bufferScratch.Clear();
            nodes.Clear();
            Batches.Clear();
        }
예제 #5
0
        //Draws the pendulum bobs.
        public override void Draw(State state)
        {
            var springLength = (Length + state.Displacement) * PixelsPerMeter - ConnectorLength * 2;
            var coilSpan     = springLength / NumberOfCoils;
            var multiplier   = -1;


            //Sets width and height to canvas height and width propeties depending on
            //if the canvas is initialised.
            var width  = Canvas.ActualWidth > 0 ? Canvas.ActualWidth : Canvas.Width;
            var height = Canvas.ActualHeight > 0 ? Canvas.ActualHeight : Canvas.Height;

            BobPosition.Y = Length + state.Displacement;

            PivotPosition = new Vec2
            {
                X = width / 2,
                Y = 10
            };
            Batches.Add(DrawingMethods.FilledCircle(PivotPosition, 4, Brushes.Black));

            //Calaculate bob position.
            BobPosCanvas.X = PivotPosition.X;
            BobPosCanvas.Y = PivotPosition.Y + BobPosition.Y * PixelsPerMeter + BobRadius;

            #region DrawSpring

            var springlineBatch = new LineBatch();
            var springPivotLine = new LightLine()
            {
                X1 = PivotPosition.X,
                Y1 = PivotPosition.Y,
                X2 = PivotPosition.X,
                Y2 = PivotPosition.Y + ConnectorLength
            };
            springlineBatch.Add(springPivotLine);

            var theta = Math.Asin(coilSpan / 2 / CoilDiameter);
            var x     = (CoilDiameter * Math.Cos(theta) / 2);

            var startLine = new LightLine()
            {
                X1 = PivotPosition.X,
                Y1 = PivotPosition.Y + ConnectorLength,
                X2 = PivotPosition.X + x,
                Y2 = PivotPosition.Y + ConnectorLength + coilSpan / 2
            };
            springlineBatch.Add(startLine);
            var tempLine = startLine;


            for (int i = 0; i < (NumberOfCoils - 1) * 2; i++)
            {
                var coilLine = new LightLine()
                {
                    X1 = tempLine.X2,
                    Y1 = tempLine.Y2,
                    X2 = tempLine.X2 + 2 * x * multiplier,
                    Y2 = tempLine.Y2 + coilSpan / 2,
                };

                springlineBatch.Add(coilLine);
                tempLine    = coilLine;
                multiplier *= -1;
            }

            var endLine = new LightLine()
            {
                X1 = tempLine.X2,
                Y1 = tempLine.Y2,
                X2 = tempLine.X2 + x * multiplier,
                Y2 = tempLine.Y2 + coilSpan / 2
            };
            springlineBatch.Add(endLine);

            var springBobLine = new LightLine()
            {
                X1 = endLine.X2,
                Y1 = endLine.Y2,
                X2 = endLine.X2,
                Y2 = endLine.Y2 + ConnectorLength
            };
            springlineBatch.Add(springBobLine);

            #endregion

            springlineBatch.LineThickness = 2;
            Batches.Add(springlineBatch);

            //Draw origin circles depending on whether interaction is taking place.
            Batches.Add(IsInteracting
                ? DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Red)
                : DrawingMethods.FilledCircle(BobPosCanvas, (int)BobRadius, Brushes.Blue));


            //Render the batches.
            foreach (var batch in Batches)
            {
                batch.Render(Canvas);
                batch.Clear();
            }

            Batches.Clear();
        }
예제 #6
0
 public void Begin(SpriteBatch.SpriteSortMode sortMode)
 {
     Batches.Clear();
     this.sortMode = sortMode;
 }