Exemple #1
0
        public static Vector3 RandomPoint(this CapsuleCollider that)
        {
            float   radius = that.radius;
            float   height = that.height;
            float   num    = 3.14159274f * radius * radius * height;
            float   num2   = 4.18879032f * radius * radius * radius;
            float   num3   = UnityEngine.Random.Range(0f, num + num2);
            Vector3 result;

            if (num3 < num)
            {
                result   = ColliderExtensions.RandomPointInCircle(radius);
                result.z = result.y;
                result.y = UnityEngine.Random.Range(-height * 0.5f, height * 0.5f);
            }
            else
            {
                result = ColliderExtensions.RandomPointInSphere(radius);
                if (result.y < 0f)
                {
                    result.y -= height * 0.5f;
                }
                else
                {
                    result.y += height * 0.5f;
                }
            }
            int direction = that.direction;

            if (direction != 0)
            {
                if (direction == 2)
                {
                    float y = result.y;
                    result.y = result.z;
                    result.z = y;
                }
            }
            else
            {
                float y2 = result.y;
                result.y = result.x;
                result.x = y2;
            }
            return(result);
        }
Exemple #2
0
        private void PrecomputeImprovedDrag()
        {
            MeshCollider meshCollider = (MeshCollider)this._LocalCollider;
            Mesh         sharedMesh   = meshCollider.sharedMesh;

            Vector3[] vertices = sharedMesh.vertices;
            Vector3[] normals  = sharedMesh.normals;
            int[]     indices  = sharedMesh.GetIndices(0);
            int       num      = indices.Length / 3;

            this._DragNormals    = new Vector3[num];
            this._DragVertices   = new Vector3[num * 3];
            this._DragCenters    = new Vector3[num];
            this._DragAreas      = new float[num];
            this._PolygonVolumes = new float[num];
            Vector3 b    = this._LocalCollider.transform.InverseTransformPoint(this._LocalCollider.bounds.center);
            int     num2 = 0;
            int     i    = 0;

            while (i < indices.Length)
            {
                Vector3 vector  = vertices[indices[i]];
                Vector3 vector2 = vertices[indices[i + 1]];
                Vector3 vector3 = vertices[indices[i + 2]];
                this._DragVertices[i]     = vector;
                this._DragVertices[i + 1] = vector2;
                this._DragVertices[i + 2] = vector3;
                this._DragAreas[num2]     = Vector3.Cross(vector2 - vector, vector3 - vector).magnitude * 0.5f;
                this._DragCenters[num2]   = (vector + vector2 + vector3) * 0.333333343f;
                Vector3 a  = normals[indices[i++]];
                Vector3 b2 = normals[indices[i++]];
                Vector3 b3 = normals[indices[i++]];
                this._DragNormals[num2] = (a + b2 + b3) * 0.333333343f;
                Vector3 p  = vector - b;
                Vector3 p2 = vector2 - b;
                Vector3 p3 = vector3 - b;
                this._PolygonVolumes[num2++] = Mathf.Abs(ColliderExtensions.SignedVolumeOfTriangle(p, p2, p3));
            }
            this._ImprovedDragSamples = new WaterSample[num];
        }
Exemple #3
0
        public static float ComputeVolume(this MeshCollider that)
        {
            float num        = 0f;
            Mesh  sharedMesh = that.sharedMesh;

            Vector3[] vertices  = sharedMesh.vertices;
            int[]     triangles = sharedMesh.triangles;
            int       num2      = triangles.Length;
            Vector3   b         = that.transform.InverseTransformPoint(that.bounds.center);
            int       i         = 0;

            while (i < num2)
            {
                Vector3 p  = vertices[triangles[i++]] - b;
                Vector3 p2 = vertices[triangles[i++]] - b;
                Vector3 p3 = vertices[triangles[i++]] - b;
                num += ColliderExtensions.SignedVolumeOfTriangle(p, p2, p3);
            }
            Vector3 lossyScale = that.transform.lossyScale;

            return(Mathf.Abs(num) * lossyScale.x * lossyScale.y * lossyScale.z);
        }
Exemple #4
0
        private void PrecomputeSamples()
        {
            List <Vector3> list      = new List <Vector3>();
            float          num       = 0.5f;
            float          num2      = 1f;
            int            num3      = this._SampleCount * 18;
            Transform      transform = base.transform;
            Vector3        vector;
            Vector3        vector2;

            ColliderExtensions.GetLocalMinMax(this._LocalCollider, out vector, out vector2);
            int num4 = 0;

            while (num4 < 4 && list.Count < num3)
            {
                for (float num5 = num; num5 <= 1f; num5 += num2)
                {
                    for (float num6 = num; num6 <= 1f; num6 += num2)
                    {
                        for (float num7 = num; num7 <= 1f; num7 += num2)
                        {
                            Vector3 vector3 = new Vector3(Mathf.Lerp(vector.x, vector2.x, num5), Mathf.Lerp(vector.y, vector2.y, num6), Mathf.Lerp(vector.z, vector2.z, num7));
                            if (this._LocalCollider.IsPointInside(transform.TransformPoint(vector3)))
                            {
                                list.Add(vector3);
                            }
                        }
                    }
                }
                num2 = num;
                num *= 0.5f;
                num4++;
            }
            this._CachedSamplePositions = list.ToArray();
            this._CachedSampleCount     = this._CachedSamplePositions.Length;
            WaterPhysics.Shuffle <Vector3>(this._CachedSamplePositions);
        }
Exemple #5
0
 public static Vector3 RandomPoint(this SphereCollider that)
 {
     return(ColliderExtensions.RandomPointInSphere(that.radius));
 }