Example #1
0
        public void Normalize()
        {
            Fix64 f = Fix64.One / Fix64.Sqrt(this.x * this.x + this.y * this.y);

            this.x *= f;
            this.y *= f;
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }
Example #6
0
        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;
            }
        }
Example #7
0
        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));
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 public static FVec2 Normalize(FVec2 v)
 {
     return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y)));
 }
Example #11
0
 public Fix64 Magnitude()
 {
     return(Fix64.Sqrt(this.x * this.x + this.y * this.y));
 }
Example #12
0
 public static FVec3 Normalize(FVec3 v)
 {
     return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z)));
 }
Example #13
0
 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)));
 }
Example #14
0
 public Fix64 Magnitude()
 {
     return(Fix64.Sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w));
 }