public void AngleBlendTest() { void test(float dega, float degb, float degresult, float percent) { // check extrema AssertFloatEqualsRadians(RMathF.ToRad(dega), RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb), 0)); AssertFloatEqualsRadians(RMathF.ToRad(degb), RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb), 1f)); // check midpoint AssertFloatEqualsRadians( RMathF.AngleMidpoint(RMathF.ToRad(dega), RMathF.ToRad(degb)), RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb), 0.5f)); AssertFloatEqualsRadians(RMathF.ToRad(degresult), RMathF.AngleBlend(RMathF.ToRad(dega), RMathF.ToRad(degb), percent)); } test(100f, 200f, 125f, 0.25f); test(200f, 100f, 125f, 0.75f); test(100f, 200f, 175f, 0.75f); test(200f, 100f, 175f, 0.25f); test(350f, 10f, 355f, 0.25f); test(10f, 350f, 355f, 0.75f); test(350f, 10f, 5f, 0.75f); test(10f, 350f, 5f, 0.25f); }
private void InterpolateLogic(SnapHistory <NentBasic2d, NentStaticBasic2d> h, float delta) { // interpolate from Current forward delta ms float tickpercent = delta / NetSnapper.TickMSTarget; float invtickpercent = 1.0f - tickpercent; // we don't adjust IDs at all // pos/vel is simple, just blend h.Shots[h.CurrentIndex].X = (h.Shots[h.CurrentIndex].X * invtickpercent) + (h.Shots[h.NextIndex].X * tickpercent); h.Shots[h.CurrentIndex].Y = (h.Shots[h.CurrentIndex].Y * invtickpercent) + (h.Shots[h.NextIndex].Y * tickpercent); h.Shots[h.CurrentIndex].XVel = (h.Shots[h.CurrentIndex].XVel * invtickpercent) + (h.Shots[h.NextIndex].XVel * tickpercent); h.Shots[h.CurrentIndex].YVel = (h.Shots[h.CurrentIndex].YVel * invtickpercent) + (h.Shots[h.NextIndex].YVel * tickpercent); // it makes sense to blend Free1 as well since we just // use it as a timer, but in other cases this might not // be appropriate h.Shots[h.CurrentIndex].Free1 = (h.Shots[h.CurrentIndex].Free1 * invtickpercent) + (h.Shots[h.NextIndex].Free1 * tickpercent); // rotation is more complicated to blend h.Shots[h.CurrentIndex].Rot = RMathF.AngleBlend(h.Shots[h.CurrentIndex].Rot, h.Shots[h.NextIndex].Rot, tickpercent); }
public void BlendLogic(SnapHistory <NentBasic2d, NentStaticBasic2d> h, ref NentBasic2d shot, NentBasic2d blendTarget, float factor) { // interpolate from Current forward delta ms float invfactor = 1.0f - factor; // we don't adjust IDs at all // pos/vel is simple, just blend shot.X = (shot.X * invfactor) + (blendTarget.X * factor); shot.Y = (shot.Y * invfactor) + (blendTarget.Y * factor); shot.XVel = (shot.XVel * invfactor) + (blendTarget.XVel * factor); shot.YVel = (shot.YVel * invfactor) + (blendTarget.YVel * factor); // it makes sense to blend Free1 as well since we just // use it as a timer, but in other cases this might not // be appropriate shot.Free1 = (shot.Free1 * invfactor) + (blendTarget.Free1 * factor); // rotation is more complicated to blend shot.Rot = RMathF.AngleBlend(shot.Rot, blendTarget.Rot, factor); }