Beispiel #1
0
 //Structure
 public Pixel4F(float v1, float v2, float v3, float v4)
 {
     this.m_v1 = UMath.Clamp01(v1);
     this.m_v2 = UMath.Clamp01(v2);
     this.m_v3 = UMath.Clamp01(v3);
     this.m_v4 = UMath.Clamp01(v4);
 }
Beispiel #2
0
        public static unsafe Vec4 operator *(Vec4 left, float right)
        {
#if IMOET_UNSAFE
            UMath.MassMultiply((float *)&left, right, 4);
            return(left);
#else
            return(new Vec4(left.x * right, left.y * right, left.z * right, left.w * right));
#endif
        }
Beispiel #3
0
        public static unsafe Vec4 operator /(Vec4 left, float right)
        {
#if IMOET_UNSAFE
            UMath.MassDivided((float *)&left, right, 4);
            return(left);
#else
            return(new Vec4(left.x / right, left.y / right, left.z / right, left.w / right));
#endif
        }
Beispiel #4
0
        //Operator
        public static Matrix4x4 operator +(Matrix4x4 a, Matrix4x4 b)
        {
#if IMOET_UNSAFE
            Matrix4x4 m = new Matrix4x4();
            UMath.MassAdd(a.Ptr, b.Ptr, m.Ptr, 9);
            return(m);
#else
            return(UMath.AddMatrix(a, b));
#endif
        }
Beispiel #5
0
        public static unsafe Vec3 operator *(Vec3 l, float r)
        {
#if IMOET_UNSAFE
            Vec3 res = l;
            UMath.MassMultiply((float *)&res, r, 3);
            return(res);
#else
            return(new Vec3(l.x * r, l.y * r, l.z * r));
#endif
        }
Beispiel #6
0
        public static unsafe Vec4 operator -(Vec4 left, Vec4 right)
        {
#if IMOET_UNSAFE
            var res = default(Vec4);
            UMath.MassAdd((float *)&left, (float *)&right, (float *)&res, 4);
            return(res);
#else
            return(new Vec4(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.z));
#endif
        }
Beispiel #7
0
        //Operator
        public static Matrix3x3 operator +(Matrix3x3 a, Matrix3x3 b)
        {
#if IMOET_UNSAFE
            var m = a;
            UMath.MassAdd(a.Ptr, b.Ptr, m.Ptr, 9);
            return(m);
#else
            return(UMath.AddMatrix(a, b));
#endif
        }
Beispiel #8
0
        public static unsafe Vec3 operator +(Vec3 l, Vec3 r)
        {
#if IMOET_UNSAFE
            Vec3 res = zero;
            UMath.MassAdd((float *)&l, (float *)&r, (float *)&res, 3);
            return(res);
#else
            return(new Vec3(l.x + r.x, l.y + r.y, l.z + r.z));
#endif
        }
Beispiel #9
0
        public static Matrix3x3 operator -(Matrix3x3 a, Matrix3x3 b)
        {
#if IMOET_UNSAFE
            Matrix3x3 m = new Matrix3x3();
            UMath.MassSubtract(a.Ptr, b.Ptr, m.Ptr, 9);
            return(m);
#else
            return(UMath.SubtractMatrix(a, b));
#endif
        }
Beispiel #10
0
        public static unsafe Vec2 operator *(Vec2 a, float d)
        {
#if IMOET_UNSAFE
            Vec2 res = a;
            UMath.MassMultiply((float *)&res, d, 2);
            return(res);
#else
            return(new Vec2(a.x * d, a.y * d));
#endif
        }
Beispiel #11
0
        public static unsafe Vec2 operator -(Vec2 a, Vec2 b)
        {
#if IMOET_UNSAFE
            Vec2 res = zero;
            UMath.MassSubtract((float *)&a, (float *)&b, (float *)&res, 2);
            return(res);
#else
            return(new Vec2(a.x - b.x, a.y - b.y));
#endif
        }
Beispiel #12
0
        public static unsafe Vec3 operator -(Vec3 l, Vec3 r)
        {
#if IMOET_UNSAFE
            Vec3 res = zero;
            UMath.MassSubtract((float *)&l, (float *)&r, (float *)&res, 3);
            return(res);
#else
            return(new Vec3(l.x - r.x, l.y - r.y, l.z - r.z));
#endif
        }
Beispiel #13
0
        public static unsafe Vec2 operator /(Vec2 a, float d)
        {
#if IMOET_UNSAFE
            Vec2 res = a;
            UMath.MassDivided((float *)&a, d, 2);
            return(res);
#else
            return(new Vec2(a.x / d, a.y / d));
#endif
        }
