コード例 #1
0
ファイル: SBSMatrix4x4.cs プロジェクト: AlinaEcke/2DCityQuest
        public bool InvertFast()
        {
            float ood = this.determinant;

            if (SBSMath.Abs(ood) < SBSMath.Epsilon)
            {
                return(false);
            }
            ood = 1.0f / ood;

            float _m00 = ood * (m11 * m22 - m12 * m21);
            float _m01 = ood * (m21 * m02 - m22 * m01);
            float _m02 = ood * (m01 * m12 - m02 * m11);
            float _m03 = 0.0f;
            float _m10 = ood * (m12 * m20 - m10 * m22);
            float _m11 = ood * (m22 * m00 - m20 * m02);
            float _m12 = ood * (m02 * m10 - m00 * m12);
            float _m13 = 0.0f;
            float _m20 = ood * (m10 * m21 - m11 * m20);
            float _m21 = ood * (m20 * m01 - m21 * m00);
            float _m22 = ood * (m00 * m11 - m01 * m10);
            float _m23 = 0.0f;
            float _m30 = ood * (m10 * (m22 * m31 - m21 * m32) + m11 * (m20 * m32 - m22 * m30) + m12 * (m21 * m30 - m20 * m31));
            float _m31 = ood * (m20 * (m02 * m31 - m01 * m32) + m21 * (m00 * m32 - m02 * m30) + m22 * (m01 * m30 - m00 * m31));
            float _m32 = ood * (m30 * (m02 * m11 - m01 * m12) + m31 * (m00 * m12 - m02 * m10) + m32 * (m01 * m10 - m00 * m11));
            float _m33 = 1.0f;

            m00 = _m00; m01 = _m01; m02 = _m02; m03 = _m03;
            m10 = _m10; m11 = _m11; m12 = _m12; m13 = _m13;
            m20 = _m20; m21 = _m21; m22 = _m22; m23 = _m23;
            m30 = _m30; m31 = _m31; m32 = _m32; m33 = _m33;

            return(true);
        }
コード例 #2
0
ファイル: SBSVector3.cs プロジェクト: AlinaEcke/2DCityQuest
        public static float Distance(SBSVector3 v0, SBSVector3 v1)
        {
            float dx = v1.x - v0.x;
            float dy = v1.y - v0.y;
            float dz = v1.z - v0.z;
            float dd = dx * dx + dy * dy + dz * dz;

            return(SBSMath.Sqrt(dd));
        }
コード例 #3
0
        public static SBSQuaternion AngleAxis(float angle, SBSVector3 axis)
        {
            angle *= (SBSMath.ToRadians * 0.5f);
            SBSVector3 a = axis.normalized;
            float      s = SBSMath.Sin(angle),
                       c = SBSMath.Cos(angle);

            return(new SBSQuaternion(a.x * s, a.y * s, a.z * s, c));
        }
コード例 #4
0
        public void Encapsulate(SBSBounds bounds)
        {
            min.x = SBSMath.Min(min.x, bounds.min.x);
            min.y = SBSMath.Min(min.y, bounds.min.y);
            min.z = SBSMath.Min(min.z, bounds.min.z);

            max.x = SBSMath.Max(max.x, bounds.max.x);
            max.y = SBSMath.Max(max.y, bounds.max.y);
            max.z = SBSMath.Max(max.z, bounds.max.z);
        }
コード例 #5
0
        public void Encapsulate(float px, float py, float pz)
        {
            min.x = SBSMath.Min(min.x, px);
            min.y = SBSMath.Min(min.y, py);
            min.z = SBSMath.Min(min.z, pz);

            max.x = SBSMath.Max(max.x, px);
            max.y = SBSMath.Max(max.y, py);
            max.z = SBSMath.Max(max.z, pz);
        }
コード例 #6
0
        public void SetAngleAxis(float angle, SBSVector3 axis)
        {
            angle *= (SBSMath.ToRadians * 0.5f);
            SBSVector3 a = axis.normalized;
            float      s = SBSMath.Sin(angle),
                       c = SBSMath.Cos(angle);

            x = a.x * s;
            y = a.y * s;
            z = a.z * s;
            w = c;
        }
コード例 #7
0
        public void Encapsulate(SBSVector3 p)
        {
            float px = p.x, py = p.y, pz = p.z;

            min.x = SBSMath.Min(min.x, px);
            min.y = SBSMath.Min(min.y, py);
            min.z = SBSMath.Min(min.z, pz);

            max.x = SBSMath.Max(max.x, px);
            max.y = SBSMath.Max(max.y, py);
            max.z = SBSMath.Max(max.z, pz);
        }
