Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        public static FVec3 NormalizeSafe(FVec3 v)
        {
            Fix64 dis = Fix64.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);

            if (dis == Fix64.Zero)
            {
                return(new FVec3());
            }
            return(v * (Fix64.One / dis));
        }
Ejemplo n.º 3
0
        public FVec3 NormalizeSafe()
        {
            Fix64 dis = Fix64.Sqrt(this.x * this.x + this.y * this.y + this.z * this.z);

            if (dis == Fix64.Zero)
            {
                return(new FVec3());
            }
            return(this * (Fix64.One / dis));
        }
Ejemplo n.º 4
0
        public static FVec3 ClampMagnitude(FVec3 v, Fix64 maxLength)
        {
            FVec3 nor          = v;
            Fix64 sqrMagnitude = nor.SqrMagnitude();

            if (sqrMagnitude > (maxLength * maxLength))
            {
                nor = nor * (maxLength / Fix64.Sqrt(sqrMagnitude));
            }
            return(nor);
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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)));
 }
Ejemplo n.º 10
0
 public Fix64 Magnitude()
 {
     return(Fix64.Sqrt(this.x * this.x + this.y * this.y + this.z * this.z));
 }
Ejemplo n.º 11
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)));
 }
Ejemplo n.º 12
0
 public static FVec2 Normalize(FVec2 v)
 {
     return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y)));
 }