public void Normalize() { Fix64 f = Fix64.One / Fix64.Sqrt(this.x * this.x + this.y * this.y); this.x *= f; this.y *= f; }
public static FVec2 NormalizeSafe(FVec2 v) { Fix64 dis = Fix64.Sqrt(v.x * v.x + v.y * v.y); if (dis == Fix64.Zero) { return(new FVec2()); } return(v * (Fix64.One / dis)); }
public FVec2 NormalizeSafe() { Fix64 dis = Fix64.Sqrt(this.x * this.x + this.y * this.y); if (dis == Fix64.Zero) { return(new FVec2()); } return(this * (Fix64.One / dis)); }
public static FVec4 NormalizeSafe(FVec4 v) { Fix64 dis = Fix64.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w); if (dis == Fix64.Zero) { return(new FVec4()); } return(v * (Fix64.One / dis)); }
public static FVec2 ClampMagnitude(FVec2 v, Fix64 maxLength) { FVec2 nor = v; Fix64 sqrMagnitude = nor.SqrMagnitude(); if (sqrMagnitude > (maxLength * maxLength)) { nor = nor * (maxLength / Fix64.Sqrt(sqrMagnitude)); } return(nor); }
public void ClampMagnitude(Fix64 maxLength) { Fix64 sqrMagnitude = this.SqrMagnitude(); if (sqrMagnitude > (maxLength * maxLength)) { Fix64 f = maxLength / Fix64.Sqrt(sqrMagnitude); this.x *= f; this.y *= f; } }
public FVec3 Refract(FVec3 normal, Fix64 refractionIndex) { //Fix64 refractionIndex = refractionIndexEnter / refractionIndexExit; Fix64 cosI = -normal.Dot(this); Fix64 sinT2 = refractionIndex * refractionIndex * (Fix64.One - cosI * cosI); if (sinT2 > Fix64.One) { return(this); } Fix64 cosT = Fix64.Sqrt(Fix64.One - sinT2); return(this * refractionIndex + normal * (refractionIndex * cosI - cosT)); }
public static FVec3 MoveTowards(FVec3 current, FVec3 target, Fix64 maxDistanceDelta) { FVec3 delta = target - current; Fix64 sqrDelta = delta.SqrMagnitude(); Fix64 sqrDistance = maxDistanceDelta * maxDistanceDelta; if (sqrDelta > sqrDistance) { Fix64 magnitude = Fix64.Sqrt(sqrDelta); if (magnitude > Fix64.Epsilon) { delta = delta * maxDistanceDelta / magnitude + current; return(delta); } return(current); } return(target); }
public static FVec3 OrthoNormalVector(FVec3 v) { FVec3 res = new FVec3(); if (Fix64.Abs(v.z) > OVER_SQRT2) { Fix64 a = v.y * v.y + v.z * v.z; Fix64 k = Fix64.One / Fix64.Sqrt(a); res.x = Fix64.Zero; res.y = -v.z * k; res.z = v.y * k; } else { Fix64 a = v.x * v.x + v.y * v.y; Fix64 k = Fix64.One / Fix64.Sqrt(a); res.x = -v.y * k; res.y = v.x * k; res.z = Fix64.Zero; } return(res); }
public static FVec2 Normalize(FVec2 v) { return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y))); }
public Fix64 Magnitude() { return(Fix64.Sqrt(this.x * this.x + this.y * this.y)); }
public static FVec3 Normalize(FVec3 v) { return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z))); }
public static FVec4 Normalize(FVec4 v) { return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w))); }
public Fix64 Magnitude() { return(Fix64.Sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w)); }