public override float Interpolate(float theBlend)
        {
            switch (mode)
            {
            case CCInterpolationMode.IN:
                return(1 - CCMath.Sqrt(1 - theBlend * theBlend));

            case CCInterpolationMode.OUT:
                theBlend = 1 - theBlend;
                return(CCMath.Sqrt(1 - theBlend * theBlend));
            }
            theBlend *= 2;
            if (theBlend < 1)
            {
                return(-0.5f * (CCMath.Sqrt(1 - theBlend * theBlend) - 1));
            }
            return(0.5f * (CCMath.Sqrt(1 - CCMath.Sq(2 - theBlend)) + 1));
        }
 /// <summary>
 /// Generates the next pseudorandom, Gaussian (normally) distributed
 /// double value, with mean 0.0 and standard deviation 1.0.
 /// <para>This is described in section 3.4.1 of <em>The Art of Computer
 /// Programming, Volume 2</em> by Donald Knuth.
 ///
 /// </para>
 /// </summary>
 /// <returns> the next pseudorandom Gaussian distributed double </returns>
 public virtual float NextGaussian()
 {
     lock (this)
     {
         if (haveNextNextGaussian)
         {
             haveNextNextGaussian = false;
             return(nextNextGaussian);
         }
         float v1, v2, s;
         do
         {
             v1 = 2 * NextFloat() - 1;                     // Between -1.0 and 1.0.
             v2 = 2 * NextFloat() - 1;                     // Between -1.0 and 1.0.
             s  = v1 * v1 + v2 * v2;
         } while (s >= 1);
         float norm = (float)CCMath.Sqrt(-2 * CCMath.Log(s) / s);
         nextNextGaussian     = v2 * norm;
         haveNextNextGaussian = true;
         return(v1 * norm);
     }
 }
Ejemplo n.º 3
0
        public void Ellipse(float theX, float theY, float theZ, float theWidth, float theHeight, bool theDrawOutline = false)
        {
            var myX      = theX;
            var myY      = theY;
            var myWidth  = theWidth;
            var myHeight = theHeight;

            switch (_myEllipseMode)
            {
            case CCShapeMode.CORNERS:
                myWidth  = theWidth - theX;
                myHeight = theHeight - theY;
                break;

            case CCShapeMode.RADIUS:
                myX      = theX - theWidth;
                myY      = theY - theHeight;
                myWidth  = theWidth * 2;
                myHeight = theHeight * 2;
                break;

            case CCShapeMode.CORNER:
            case CCShapeMode.CENTER:
                break;

            default:
                myX = theX - theWidth / 2f;
                myY = theY - theHeight / 2f;
                break;
            }
            // undo negative width
            if (myWidth < 0)
            {
                myX    += myWidth;
                myWidth = -myWidth;
            }

            // undo negative height
            if (myHeight < 0)
            {
                myY     += myHeight;
                myHeight = -myHeight;
            }

            myWidth  /= 2;
            myHeight /= 2;

            myX += myWidth;
            myY += myHeight;

            var accuracy = (int)(4 + CCMath.Sqrt(myWidth + myHeight) * 3);
            var inc      = (float)sinCosLength / accuracy;

            if (theDrawOutline)
            {
                GL.Begin(GL.LINE_STRIP);
                float val = 0;
                GL.Color(_myColor);
                for (var i = 0; i < accuracy; i++)
                {
                    GL.Vertex3(
                        myX + CosLut[(int)val] * myWidth,
                        myY + SinLut[(int)val] * myHeight,
                        theZ
                        );
                    val += inc;
                }
                // back to the beginning
                GL.Vertex3(myX + CosLut[0] * myWidth, myY + SinLut[0] * myHeight, theZ);
                GL.End();
            }
            else
            {
                GL.Begin(GL.TRIANGLE_STRIP);
                GL.Color(_myColor);
                float val = 0;
                for (var i = 0; i < accuracy; i++)
                {
                    GL.Vertex3(myX, myY, theZ);
                    GL.Vertex3(
                        myX + CosLut[(int)val] * myWidth,
                        myY + SinLut[(int)val] * myHeight,
                        theZ
                        );
                    val += inc;
                }
                // back to the beginning
                GL.Vertex3(myX + CosLut[0] * myWidth, myY + SinLut[0] * myHeight, theZ);
                GL.End();
            }
        }