Exemple #1
0
        public override void Transform(Matrix4x4 matrix)
        {
            Matrix4x4.Decompose(matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation);

            m_radius = m_radius * NetMath.Max(scale.X, NetMath.Max(scale.Y, scale.Z));
            m_center = m_center + translation;
        }
Exemple #2
0
        public static SphereCollider Transform(SphereCollider collider, Matrix4x4 matrix)
        {
            SphereCollider result = new SphereCollider();

            Matrix4x4.Decompose(matrix, out Vector3 scale, out Quaternion rotation, out Vector3 translation);

            result.Radius = collider.m_radius * NetMath.Max(scale.X, NetMath.Max(scale.Y, scale.Z));
            result.Center = collider.m_center + translation;

            return(result);
        }
Exemple #3
0
        private bool Intersects(BoxCollider box, out float distance)
        {
            //from Real-Time Rendering
            //The ray is in world spcae

            distance = 0;

            Vector3 d = Vector3.Normalize(m_direction);
            Vector3 p = box.Center - m_position;

            Matrix4x4 m = Matrix4x4.CreateFromQuaternion(box.Rotate);

            Vector3[] axis = new Vector3[3];

            axis[0] = new Vector3(m.M11, m.M12, m.M13);
            axis[1] = new Vector3(m.M21, m.M22, m.M23);
            axis[2] = new Vector3(m.M31, m.M32, m.M33);

            float[] h = new float[3] {
                box.Radius.X, box.Radius.Y, box.Radius.Z
            };

            float tmin = -float.MaxValue;
            float tmax = float.MaxValue;

            for (int i = 0; i < 3; i++)
            {
                Vector3 item   = axis[i];
                float   radius = h[i];

                float e = Vector3.Dot(item, p);
                float f = Vector3.Dot(item, d);

                float t1 = (e + radius) / f;
                float t2 = (e - radius) / f;

                if (t1 > t2)
                {
                    float temp = t1; t1 = t2; t2 = temp;
                }

                tmin = NetMath.Max(tmin, t1);
                tmax = NetMath.Min(tmax, t2);

                if (tmin > tmax)
                {
                    return(false);
                }
                if (tmax < 0)
                {
                    return(false);
                }
            }

            if (tmin > 0)
            {
                distance = tmin;
            }
            else
            {
                distance = tmax;
            }

            return(true);
        }
Exemple #4
0
 public override void Transform(Vector3 translation, Quaternion rotation, Vector3 scale)
 {
     m_radius = m_radius * NetMath.Max(scale.X, NetMath.Max(scale.Y, scale.Z));
     m_center = m_center + translation;
 }