コード例 #8
0
        public static SBSQuaternion Slerp(SBSQuaternion q0, SBSQuaternion q1, float t)
        {
            float w1 = q0.w, x1 = q0.x, y1 = q0.y, z1 = q0.z,
                  w2 = q1.w, x2 = q1.x, y2 = q1.y, z2 = q1.z,
                  dot = w1 * w2 + x1 * x2 + y1 * y2 + z1 * z2;

            if (dot < 0.0f)
            {
                dot = -dot;
                w2  = -w2;
                x2  = -x2;
                y2  = -y2;
                z2  = -z2;
            }

            if (dot < 0.95f)
            {
                float angle = SBSMath.Acos(dot),
                      s     = 1.0f / SBSMath.Sin(angle),
                      s1    = SBSMath.Sin(angle * (1.0f - t)) * s,
                      s2    = SBSMath.Sin(angle * t) * s;

                w1 = w1 * s1 + w2 * s2;
                x1 = x1 * s1 + x2 * s2;
                y1 = y1 * s1 + y2 * s2;
                z1 = z1 * s1 + z2 * s2;
            }
            else
            {
                w1 += t * (w2 - w1);
                x1 += t * (x2 - x1);
                y1 += t * (y2 - y1);
                z1 += t * (z2 - z1);

                float oom = x1 * x1 + y1 * y1 + z1 * z1 + w1 * w1;
                if (oom < SBSMath.SqrEpsilon)
                {
                    return(new SBSQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
                }

                oom = 1.0f / SBSMath.Sqrt(oom);

                x1 *= oom;
                y1 *= oom;
                z1 *= oom;
                w1 *= oom;
            }

            return(new SBSQuaternion(x1, y1, z1, w1));
        }
コード例 #9
0
        public void Normalize()
        {
            float oom = x * x + y * y + z * z + w * w;

            if (oom < SBSMath.SqrEpsilon)
            {
                x = 0.0f;
                y = 0.0f;
                z = 0.0f;
                w = 1.0f;
                return;
            }
            oom = 1.0f / SBSMath.Sqrt(oom);
            x  *= oom;
            y  *= oom;
            z  *= oom;
            w  *= oom;
        }
コード例 #10
0
        public static SBSQuaternion LookRotation(SBSVector3 forward, SBSVector3 up)
        {
#if UNITY_FLASH
            forward = forward.normalized;
#else
            forward.Normalize();
#endif
            SBSVector3 right = SBSVector3.Cross(up.normalized, forward).normalized;
            up = SBSVector3.Cross(forward, right);

            float w    = SBSMath.Sqrt(1.0f + right.x + up.y + forward.z) * 0.5f,
                  oo4w = 1.0f / (4.0f * w),
                  x    = (forward.y - up.z) * oo4w,
                  y    = (right.z - forward.x) * oo4w,
                  z    = (up.x - right.y) * oo4w;

            return(new SBSQuaternion(x, y, z, w));
        }
コード例 #11
0
ファイル: SBSVector3.cs プロジェクト: AlinaEcke/2DCityQuest
        public float Normalize()
        {
            float m = x * x + y * y + z * z;

            if (m < SBSMath.SqrEpsilon)
            {
                return(0.0f);
            }

            m = SBSMath.Sqrt(m);
            float oom = 1.0f / m;

            x *= oom;
            y *= oom;
            z *= oom;

            return(m);
        }
コード例 #12
0
        public static void Slerp(SBSQuaternion q0, SBSQuaternion q1, float t, out SBSQuaternion o)
#endif
        {
            float w1 = q0.w, x1 = q0.x, y1 = q0.y, z1 = q0.z,
                  w2 = q1.w, x2 = q1.x, y2 = q1.y, z2 = q1.z,
                  dot = w1 * w2 + x1 * x2 + y1 * y2 + z1 * z2;

            if (dot < 0.0f)
            {
                dot = -dot;
                w2  = -w2;
                x2  = -x2;
                y2  = -y2;
                z2  = -z2;
            }

            if (dot < 0.95f)
            {
                float angle = SBSMath.Acos(dot),
                      s     = 1.0f / SBSMath.Sin(angle),
                      s1    = SBSMath.Sin(angle * (1.0f - t)) * s,
                      s2    = SBSMath.Sin(angle * t) * s;

                o.w = w1 * s1 + w2 * s2;
                o.x = x1 * s1 + x2 * s2;
                o.y = y1 * s1 + y2 * s2;
                o.z = z1 * s1 + z2 * s2;
            }
            else
            {
                o.w = w1 + t * (w2 - w1);
                o.x = x1 + t * (x2 - x1);
                o.y = y1 + t * (y2 - y1);
                o.z = z1 + t * (z2 - z1);

                o.Normalize();
            }
        }
コード例 #13
0
ファイル: SBSVector3.cs プロジェクト: AlinaEcke/2DCityQuest
 public static float Angle(SBSVector3 v0, SBSVector3 v1)
 {
     return(SBSMath.Acos(SBSVector3.Dot(v0.normalized, v1.normalized)) * SBSMath.ToDegrees);
 }