public static void prependRotation(AsMatrix matrix, float angle) { float sin = AsMath.sin(angle); float cos = AsMath.cos(angle); matrix.setTo(matrix.a * cos + matrix.c * sin, matrix.b * cos + matrix.d * sin, matrix.c * cos - matrix.a * sin, matrix.d * cos - matrix.b * sin, matrix.tx, matrix.ty); }
public static float distance(AsPoint pt1, AsPoint pt2) { float dx = pt1.x - pt2.x; float dy = pt1.y - pt2.y; return(AsMath.sqrt(dx * dx + dy * dy)); }
private static float easeOutBounce(float ratio) { float s = 7.5625f; float p = 2.75f; float l = 0; if (ratio < (1.0f / p)) { l = s * AsMath.pow(ratio, 2); } else { if (ratio < (2.0f / p)) { ratio = ratio - 1.5f / p; l = s * AsMath.pow(ratio, 2) + 0.75f; } else { if (ratio < 2.5f / p) { ratio = ratio - 2.25f / p; l = s * AsMath.pow(ratio, 2) + 0.9375f; } else { ratio = ratio - 2.625f / p; l = s * AsMath.pow(ratio, 2) + 0.984375f; } } } return(l); }
public AsAtfData(AsByteArray data) { String signature = AsString.fromCharCode((As_AS_REST)(data.getOwnProperty(0)), data.getOwnProperty(1), data.getOwnProperty(2)); if (signature != "ATF") { throw new AsArgumentError("Invalid ATF data"); } switch (data.getOwnProperty(6)) { case 0: case 1: mFormat = AsContext3DTextureFormat.BGRA; break; case 2: case 3: mFormat = AsContext3DTextureFormat.COMPRESSED; break; case 4: case 5: mFormat = "compressedAlpha"; break; default: throw new AsError("Invalid ATF format"); } mWidth = (int)(AsMath.pow(2, (float)(data.getOwnProperty(7)))); mHeight = (int)(AsMath.pow(2, (float)(data.getOwnProperty(8)))); mNumTextures = (int)(data.getOwnProperty(9)); mData = data; }
private static float easeOutBack(float ratio) { float invRatio = ratio - 1.0f; float s = 1.70158f; return(AsMath.pow(invRatio, 2) * ((s + 1.0f) * invRatio + s) + 1.0f); }
private void processTap(AsTouch touch) { AsTouch nearbyTap = null; float minSqDist = MULTITAP_DISTANCE * MULTITAP_DISTANCE; AsVector <AsTouch> __taps_ = mLastTaps; if (__taps_ != null) { foreach (AsTouch tap in __taps_) { float sqDist = AsMath.pow(tap.getGlobalX() - touch.getGlobalX(), 2) + AsMath.pow(tap.getGlobalY() - touch.getGlobalY(), 2); if (sqDist <= minSqDist) { nearbyTap = tap; break; } } } if (nearbyTap != null) { touch.setTapCount(nearbyTap.getTapCount() + 1); mLastTaps.splice(mLastTaps.indexOf(nearbyTap), (uint)(1)); } else { touch.setTapCount(1); } mLastTaps.push(touch.clone()); }
public virtual void adjustHue(float _value) { _value = _value * AsMath.PI; float cos = AsMath.cos(_value); float sin = AsMath.sin(_value); concatValues((LUMA_R + (cos * (1 - LUMA_R))) + (sin * -LUMA_R), (LUMA_G + (cos * -LUMA_G)) + (sin * -LUMA_G), (LUMA_B + (cos * -LUMA_B)) + (sin * (1 - LUMA_B)), 0, 0, (LUMA_R + (cos * -LUMA_R)) + (sin * 0.143f), (LUMA_G + (cos * (1 - LUMA_G))) + (sin * 0.14f), (LUMA_B + (cos * -LUMA_B)) + (sin * -0.283f), 0, 0, (LUMA_R + (cos * -LUMA_R)) + (sin * -1 - LUMA_R), (LUMA_G + (cos * -LUMA_G)) + (sin * LUMA_G), (LUMA_B + (cos * (1 - LUMA_B))) + (sin * LUMA_B), 0, 0, 0, 0, 0, 1, 0); }
public static float distance(AsVector3D pt1, AsVector3D pt2) { float dx = pt1.x - pt2.x; float dy = pt1.y - pt2.y; float dz = pt1.z - pt2.z; return(AsMath.sqrt(dx * dx + dy * dy + dz * dz)); }
public virtual AsDelayedCall reset(AsDelayedCallback call, float delay, AsArray args) { mCurrentTime = 0; mTotalTime = AsMath.max(delay, 0.0001f); mCall = call; mArgs = args; mRepeatCount = 1; return(this); }
private void updateMarginsAndPasses() { if (mBlurX == 0 && mBlurY == 0) { mBlurX = 0.001f; } setNumPasses(AsMath.ceil(mBlurX) + AsMath.ceil(mBlurY)); setMarginX(4 + AsMath.ceil(mBlurX)); setMarginY(4 + AsMath.ceil(mBlurY)); }
public static AsBlurFilter createDropShadow(float distance, float angle, uint color, float alpha, float blur, float resolution) { AsBlurFilter dropShadow = new AsBlurFilter(blur, blur, resolution); dropShadow.setOffsetX(AsMath.cos(angle) * distance); dropShadow.setOffsetY(AsMath.sin(angle) * distance); dropShadow.setMode(AsFragmentFilterMode.BELOW); dropShadow.setUniformColor(true, color, alpha); return(dropShadow); }
public virtual AsTween reset(Object target, float time, Object transition) { mTarget = target; mCurrentTime = 0; mTotalTime = AsMath.max(0.0001f, time); mDelay = mRepeatDelay = 0.0f; mOnStart = mOnUpdate = mOnComplete = null; mOnStartArgs = mOnUpdateArgs = mOnCompleteArgs = null; mRoundToInt = mReverse = false; mRepeatCount = 1; mCurrentCycle = -1; if (transition is String) { this.setTransition(transition as String); } else { if (transition is AsTransitionCallback) { this.setTransitionFunc(transition as AsTransitionCallback); } else { throw new AsArgumentError("Transition must be either a string or a function"); } } if (mProperties != null) { mProperties.setLength(0); } else { mProperties = new AsVector <String>(); } if (mStartValues != null) { mStartValues.setLength(0); } else { mStartValues = new AsVector <float>(); } if (mEndValues != null) { mEndValues.setLength(0); } else { mEndValues = new AsVector <float>(); } return(this); }
private static float easeOutElastic(float ratio) { if (ratio == 0 || ratio == 1) { return(ratio); } else { float p = 0.3f; float s = p / 4.0f; return(AsMath.pow(2.0f, -10.0f * ratio) * AsMath.sin((ratio - s) * (2.0f * AsMath.PI) / p) + 1); } }
private void updateParameters(int pass, int textureWidth, int textureHeight) { float sigma = 0; bool horizontal = pass < mBlurX; float pixelSize = 0; if (horizontal) { sigma = AsMath.min(1.0f, mBlurX - pass) * MAX_SIGMA; pixelSize = 1.0f / textureWidth; } else { sigma = AsMath.min(1.0f, mBlurY - (pass - AsMath.ceil(mBlurX))) * MAX_SIGMA; pixelSize = 1.0f / textureHeight; } float twoSigmaSq = 2 * sigma * sigma; float multiplier = 1.0f / AsMath.sqrt(twoSigmaSq * AsMath.PI); int i = 0; for (; i < 4; ++i) { sTmpWeights[i] = multiplier * AsMath.exp(-i * i / twoSigmaSq); } mWeights[0] = sTmpWeights[0]; mWeights[1] = sTmpWeights[1] + sTmpWeights[2]; mWeights[2] = sTmpWeights[3] + sTmpWeights[4]; float weightSum = mWeights[0] + 2 * mWeights[1] + 2 * mWeights[2]; float invWeightSum = 1.0f / weightSum; mWeights[0] = mWeights[0] * invWeightSum; mWeights[1] = mWeights[1] * invWeightSum; mWeights[2] = mWeights[2] * invWeightSum; float offset1 = (pixelSize * sTmpWeights[1] + 2 * pixelSize * sTmpWeights[2]) / mWeights[1]; float offset2 = (3 * pixelSize * sTmpWeights[3] + 4 * pixelSize * sTmpWeights[4]) / mWeights[2]; if (horizontal) { mOffsets[0] = offset1; mOffsets[1] = 0; mOffsets[2] = offset2; mOffsets[3] = 0; } else { mOffsets[0] = 0; mOffsets[1] = offset1; mOffsets[2] = 0; mOffsets[3] = offset2; } }
private static float easeInElastic(float ratio) { if (ratio == 0 || ratio == 1) { return(ratio); } else { float p = 0.3f; float s = p / 4.0f; float invRatio = ratio - 1; return(-1.0f * AsMath.pow(2.0f, 10.0f * invRatio) * AsMath.sin((invRatio - s) * (2.0f * AsMath.PI) / p)); } }
public static void skew(AsMatrix matrix, float skewX, float skewY) { float a = matrix.a; float b = matrix.b; float c = matrix.c; float d = matrix.d; float tx = matrix.tx; float ty = matrix.ty; float sinX = AsMath.sin(skewX); float cosX = AsMath.cos(skewX); float sinY = AsMath.sin(skewY); float cosY = AsMath.cos(skewY); matrix.a = a * cosY + c * sinY; matrix.b = b * cosY + d * sinY; matrix.c = c * cosX - a * sinX; matrix.d = d * cosX - b * sinX; }
public static float angleBetween(AsVector3D a, AsVector3D b) { float aLen = a.getLength(); if (epsilonEquals(aLen, 0)) { throw new AsArgumentError(); } float bLen = b.getLength(); if (epsilonEquals(bLen, 0)) { throw new AsArgumentError(); } float dotProd = a.x * b.x + a.y * b.y + a.z * b.z; if (epsilonEquals(dotProd, 0)) { return(0.5f * AsMath.PI); } return(AsMath.acos(dotProd / aLen / bLen)); }
public virtual void advanceTime(float time) { float previousTime = mCurrentTime; mCurrentTime = AsMath.min(mTotalTime, mCurrentTime + time); if (previousTime < mTotalTime && mCurrentTime >= mTotalTime) { mCall(); if (mRepeatCount == 0 || mRepeatCount > 1) { if (mRepeatCount > 0) { mRepeatCount = mRepeatCount - 1; } mCurrentTime = 0; advanceTime((previousTime + time) - mTotalTime); } else { dispatchEventWith(AsEvent.REMOVE_FROM_JUGGLER); } } }
public virtual void setTransformationMatrix(AsMatrix matrix) { mOrientationChanged = false; mTransformationMatrix.copyFrom(matrix); mX = matrix.tx; mY = matrix.ty; float a = matrix.a; float b = matrix.b; float c = matrix.c; float d = matrix.d; mScaleX = AsMath.sqrt(a * a + b * b); if (mScaleX != 0) { mRotation = AsMath.atan2(b, a); } else { mRotation = 0; } float cosTheta = AsMath.cos(mRotation); float sinTheta = AsMath.sin(mRotation); mScaleY = d * cosTheta - c * sinTheta; if (mScaleY != 0) { mSkewX = AsMath.atan2(d * sinTheta + c * cosTheta, mScaleY); } else { mSkewX = 0; } mSkewY = 0; mPivotX = 0; mPivotY = 0; }
private static float easeInBack(float ratio) { float s = 1.70158f; return(AsMath.pow(ratio, 2) * ((s + 1.0f) * ratio - s)); }
public virtual bool nearEquals(AsVector3D toCompare, float tolerance, bool allFour) { return(AsMath.abs(x - toCompare.x) <= tolerance && AsMath.abs(y - toCompare.y) <= tolerance && AsMath.abs(z - toCompare.z) <= tolerance && (!allFour || AsMath.abs(w - toCompare.w) <= tolerance)); }
public virtual void advanceTime(float time) { if (time == 0 || (mRepeatCount == 1 && mCurrentTime == mTotalTime)) { return; } int i = 0; float previousTime = mCurrentTime; float restTime = mTotalTime - mCurrentTime; float carryOverTime = time > restTime ? time - restTime : 0.0f; mCurrentTime = AsMath.min(mTotalTime, mCurrentTime + time); if (mCurrentTime <= 0) { return; } if (mCurrentCycle < 0 && previousTime <= 0 && mCurrentTime > 0) { mCurrentCycle++; if (mOnStart != null) { mOnStart((float)(mOnStartArgs[0])); } } float ratio = mCurrentTime / mTotalTime; bool reversed = mReverse && (mCurrentCycle % 2 == 1); int numProperties = (int)(mStartValues.getLength()); for (i = 0; i < numProperties; ++i) { if (AsGlobal.isNaN(mStartValues[i])) { mStartValues[i] = ((AsObject)(mTarget)).getOwnProperty(mProperties[i]) as float; } float startValue = mStartValues[i]; float endValue = mEndValues[i]; float delta = endValue - startValue; float transitionValue = reversed ? mTransitionFunc(1.0f - ratio) : mTransitionFunc(ratio); float currentValue = startValue + transitionValue * delta; if (mRoundToInt) { currentValue = AsMath.round(currentValue); } ((AsObject)(mTarget)).setOwnProperty(mProperties[i], currentValue); } if (mOnUpdate != null) { mOnUpdate((float)(mOnUpdateArgs[0])); } if (previousTime < mTotalTime && mCurrentTime >= mTotalTime) { if (mRepeatCount == 0 || mRepeatCount > 1) { mCurrentTime = -mRepeatDelay; mCurrentCycle++; if (mRepeatCount > 1) { mRepeatCount--; } if (mOnRepeat != null) { mOnRepeat((float)(mOnRepeatArgs[0])); } } else { AsTransitionCallback onComplete = mOnComplete; AsArray onCompleteArgs = mOnCompleteArgs; dispatchEventWith(AsEvent.REMOVE_FROM_JUGGLER); if (onComplete != null) { onComplete((float)(onCompleteArgs[0])); } } } if (carryOverTime != 0) { advanceTime(carryOverTime); } }
public static AsPoint polar(float len, float angle) { return(new AsPoint(AsMath.cos(angle) * len, AsMath.sin(angle) * len)); }
public virtual float getLength() { return(AsMath.sqrt(x * x + y * y)); }
public static bool epsilonZero(float a) { return(AsMath.abs(a) < epsilon); }
public static bool epsilonEquals(float a, float b) { return(AsMath.abs((a - b)) < epsilon); }