public float EffectBlend(CCEffectData theData, float theBlend) { switch (theBlend) { case 0: return(0); case 1: return(1); } var myOffsetSum = modulation.OffsetSum() * blendAmp; var myModulation = modulation.Modulation(theData) * blendAmp; var myBlend = (myModulation - myOffsetSum) + theBlend * (1 + myOffsetSum * 2); myBlend = CCMath.Saturate(myBlend); if (interpolator) { myBlend = interpolator.Interpolate(myBlend); } return(myBlend); }
static CCGraphics() { SinLut = new float[sinCosLength]; CosLut = new float[sinCosLength]; for (var i = 0; i < sinCosLength; i++) { SinLut[i] = CCMath.Sin(i * CCMath.DEG_TO_RAD * sinCosPrecision); CosLut[i] = CCMath.Cos(i * CCMath.DEG_TO_RAD * sinCosPrecision); } // Unity has a built-in shader that is useful for drawing // simple colored things. var shader = Shader.Find("Hidden/Internal-Colored"); colorMaterial = new Material(shader) { hideFlags = HideFlags.HideAndDontSave }; // Turn on alpha blending colorMaterial.SetInt(SrcBlend, (int)Rendering.BlendMode.SrcAlpha); colorMaterial.SetInt(DstBlend, (int)Rendering.BlendMode.OneMinusSrcAlpha); // Turn backface culling off colorMaterial.SetInt(Cull, (int)Rendering.CullMode.Off); // Turn off depth writes colorMaterial.SetInt(ZWrite, 0); }
public override float Process(int theChannel, float theData, float theTime) { if (_myValues == null || theChannel >= _myChannels || _myValues.Length < _myChannels) { _myChannels = theChannel + 1; _myValues = new float[_myChannels]; } if (_myValues[theChannel] == 0) { _myValues[theChannel] = theData; return(_myValues[theChannel]); } if (CCMath.Abs(_myValues[theChannel] - theData) > skipRange && skipRange > 0) { _myValues[theChannel] = theData; return(_myValues[theChannel]); } _myValues[theChannel] = CCMath.Blend(theData, _myValues[theChannel], weight); if (bypass) { return(theData); } return(_myValues[theChannel]); }
/// <summary> /// Discretizes the spline on the count points /// </summary> /// <param name="theCount">resolution of the discretized spline</param> /// <returns>List of theCount points on the spline</returns> public List <Vector3> Discretize(int theCount) { List <Vector3> myResult = new List <Vector3>(); for (int i = 0; i < theCount; i++) { float myT = CCMath.Map(i, 0, theCount - 1, 0, 1); myResult.Add(Interpolate(myT)); } return(myResult); }
private float[] Step(float[] theValues) { var myResult = new float[theValues.Length]; for (var i = 0; i < theValues.Length; i++) { myResult[i] = CCMath.Step(_cRatio, theValues[i]); } return(myResult); }
private static void RenderGraph(IReadOnlyList <float> theList, Color theColor, float theY0, float theY1, float theMax) { GL.Begin(GL.LINE_STRIP); GL.Color(theColor); for (var i = 0; i < theList.Count; i++) { var x = (float)i / (theList.Count - 1); var y = CCMath.Blend(theY0, theY1, CCMath.Saturate(CCMath.Norm(theList[i], -theMax, theMax))); GL.Vertex3(x, y, 0); } GL.End(); }
public override float Interpolate(float theBlend) { switch (mode) { case CCInterpolationMode.IN: return(1 - CCMath.Cos(theBlend * CCMath.HALF_PI)); case CCInterpolationMode.OUT: return(CCMath.Sin(theBlend * CCMath.HALF_PI)); } return((CCMath.Cos(CCMath.PI + CCMath.PI * theBlend) + 1) / 2); }
public override float Interpolate(float theBlend) { switch (mode) { case CCInterpolationMode.IN: return(CCMath.Sq(theBlend)); case CCInterpolationMode.OUT: return(-(theBlend) * (theBlend - 2)); } if (theBlend < 0.5) { return(2 * theBlend * theBlend); } return(1 - 2 * CCMath.Sq(1 - theBlend)); }
public override float Interpolate(float theBlend) { switch (mode) { case CCInterpolationMode.IN: return((theBlend == 0) ? 0 : theBlend *CCMath.Pow(2, 10 *(theBlend - 1))); case CCInterpolationMode.OUT: return((theBlend == 1) ? 1 : (-CCMath.Pow(2, -10 * theBlend) + 1)); } if ((theBlend) < 0.5) { return(0.5f * CCMath.Pow(2, 10 * (theBlend - 1))); } return(0.5f * (-CCMath.Pow(2, -10 * (theBlend - 1)) + 2)); }
public override float Interpolate(float theBlend) { switch (mode) { case CCInterpolationMode.IN: return(CCMath.Pow(theBlend, pow)); case CCInterpolationMode.OUT: return(1 - CCMath.Pow(1 - theBlend, pow)); } if (theBlend < 0.5f) { return(CCMath.Pow(theBlend * 2, pow) / 2); } return(1 - CCMath.Pow((1 - theBlend) * 2, pow) / 2); }
public override void GetData(RenderTexture theTargetMap, List <Vector4> theDataList) { if (curves.Count <= 0) { return; } for (var y = 0; y < theTargetMap.height; y++) { var myCurve = curves[y % curves.Count]; for (var x = 0; x < theTargetMap.width; x++) { var value = myCurve.Evaluate(CCMath.Norm(x, 0, theTargetMap.width - 1)); theDataList.Add(new Vector4(value, 0, 0, 0)); } } }
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)); }
private void LateUpdate() { effects.effectDatas.ForEach(data => { var angle = CCMath.Degrees(data.angle); var velocity = (angle - _lastVal[data.id]) / Time.deltaTime; var acceleration = (velocity - _lastVel[data.id]) / Time.deltaTime; var jerk = (acceleration - _lastAcc[data.id]) / Time.deltaTime; AddData(val, _lastVal, data.id, angle); AddData(vel, _lastVel, data.id, velocity); AddData(acc, _lastAcc, data.id, acceleration); AddData(jer, null, data.id, jerk); _lastVal[data.id] = angle; _lastVel[data.id] = velocity; _lastAcc[data.id] = acceleration; }); }
/// <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); } }
public override float Process(int theChannel, float signal, float theTime) { _myChannels = CCMath.Max(_myChannels, theChannel + 1); // Debug.Log(_myChannels + " " + input.Length); // make sure we have enough filter buffers if (input == null || input.Length != _myChannels || (input[theChannel].Length < a.Length && input[theChannel].Length < b.Length)) { InitArrays(); } // apply the filter to the sample value in each channel Array.Copy(input[theChannel], 0, input[theChannel], 1, input[theChannel].Length - 1); input[theChannel][0] = signal; float y = 0; for (int ci = 0; ci < a.Length; ci++) { y += a[ci] * input[theChannel][ci]; } for (int ci = 0; ci < b.Length; ci++) { y += b[ci] * output[theChannel][ci]; } Array.Copy(output[theChannel], 0, output[theChannel], 1, output[theChannel].Length - 1); if (double.IsNaN(y)) { y = 0; } output[theChannel][0] = y; if (bypass) { return(signal); } return(y); }
public override int NumberOfSegments() { return(CCMath.Max(_mySpline1.NumberOfSegments(), _mySpline2.NumberOfSegments())); }
public override float TotalLength() { return(CCMath.Blend(_mySpline1.TotalLength(), _mySpline2.TotalLength(), _myBlend)); }
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(); } }
protected internal override void CalcCoeff() { calcpoles(); // System.out.println("ChebFilter is calculating coefficients..."); // initialize our arrays for (int i = 0; i < 23; ++i) { ca[i] = cb[i] = ta[i] = tb[i] = 0.0f; } // I don't know why this must be done ca[2] = 1.0f; cb[2] = 1.0f; // calculate two poles at a time for (int p = 1; p <= poles / 2; p++) { // calc pair p, put the results in pa and pb calcTwoPole(p, pa, pb); // copy ca and cb into ta and tb Array.Copy(ca, 0, ta, 0, ta.Length); Array.Copy(cb, 0, tb, 0, tb.Length); // add coefficients to the cascade for (int i = 2; i < 23; i++) { ca[i] = pa[0] * ta[i] + pa[1] * ta[i - 1] + pa[2] * ta[i - 2]; cb[i] = tb[i] - pb[0] * tb[i - 1] - pb[1] * tb[i - 2]; } } // final stage of combining coefficients cb[2] = 0; for (int i = 0; i < 21; i++) { ca[i] = ca[i + 2]; cb[i] = -cb[i + 2]; } // normalize the gain float sa = 0; float sb = 0; for (int i = 0; i < 21; i++) { if (type == ChebFilterType.LP) { sa += ca[i]; sb += cb[i]; } else { sa += ca[i] * CCMath.Pow(-1, i); sb += cb[i] * CCMath.Pow(-1, i); } } float gain = sa / (1 - sb); for (int i = 0; i < 21; i++) { ca[i] /= gain; } // initialize the coefficient arrays used by process() // but only if the number of poles has changed if (a == null || a.Length != poles + 1) { a = new float[poles + 1]; } if (b == null || b.Length != poles) { b = new float[poles]; } // copy the values from ca and cb into a and b // in this implementation cb[0] = 0 and cb[1] is where // the b coefficients begin, so they are numbered the way // one normally numbers coefficients when talking about IIR filters // however, process() expects b[0] to be the coefficient B1 // so we copy cb over to b starting at index 1 Array.Copy(ca, 0, a, 0, a.Length); Array.Copy(cb, 1, b, 0, b.Length); }
/// <summary> /// @shortdesc Returns the next pseudorandom, Gaussian ("normally") distributed double value /// Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean /// 0.0 and standard deviation 1.0 from this random number generator's sequence. The general /// contract of nextGaussian is that one double value, chosen from (approximately) the usual /// normal distribution with mean 0.0 and standard deviation 1.0, is pseudo randomly generated /// and returned. /// /// This method ensures that the result is mapped between 0 and 1. </summary> /// <returns> gaussian random </returns> public virtual float GaussianRandom() { return((CCMath.Constrain(NextGaussian() / 4f, -1, 1) + 1) / 2); }