コード例 #1
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
 /// <summary>
 /// Create a triangle primitive.
 /// </summary>
 /// <param name="p1">Fist point, in pixels.</param>
 /// <param name="p2">Second point, in pixels.</param>
 /// <param name="p3">Third point, in pixels.</param>
 private void CreateTriangle(Vector2 p1, Vector2 p2, Vector2 p3)
 {
     VectorList.Add(p1);
     VectorList.Add(p2);
     VectorList.Add(p3);
     VectorList.Add(p1);
 }
コード例 #2
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
 /// <summary>
 /// Create a square primitive.
 /// </summary>
 /// <param name="topLeft">Top left hand corner of the square.</param>
 /// <param name="bottomRight">Bottom right hand corner of the square.</param>
 private void CreateSquare(Vector2 topLeft, Vector2 bottomRight)
 {
     VectorList.Add(topLeft);
     VectorList.Add(new Vector2(topLeft.X, bottomRight.Y));
     VectorList.Add(bottomRight);
     VectorList.Add(new Vector2(bottomRight.X, topLeft.Y));
     VectorList.Add(topLeft);
 }
コード例 #3
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
        /// <summary>
        /// draw a pie shape
        /// </summary>
        /// <param name="Position">location to draw the pie</param>
        /// <param name="radius">the radius of the pie</param>
        /// <param name="startAngle">the angle to start the pie</param>
        /// <param name="sweepAngle">the sweep angle of the pie</param>
        /// <param name="color">color dat pie</param>
        public void Pie(Vector2 position, float radius, float startAngle, float sweepAngle, Color color)
        {
            Clear();
            Position = position;
            Color    = color;

            VectorList.Add(Vector2.Zero);
            CreateArc(radius, NumCircleSegments, startAngle, sweepAngle);
            VectorList.Add(Vector2.Zero);

            RenderLinePrimitive();
        }
コード例 #4
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
        /// <summary>
        /// Creates an ellipse starting from (0, 0) with the given width and height.
        /// Vectors are generated using the parametric equation of an ellipse.
        /// </summary>
        /// <param name="semiMajorAxis">The width of the ellipse at its center.</param>
        /// <param name="semiMinorAxis">The height of the ellipse at its center.</param>
        /// <param name="sides">The number of sides on the ellipse. (64 is average).</param>
        private void CreateEllipse(float semiMajorAxis, float semiMinorAxis, int sides)
        {
            // Local variables.
            float fMax  = (float)MathHelper.TwoPi;
            float fStep = fMax / (float)sides;

            // Create full ellipse.
            for (float fTheta = fMax; fTheta >= -1; fTheta -= fStep)
            {
                VectorList.Add(new Vector2((float)(semiMajorAxis * Math.Cos(fTheta)),
                                           (float)(semiMinorAxis * Math.Sin(fTheta))));
            }
        }
コード例 #5
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
        /// <summary>
        /// Creates a circle starting from (0, 0).
        /// </summary>
        /// <param name="radius">The radius (half the width) of the circle.</param>
        /// <param name="sides">The number of sides on the circle. (64 is average).</param>
        private void CreateArc(float radius, int sides, float startAngle, float sweepAngle)
        {
            float step = sweepAngle / (float)sides;

            // Create the full circle.
            var numSteps = 0;
            var theta    = startAngle;

            while (numSteps < sides + 1)
            {
                VectorList.Add(new Vector2(radius * (float)Math.Cos(theta),
                                           radius * (float)Math.Sin(theta)));
                numSteps++;
                theta += step;
            }
        }
コード例 #6
0
        public void SineWave(Vector2 start, Vector2 end, float frequency, float amplitude, Color color)
        {
            Clear();
            Color = color;

            //get the length of the sine wave
            var length = (end - start).Length();

            //lay out all the points
            float segmentLength = 5f;
            float xPos          = 0f;
            float mid           = length / 2f;

            while ((xPos + segmentLength) < length)
            {
                var ratio = 1f - (Math.Abs(mid - xPos) / mid);
                VectorList.Add(new Vector2(xPos, ratio * (float)(Math.Sin(frequency * xPos) * amplitude)));
                //VectorList.Add(new Vector2(xPos, 0));
                xPos += segmentLength;
            }

            //add the last line segment at the end
            VectorList.Add(new Vector2(length, 0f));

            //create the rotaion matrix
            Matrix mat = Matrix.CreateRotationZ((end - start).Angle());

            //multiply the rotaion by the translation matrices
            mat *= Matrix.CreateTranslation(start.X, start.Y, 0f);

            //multiply each point by the combined matrix
            for (int i = 0; i < VectorList.Count; i++)
            {
                VectorList[i] = MatrixExtensions.MatrixExt.Multiply(mat, VectorList[i]);
            }

            RenderLinePrimitive();
        }
コード例 #7
0
ファイル: Primitive.cs プロジェクト: FabianKramm/simulation
 /// <summary>
 /// Create a line primitive.
 /// </summary>
 /// <param name="start">Start of the line, in pixels.</param>
 /// <param name="end">End of the line, in pixels.</param>
 private void CreateLine(Vector2 start, Vector2 end)
 {
     VectorList.Add(start);
     VectorList.Add(end);
 }