Ejemplo n.º 1
0
        public RealtimeCSG.AABB CalculateBounds(Quaternion rotation, Vector3 gridTangent, Vector3 gridBinormal)
        {
            var bounds = new RealtimeCSG.AABB();

            bounds.Reset();
            var radius = Mathf.Max(RadiusA, RadiusB);
            var point1 = rotation * (vertices[0] + (gridTangent * radius) + (gridBinormal * radius));
            var point2 = rotation * (vertices[0] - (gridTangent * radius) - (gridBinormal * radius));
            var min    = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            var max    = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);

            min.x = Mathf.Min(min.x, point1.x);
            min.y = Mathf.Min(min.y, point1.y);
            min.z = Mathf.Min(min.z, point1.z);

            max.x = Mathf.Max(max.x, point1.x);
            max.y = Mathf.Max(max.y, point1.y);
            max.z = Mathf.Max(max.z, point1.z);

            min.x = Mathf.Min(min.x, point2.x);
            min.y = Mathf.Min(min.y, point2.y);
            min.z = Mathf.Min(min.z, point2.z);

            max.x = Mathf.Max(max.x, point2.x);
            max.y = Mathf.Max(max.y, point2.y);
            max.z = Mathf.Max(max.z, point2.z);

            bounds.Min = min;
            bounds.Max = max;
            return(bounds);
        }
Ejemplo n.º 2
0
        public RealtimeCSG.AABB CalculateBounds(Quaternion rotation, Vector3 gridTangent, Vector3 gridBinormal)
        {
            var bounds = new RealtimeCSG.AABB();

            bounds.Reset();

            for (int i = 0; i < vertices.Length; i++)
            {
                bounds.Extend(rotation * vertices[i]);
            }

            return(bounds);
        }
Ejemplo n.º 3
0
        public RealtimeCSG.AABB CalculateBounds(Quaternion rotation, Vector3 gridTangent, Vector3 gridBinormal)
        {
            var bounds = new RealtimeCSG.AABB();

            bounds.Reset();

            if (vertices != null && vertices.Length == 2)
            {
                Vector3 center           = vertices[0];
                Vector3 corner           = vertices[1];
                Vector3 delta            = corner - center;
                Vector3 projected_width  = Vector3.Project(delta, gridTangent);
                Vector3 projected_length = Vector3.Project(delta, gridBinormal);

                var min = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
                var max = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);

                var point0 = rotation * center;
                var point1 = rotation * (center + projected_width);
                var point2 = rotation * (center + projected_length);
                var point3 = rotation * corner;

                min.x = Mathf.Min(min.x, point0.x); min.y = Mathf.Min(min.y, point0.y); min.z = Mathf.Min(min.z, point0.z);
                max.x = Mathf.Max(max.x, point0.x); max.y = Mathf.Max(max.y, point0.y); max.z = Mathf.Max(max.z, point0.z);

                min.x = Mathf.Min(min.x, point1.x); min.y = Mathf.Min(min.y, point1.y); min.z = Mathf.Min(min.z, point1.z);
                max.x = Mathf.Max(max.x, point1.x); max.y = Mathf.Max(max.y, point1.y); max.z = Mathf.Max(max.z, point1.z);

                min.x = Mathf.Min(min.x, point2.x); min.y = Mathf.Min(min.y, point2.y); min.z = Mathf.Min(min.z, point2.z);
                max.x = Mathf.Max(max.x, point2.x); max.y = Mathf.Max(max.y, point2.y); max.z = Mathf.Max(max.z, point2.z);

                min.x = Mathf.Min(min.x, point3.x); min.y = Mathf.Min(min.y, point3.y); min.z = Mathf.Min(min.z, point3.z);
                max.x = Mathf.Max(max.x, point3.x); max.y = Mathf.Max(max.y, point3.y); max.z = Mathf.Max(max.z, point3.z);

                bounds.Min = min;
                bounds.Max = max;
            }
            return(bounds);
        }
Ejemplo n.º 4
0
        public RealtimeCSG.AABB CalculateBounds(Quaternion rotation, Vector3 gridTangent, Vector3 gridBinormal)
        {
            var bounds = new RealtimeCSG.AABB();

            bounds.Reset();
            var min = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            var max = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);

            for (int i = 0; i < this.VertexLength; i++)
            {
                var pos = rotation * curve.Points[i];

                min.x = Mathf.Min(min.x, pos.x);
                min.y = Mathf.Min(min.y, pos.y);
                min.z = Mathf.Min(min.z, pos.z);

                max.x = Mathf.Max(max.x, pos.x);
                max.y = Mathf.Max(max.y, pos.y);
                max.z = Mathf.Max(max.z, pos.z);
            }
            bounds.Min = min;
            bounds.Max = max;
            return(bounds);
        }