コード例 #1
0
ファイル: Torus.cs プロジェクト: Arnyev/MG
        public BoundingBox[] GetBoxes(int divisionsU, int divisionsV)
        {
            var angleRange = new ParameterRange(0, 2 * (float)Math.PI, 0, 2 * (float)Math.PI);

            GetBoundingBoxes(divisionsU, divisionsV, angleRange, out var triangleIndices, out var triangleVertices, out var angleRanges);

            var boundingBoxes = new BoundingBox[divisionsU * divisionsV];

            for (int i = 0; i < triangleIndices.Length; i++)
            {
                boundingBoxes[i] = new BoundingBox(triangleIndices[i], triangleVertices[i], angleRanges[i]);
            }

            return(boundingBoxes);
        }
コード例 #2
0
        public BoundingBox(Triangle[] triangles, ParameterRange range)
        {
            Triangles = triangles;
            MinU      = range.MinU;
            MaxU      = range.MaxU;
            MinV      = range.MinV;
            MaxV      = range.MaxV;

            MaxX = triangles.Max(t => t.MaxX);
            MaxY = triangles.Max(t => t.MaxY);
            MaxZ = triangles.Max(t => t.MaxZ);

            MinX = triangles.Min(t => t.MinX);
            MinY = triangles.Min(t => t.MinY);
            MinZ = triangles.Min(t => t.MinZ);
        }
コード例 #3
0
ファイル: Torus.cs プロジェクト: Arnyev/MG
        private void GetBoundingBoxes(int divisionsU, int divisionsV, ParameterRange parameterRange, out List <TriangleIndices>[] triangleIndices,
                                      out List <Vector3>[] triangleVertices, out ParameterRange[] parameterRanges)
        {
            var angleForMultiplyRadiusU =
                2 * (float)Math.PI / (divisionsU * 2 * (float)Math.PI / (parameterRange.MaxU - parameterRange.MinU));
            var angleForMultiplyRadiusV =
                2 * (float)Math.PI / (divisionsV * 2 * (float)Math.PI / (parameterRange.MaxV - parameterRange.MinV));

            var torusRadius     = TorusRadius;
            var torusRadiusDiff = TorusRadius / (float)Math.Cos(angleForMultiplyRadiusU / 2) - TorusRadius;
            var tubeRadius      = torusRadiusDiff + TubeRadius / (float)Math.Cos(angleForMultiplyRadiusV / 2);

            triangleIndices  = new List <TriangleIndices> [divisionsU * divisionsV];
            triangleVertices = new List <Vector3> [divisionsU * divisionsV];
            parameterRanges  = new ParameterRange[divisionsU * divisionsV];

            var modelMatrix = GetModelMatrix();

            for (int i = 0; i < divisionsU; i++)
            {
                for (int j = 0; j < divisionsV; j++)
                {
                    var startAlpha = parameterRange.MinU + angleForMultiplyRadiusU * i;
                    var endAlpha   = parameterRange.MinU + angleForMultiplyRadiusU * ((i + 1) % divisionsU);
                    var startBeta  = parameterRange.MinV + angleForMultiplyRadiusV * j;
                    var endBeta    = parameterRange.MinV + angleForMultiplyRadiusV * ((j + 1) % divisionsV);

                    parameterRanges[i * divisionsV + j] = new ParameterRange(startAlpha, endAlpha, startBeta, endBeta);

                    var points = new List <Vector3>();

                    for (float u = 0; u <= 1.0f; u += 0.5f)
                    {
                        for (float v = 0; v <= 1.0f; v += 0.5f)
                        {
                            var alpha = startAlpha + u * angleForMultiplyRadiusU;
                            var beta  = startBeta + v * angleForMultiplyRadiusV;
                            var point = GetPoint(alpha, beta, tubeRadius, torusRadius);
                            points.Add(Vector3.Transform(point, modelMatrix));
                        }
                    }

                    triangleIndices[i * divisionsV + j]  = new QuickHull(points).GetMeshIndices();
                    triangleVertices[i * divisionsV + j] = points;
                }
            }
        }
コード例 #4
0
 public BoundingBox(List <TriangleIndices> triangleIndices, List <Vector3> points, ParameterRange range)
     : this(triangleIndices.Select(x => new Triangle(points[x.A], points[x.B], points[x.C])).ToArray(), range)
 {
 }