Beispiel #14
0
        public void GetCorner(Vec2[] corner)
        {
            if (corner == null)
            {
                throw new ArgumentNullException("Corner must not null array");
            }
            int count = corner.Length;

            count = (int)UMath.Clamp(count, 0, 4);
            for (int i = 0; i < count; i++)
            {
                corner[0] = new Vec2(x, y);
                corner[1] = new Vec2(x + width, y);
                corner[2] = new Vec2(x, y + height);
                corner[3] = new Vec2(x + width, y + height);
            }
        }
Beispiel #15
0
        public Vec3 Evaluate(float amount, CurveType type)
        {
            if (m_points.Count < 2)
            {
                throw new ArgumentException("Number of CurverPoint is less than 2");
            }
            //Evaluate Point Only At particular time

            //Find Which "Pair" that we want to calculate
            var tr    = 1.0f / (m_points.Count - 1);
            var tIdxF = UMath.LerpPercent(amount - 0.0000001f, 0.0f, tr);
            var tIdx  = (int)UMath.Floor(tIdxF);
            var r     = tIdxF - tIdx;

            //Get Point
            var p0 = m_points[tIdx].point;
            var p1 = m_points[tIdx].handleB;
            var p2 = m_points[tIdx + 1].handleA;
            var p3 = m_points[tIdx + 1].point;

            //Apply calculation
            var u  = 1f - r;
            var u2 = u * u;
            var u3 = u2 * u;

            var r2 = r * r;
            var r3 = r2 * r;

            switch (type)
            {
            case CurveType.Linear:
                return(p0 + (p1 - p0) * r);

            case CurveType.Bezier:
                return(u3 * p0 + (3f * u2 * r) * p1 + (3f * u * r2) * p2 + r3 * p3);

            case CurveType.CatmullRom:
                return(0.5f * (2.0f * p0 + (p3 - p1) * r + (2.0f * p1 - 5.0f * p0 + 4.0f * p3 - p2) * r2 + (-p1 + 3.0f * p0 - 3.0f * p3 + p2) * r3));

            case CurveType.Hermite:
                return((2 * p0 - 2 * p3 + p3 + p1) * r3 + (3 * p3 - 3 * p0 - 2 * p1 - p2) * r2 + p1 * r + p0);

            default:
                throw new ArgumentException("Something Goes Wrong");
            }
        }
Beispiel #16
0
        public static Vec2 SmoothDamp(Vec2 current, Vec2 target, ref Vec2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
        {
            smoothTime = UMath.Max(0.0001f, smoothTime);
            float num       = 2f / smoothTime;
            float num2      = num * deltaTime;
            float d         = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
            Vec2  vector    = current - target;
            Vec2  Vec2      = target;
            float maxLength = maxSpeed * smoothTime;

            vector = ClampMagnitude(vector, maxLength);
            target = current - vector;
            Vec2 vector3 = (currentVelocity + num * vector) * deltaTime;

            currentVelocity = (currentVelocity - num * vector3) * d;
            Vec2 vector4 = target + (vector + vector3) * d;

            if (Dot(Vec2 - current, vector4 - Vec2) > 0f)
            {
                vector4         = Vec2;
                currentVelocity = (vector4 - Vec2) / deltaTime;
            }
            return(vector4);
        }
Beispiel #17
0
 public static Vec2 LerpClamped(Vec2 from, Vec2 to, float t)
 {
     t = UMath.Clamp01(t);
     return(new Vec2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t));
 }
Beispiel #18
0
 public static Matrix3x3 operator -(Matrix3x3 a)
 {
     return(UMath.MultiplyMatrix(a, -1));
 }
Beispiel #19
0
 public static Matrix3x3 operator /(Matrix3x3 a, float b)
 {
     return(UMath.DivideMatrix(a, b));
 }
Beispiel #20
0
 public static Matrix3x3 operator *(Matrix3x3 a, float b)
 {
     return(UMath.MultiplyMatrix(a, b));
 }
Beispiel #21
0
 public static float AngleRad(Vec2 from, Vec3 to)
 {
     return(UMath.Acos(UMath.Clamp(Vec2.Dot(from.normalized, to.normalized), -1f, 1f)));
 }
Beispiel #22
0
 public override int GetHashCode()
 {
     return(UMath.Max(x + y + z, int.MaxValue).GetHashCode());
 }
Beispiel #23
0
 //Structure
 public Pixel3F(float v1, float v2, float v3)
 {
     this.m_v1 = UMath.Clamp01(v1);
     this.m_v2 = UMath.Clamp01(v2);
     this.m_v3 = UMath.Clamp01(v3);
 }
Beispiel #24
0
 public static Matrix4x4 operator *(Matrix4x4 a, Matrix4x4 b)
 {
     return(UMath.MultiplyMatrix(a, b));
 }