예제 #1
0
            public static Vector3[] rotate(Vector3[] to_rotate, double angle, char axis)
            {
                Vector3[] rotated = new Vector3[to_rotate.Length];
                MyMatrix4 mat     = MyMatrix4.getSingleRotationMatrix(angle, axis);

                for (int i = 0; i < to_rotate.Length; i++)
                {
                    rotated[i] = mat * to_rotate[i];
                }

                return(rotated);
            }
예제 #2
0
            public static Vector3 rotate(Vector3 to_rotate, double angle, char axis)
            {
                MyMatrix4 mat = MyMatrix4.getSingleRotationMatrix(angle, axis);

                return(mat * to_rotate);
            }
예제 #3
0
        private int createBentPipe(SceneBrep scene, Matrix4 m, Vector3 v1, Vector3 v2, Vector3 v3)
        {
            Vector3[] centers    = new Vector3[bdetail];
            Vector3   oned       = (v1 - v2) * size;
            Vector3   twod       = (v3 - v2) * size;
            Vector3   rtwod      = (v3 - v2) * (1 - size);
            Vector3   rot_point  = v2 + oned + twod;
            Vector3   test_point = oned + twod;

            test_point.X = Math.Abs(test_point.X);
            test_point.Y = Math.Abs(test_point.Y);
            test_point.Z = Math.Abs(test_point.Z);
            double angle = -(Math.PI / 2) / (bdetail - 1);
            char   axis;

            if (test_point.Y < test_point.X)
            {
                axis = (test_point.Z < test_point.Y) ? 'z' : 'y';
            }
            else
            {
                axis = (test_point.Z < test_point.X) ? 'z' : 'x';
            }

            MyMatrix4 mat = MyMatrix4.getSingleRotationMatrix(angle, axis);
            float     l   = longestSide(last_circle[0] - v1);
            Vector3   sp  = rotateAroundPoint(last_circle[0], rot_point, mat);
            float     l2  = longestSide(sp - v1);

            if (l2 < l)
            {
                mat = MyMatrix4.getSingleRotationMatrix(-angle, axis);
            }
            Vector3[] field = new Vector3[bdetail * cdetail];
            Array.Copy(last_circle, field, cdetail);
            centers[0] = getCenter(last_circle);
            Vector3[] new_circle = new Vector3[cdetail];

            for (int i = 1; i < bdetail; i++)
            {
                Array.ConstrainedCopy(field, (i - 1) * cdetail, new_circle, 0, cdetail);
                new_circle = rotateAroundPoint(new_circle, rot_point, mat);
                Array.ConstrainedCopy(new_circle, 0, field, i * cdetail, cdetail);
                centers[i] = getCenter(new_circle);
            }

            Array.ConstrainedCopy(field, (bdetail - 1) * cdetail, last_circle, 0, cdetail);
            for (int i = 0; i < cdetail; i++)
            {
                last_circle[i] += rtwod - twod;
            }
            int[] v = new int[field.Length];

            for (int i = 0; i < field.Length; i++)
            {
                v[i] = scene.AddVertex(Vector3.TransformPosition(field[i], m));
                scene.SetNormal(v[i], Vector3.TransformVector(field[i] - centers[i / cdetail], m).Normalized());
                float r = (field[i].X + 1.1f) / 2.5f;
                float g = (field[i].Y + 1.1f) / 2.5f;
                float b = (field[i].Z + 1.1f) / 2.5f;
                scene.SetColor(v[i], new Vector3(r, g, b));
            }

            for (int i = 0; i < cdetail - 1; i++)
            {
                scene.AddTriangle(connect_indices[i], v[i], connect_indices[i + 1]);
                scene.AddTriangle(connect_indices[i + 1], v[i], v[i + 1]);
            }

            scene.AddTriangle(connect_indices[cdetail - 1], v[cdetail - 1], connect_indices[0]);
            scene.AddTriangle(connect_indices[0], v[cdetail - 1], v[0]);

            for (int i = 0; i < (bdetail - 1); i++)
            {
                for (int j = 0; j < cdetail - 1; j++)
                {
                    int a = i * cdetail + j;
                    scene.AddTriangle(v[a], v[a + cdetail], v[a + 1]);
                    scene.AddTriangle(v[a + 1], v[a + cdetail], v[a + cdetail + 1]);
                }
                int b = i * cdetail + cdetail - 1;
                scene.AddTriangle(v[b], v[b + cdetail], v[b - cdetail + 1]);
                scene.AddTriangle(v[b - cdetail + 1], v[b + cdetail], v[b + 1]);
            }
            Array.ConstrainedCopy(v, (bdetail - 1) * cdetail, connect_indices, 0, cdetail);

            return(bdetail * cdetail * 2 + cdetail * 2);
        }