public void Scale(ref Thickness self) { self = new Thickness( ScaleFunc(self.Left, this.curWidthFactor)(), ScaleFunc(self.Top, this.curHeightFactor)(), ScaleFunc(self.Right, this.curWidthFactor)(), ScaleFunc(self.Bottom, this.curHeightFactor)()); }
public void Scale(ref Rectangle self) { self = new Rectangle( ScaleFunc(self.X, this.curWidthFactor)(), ScaleFunc(self.Y, this.curHeightFactor)(), ScaleFunc(self.Width, this.curWidthFactor)(), ScaleFunc(self.Height, this.curHeightFactor)()); }
static void MakeScaleImage(string path, int width, int height, ScaleFunc func) { Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); Rectangle lockRect = new Rectangle(0, 0, width, height); BitmapData bitmapData = bitmap.LockBits(lockRect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); double divWidth = width - 1; double divHeight = height - 1; unsafe { RGBA *pData; for (int row = 0; row < height; row++) { pData = (RGBA *)(bitmapData.Scan0 + bitmapData.Stride * row); for (int col = 0; col < width; col++) { *pData = func(col / divWidth, row / divHeight); pData++; } } } bitmap.UnlockBits(bitmapData); bitmap.Save(path); bitmap.Dispose(); }
// // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to // the next POT). The function takes a Vec2 as parameter that holds max width & height // values for the current manager context and returns a Vec2 of the final size in pixels. // // var rth = Alloc( // size => new Vector2Int(size.x / 2, size.y), // [...] // ); // public RTHandle Alloc( ScaleFunc scaleFunc, int slices = 1, DepthBits depthBufferBits = DepthBits.None, RenderTextureFormat colorFormat = RenderTextureFormat.Default, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureDimension dimension = TextureDimension.Tex2D, bool sRGB = true, bool enableRandomWrite = false, bool useMipMap = false, bool autoGenerateMips = true, int anisoLevel = 1, float mipMapBias = 0f, bool enableMSAA = false, bool bindTextureMS = false, bool useDynamicScale = false, VRTextureUsage vrUsage = VRTextureUsage.None, RenderTextureMemoryless memoryless = RenderTextureMemoryless.None, string name = "" ) { bool allocForMSAA = m_ScaledRTSupportsMSAA ? enableMSAA : false; RTCategory category = allocForMSAA ? RTCategory.MSAA : RTCategory.Regular; var scaleFactor = scaleFunc(new Vector2Int(GetMaxWidth(category), GetMaxHeight(category))); int width = Mathf.Max(scaleFactor.x, 1); int height = Mathf.Max(scaleFactor.y, 1); var rth = AllocAutoSizedRenderTexture(width, height, slices, depthBufferBits, colorFormat, filterMode, wrapMode, dimension, sRGB, enableRandomWrite, useMipMap, autoGenerateMips, anisoLevel, mipMapBias, enableMSAA, bindTextureMS, useDynamicScale, vrUsage, memoryless, name ); rth.referenceSize = new Vector2Int(width, height); rth.scaleFunc = scaleFunc; return(rth); }
/// <summary> /// TextureDesc constructor for a texture using a functor for scaling /// </summary> /// <param name="func">Function used to determnine the texture size</param> /// <param name="dynamicResolution">Use dynamic resolution</param> /// <param name="xrReady">Set this to true if the Texture is a render texture in an XR setting.</param> public TextureDesc(ScaleFunc func, bool dynamicResolution = false, bool xrReady = false) : this() { // Size related init sizeMode = TextureSizeMode.Functor; this.func = func; // Important default values not handled by zero construction in this() msaaSamples = MSAASamples.None; dimension = TextureDimension.Tex2D; InitDefaultValues(dynamicResolution, xrReady); }
// // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to // the next POT). The function takes a Vec2 as parameter that holds max width & height // values for the current manager context and returns a Vec2 of the final size in pixels. // // var rth = Alloc( // size => new Vector2Int(size.x / 2, size.y), // [...] // ); // public RTHandle Alloc( ScaleFunc scaleFunc, int slices = 1, DepthBits depthBufferBits = DepthBits.None, GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureDimension dimension = TextureDimension.Tex2D, bool enableRandomWrite = false, bool useMipMap = false, bool autoGenerateMips = true, bool isShadowMap = false, int anisoLevel = 1, float mipMapBias = 0f, bool enableMSAA = false, bool bindTextureMS = false, bool useDynamicScale = false, bool xrInstancing = false, RenderTextureMemoryless memoryless = RenderTextureMemoryless.None, string name = "" ) { var scaleFactor = scaleFunc(new Vector2Int(GetMaxWidth(), GetMaxHeight())); int width = Mathf.Max(scaleFactor.x, 1); int height = Mathf.Max(scaleFactor.y, 1); var rth = AllocAutoSizedRenderTexture(width, height, slices, depthBufferBits, colorFormat, filterMode, wrapMode, dimension, enableRandomWrite, useMipMap, autoGenerateMips, isShadowMap, anisoLevel, mipMapBias, enableMSAA, bindTextureMS, useDynamicScale, xrInstancing, memoryless, name ); rth.referenceSize = new Vector2Int(width, height); rth.scaleFunc = scaleFunc; return(rth); }
// // You can provide your own scaling function for advanced scaling schemes (e.g. scaling to // the next POT). The function takes a Vec2 as parameter that holds max width & height // values for the current manager context and returns a Vec2 of the final size in pixels. // // var rth = Alloc( // size => new Vector2Int(size.x / 2, size.y), // [...] // ); // public static RTHandle Alloc( ScaleFunc scaleFunc, DepthBits depthBufferBits = DepthBits.None, RenderTextureFormat colorFormat = RenderTextureFormat.Default, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureDimension dimension = TextureDimension.Tex2D, bool sRGB = true, bool enableRandomWrite = false, bool useMipMap = false, bool autoGenerateMips = true, int anisoLevel = 1, float mipMapBias = 0f, MSAASamples msaaSamples = MSAASamples.None, bool bindTextureMS = false, bool useDynamicScale = false, VRTextureUsage vrUsage = VRTextureUsage.None, RenderTextureMemoryless memoryless = RenderTextureMemoryless.None ) { var scaleFactor = scaleFunc(new Vector2Int(s_MaxWidth, s_MaxHeight)); int width = Mathf.Max(scaleFactor.x, 1); int height = Mathf.Max(scaleFactor.y, 1); var rth = Alloc(width, height, 1, depthBufferBits, colorFormat, filterMode, wrapMode, dimension, sRGB, enableRandomWrite, useMipMap, autoGenerateMips, anisoLevel, mipMapBias, msaaSamples, bindTextureMS, useDynamicScale, vrUsage, memoryless ); rth.scaleFunc = scaleFunc; s_AutoSizedRTs.Add(rth); return(rth); }
/// <summary> /// Starts a tween. /// </summary> /// <param name="start">The start value.</param> /// <param name="end">The end value.</param> /// <param name="duration">The duration of the tween.</param> /// <param name="scaleFunc">A function used to scale progress over time.</param> public void Start(T start, T end, float duration, ScaleFunc scaleFunc) { if (duration <= 0) { throw new ArgumentException("duration must be greater than 0"); } this._currentTime = 0; this._duration = duration; this._scaleFunc = scaleFunc ?? throw new ArgumentNullException("scaleFunc"); this._state = TweenState.Running; this._start = start; this._end = end; this.UpdateValue(); }
public static RTHandleSystem.RTHandle Alloc( ScaleFunc scaleFunc, int slices = 1, DepthBits depthBufferBits = DepthBits.None, GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_SRGB, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureDimension dimension = TextureDimension.Tex2D, bool enableRandomWrite = false, bool useMipMap = false, bool autoGenerateMips = true, bool isShadowMap = false, int anisoLevel = 1, float mipMapBias = 0, bool enableMSAA = false, bool bindTextureMS = false, bool useDynamicScale = false, bool xrInstancing = false, RenderTextureMemoryless memoryless = RenderTextureMemoryless.None, string name = "" ) { return(s_DefaultInstance.Alloc( scaleFunc, slices, depthBufferBits, colorFormat, filterMode, wrapMode, dimension, enableRandomWrite, useMipMap, autoGenerateMips, isShadowMap, anisoLevel, mipMapBias, enableMSAA, bindTextureMS, useDynamicScale, xrInstancing, memoryless, name )); }
public static RTHandleSystem.RTHandle Alloc( ScaleFunc scaleFunc, DepthBits depthBufferBits = DepthBits.None, RenderTextureFormat colorFormat = RenderTextureFormat.Default, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat, TextureDimension dimension = TextureDimension.Tex2D, bool sRGB = true, bool enableRandomWrite = false, bool useMipMap = false, bool autoGenerateMips = true, int anisoLevel = 1, float mipMapBias = 0, bool enableMSAA = false, bool bindTextureMS = false, bool useDynamicScale = false, VRTextureUsage vrUsage = VRTextureUsage.None, RenderTextureMemoryless memoryless = RenderTextureMemoryless.None, string name = "" ) { return(s_DefaultInstance.Alloc( scaleFunc, depthBufferBits, colorFormat, filterMode, wrapMode, dimension, sRGB, enableRandomWrite, useMipMap, autoGenerateMips, anisoLevel, mipMapBias, enableMSAA, bindTextureMS, useDynamicScale, vrUsage, memoryless, name )); }
public void Scale(ref Size self) { self = new Size( ScaleFunc(self.Width, this.curWidthFactor)(), ScaleFunc(self.Height, this.curHeightFactor)()); }
/// <summary> /// Starts a tween. /// </summary> /// <param name="start">The start value.</param> /// <param name="end">The end value.</param> /// <param name="duration">The duration of the tween.</param> /// <param name="scaleFunc">A function used to scale progress over time.</param> public void Start(T start, T end, float duration, Easing easing) { if (duration <= 0) { throw new ArgumentException("duration must be greater than 0"); } switch (easing) { case Easing.Linear: this.scaleFunc = ScaleFuncs.Linear; break; case Easing.CubicEaseIn: this.scaleFunc = ScaleFuncs.CubicEaseIn; break; case Easing.CubicEaseOut: this.scaleFunc = ScaleFuncs.CubicEaseOut; break; case Easing.CubicEaseInOut: this.scaleFunc = ScaleFuncs.CubicEaseInOut; break; case Easing.QuadraticEaseIn: this.scaleFunc = ScaleFuncs.QuadraticEaseIn; break; case Easing.QuadraticEaseOut: this.scaleFunc = ScaleFuncs.QuadraticEaseOut; break; case Easing.QuadraticEaseInOut: this.scaleFunc = ScaleFuncs.QuadraticEaseInOut; break; case Easing.QuarticEaseIn: this.scaleFunc = ScaleFuncs.QuarticEaseIn; break; case Easing.QuarticEaseOut: this.scaleFunc = ScaleFuncs.QuarticEaseOut; break; case Easing.QuarticEaseInOut: this.scaleFunc = ScaleFuncs.QuarticEaseInOut; break; case Easing.SineEaseIn: this.scaleFunc = ScaleFuncs.SineEaseIn; break; case Easing.SineEaseOut: this.scaleFunc = ScaleFuncs.SineEaseOut; break; case Easing.SineEaseInOut: this.scaleFunc = ScaleFuncs.SineEaseInOut; break; default: this.scaleFunc = ScaleFuncs.Linear; break; } currentTime = 0; this.duration = duration; state = TweenState.Running; this.start = start; this.end = end; UpdateValue(); }
public Tween() { ScaleFunc = DefaultScaleFunc; }
// private static float RecoilMax = -0.15f; // private static Vector3 curOffset = new Vector3(0f, 0f, 0f); // public static void AddOffset(float dist, float dir) // { // curOffset += Quaternion.AngleAxis(dir, Vector3.up) * Vector3.forward * dist; // if (curOffset.sqrMagnitude > RecoilMax * RecoilMax) // { // curOffset *= RecoilMax / curOffset.magnitude; // } // } public static void DoWeaponOffsets(Pawn pawn, Thing eq, ref Vector3 drawLoc, ref float weaponAngle, ref Mesh weaponMesh) { CompProperties_WeaponExtensions extensions = eq.def.GetCompProperties <CompProperties_WeaponExtensions>(); bool flipped = weaponMesh == MeshPool.plane10Flip; if ((pawn == null) || (!pawn.GetCompAnim(out CompBodyAnimator animator)) || (extensions == null)) { return; } float sizeMod = 1f; // if (Controller.settings.IReallyLikeBigGuns) { sizeMod = 2.0f; } // else if (Controller.settings.ILikeBigGuns) // { // sizeMod = 1.4f; // } // else // { // sizeMod = 1f; // } if (Find.TickManager.TicksGame == animator.LastPosUpdate[(int)equipment] || MainTabWindow_WalkAnimator.IsOpen && MainTabWindow_WalkAnimator.Pawn != pawn) { drawLoc = animator.LastPosition[(int)equipment]; weaponAngle = animator.LastWeaponAngle; } else { animator.LastPosUpdate[(int)equipment] = Find.TickManager.TicksGame; CalculatePositionsWeapon(pawn, ref weaponAngle, extensions, out Vector3 weaponPosOffset, out bool aiming, flipped); // weapon angle and position offsets based on current attack keyframes sequence DoAttackAnimationOffsetsWeapons(pawn, ref weaponAngle, ref weaponPosOffset, flipped, animator, out bool noTween); drawLoc += weaponPosOffset * sizeMod; Vector3Tween eqTween = animator.Vector3Tweens[(int)equipment]; if (pawn.pather.MovedRecently(5)) { noTween = true; } switch (eqTween.State) { case TweenState.Running: if (noTween || animator.IsMoving) { eqTween.Stop(StopBehavior.ForceComplete); } drawLoc = eqTween.CurrentValue; break; case TweenState.Paused: break; case TweenState.Stopped: if (noTween || (animator.IsMoving)) { break; } ScaleFunc scaleFunc = ScaleFuncs.SineEaseOut; Vector3 start = animator.LastPosition[(int)equipment]; float distance = Vector3.Distance(start, drawLoc); float duration = Mathf.Abs(distance * 50f); if (start != Vector3.zero && duration > 12f) { start.y = drawLoc.y; eqTween.Start(start, drawLoc, duration, scaleFunc); drawLoc = start; } break; } // // fix the reset to default pos is target is changing // bool isAimAngle = (Math.Abs(aimAngle - angleStanding) <= 0.1f); // bool isAimAngleFlipped = (Math.Abs(aimAngle - angleStandingFlipped) <= 0.1f); // // if (aiming && (isAimAngle || isAimAngleFlipped)) // { // // use the last known position to avoid 1 frame flipping when target changes // drawLoc = animator.lastPosition[(int)equipment]; // weaponAngle = animator.lastWeaponAngle; // } // else { animator.LastPosition[(int)equipment] = drawLoc; animator.LastWeaponAngle = weaponAngle; animator.MeshFlipped = flipped; } } // Now the remaining hands if possible if (animator.Props.bipedWithHands && Controller.settings.UseHands) { SetPositionsForHandsOnWeapons( drawLoc, flipped, weaponAngle, extensions, animator, sizeMod); } }
public static void Scale(ref Range self, double scale) { self = new Range(ScaleFunc(self.First, scale)(), ScaleFunc(self.Last, scale)()); }
public static void Scale(ref int self, double scale) { self = ScaleFunc(self, scale)(); }
private void DrawTweenedHand(Vector3 position, Mesh handsMesh, Material material, Quaternion quat, TweenThing tweenThing, bool portrait, bool noTween) { if (position == Vector3.zero || handsMesh == null || material == null || quat == null || tweenThing == null) { return; } if (!this.Pawn.Downed || !this.Pawn.Dead) { if (!HarmonyPatchesFS.AnimatorIsOpen() && Find.TickManager.TicksGame == this.CompAnimator.LastPosUpdate[(int)tweenThing] || HarmonyPatchesFS.AnimatorIsOpen() && MainTabWindow_BaseAnimator.Pawn != this.Pawn) { position = this.CompAnimator.LastPosition[(int)tweenThing]; } else { if (this.Pawn.pather.MovedRecently(5)) { noTween = true; } this.CompAnimator.LastPosUpdate[(int)tweenThing] = Find.TickManager.TicksGame; Vector3Tween tween = this.CompAnimator.Vector3Tweens[(int)tweenThing]; switch (tween.State) { case TweenState.Running: if (noTween || this.CompAnimator.IsMoving) { tween.Stop(StopBehavior.ForceComplete); } position = tween.CurrentValue; break; case TweenState.Paused: break; case TweenState.Stopped: if (noTween || (this.CompAnimator.IsMoving)) { break; } ScaleFunc scaleFunc = ScaleFuncs.SineEaseOut; Vector3 start = this.CompAnimator.LastPosition[(int)tweenThing]; float distance = Vector3.Distance(start, position); float duration = Mathf.Abs(distance * 50f); if (start != Vector3.zero && duration > 12f) { start.y = position.y; tween.Start(start, position, duration, scaleFunc); position = start; } break; } this.CompAnimator.LastPosition[(int)tweenThing] = position; } } // tweener.PreThingPosCalculation(tweenThing, noTween); GenDraw.DrawMeshNowOrLater( handsMesh, position, quat, material, portrait); }
public void Scale(ref Point self) { self = new Point( ScaleFunc(self.X, this.curWidthFactor)(), ScaleFunc(self.Y, this.curHeightFactor)()); }
public TweenBuilder <TTarget> ScaleFunc(ScaleFunc scaleFunc) { CurrentTween.ScaleFunc = scaleFunc; return(this); }