public static void Transform(Mesh3D model, Point3D center, int type, double[] rotmatrix)
        {
            //double angleX = 3.1415926f * aX / 180;
            //double angleZ = 3.1415926f * aZ / 180;
            double sinAlpha = Math.Sin(-Math.PI / 2);
            double cosAlpha = Math.Cos(-Math.PI / 2);

            double[] setAxisMatrix;
            switch (type)
            {
            case 1:
                setAxisMatrix = new double[9] {
                    cosAlpha, 0, sinAlpha, 0, 1, 0, -sinAlpha, 0, cosAlpha
                };
                break;

            case 2:
                setAxisMatrix = new double[9] {
                    1, 0, 0, 0, cosAlpha, -sinAlpha, 0, sinAlpha, cosAlpha
                };
                break;

            case 3:
                setAxisMatrix = new double[9] {
                    cosAlpha, -sinAlpha, 0, sinAlpha, cosAlpha, 0, 0, 0, 1
                };
                break;

            default:
                return;
            }

            int nVertNo = model.GetVertexNo();

            for (int i = 0; i < nVertNo; i++)
            {
                Point3D pt1 = model.GetPoint(i);
                // rotate from z-axis

                double x1 = pt1.X * setAxisMatrix[0] + pt1.Y * setAxisMatrix[1] + pt1.Z * setAxisMatrix[2];
                double y1 = pt1.X * setAxisMatrix[3] + pt1.Y * setAxisMatrix[4] + pt1.Z * setAxisMatrix[5];
                double z1 = pt1.X * setAxisMatrix[6] + pt1.Y * setAxisMatrix[7] + pt1.Z * setAxisMatrix[8];

                double x2 = x1 * rotmatrix[0] + y1 * rotmatrix[1] + z1 * rotmatrix[2];
                double y2 = x1 * rotmatrix[3] + y1 * rotmatrix[4] + z1 * rotmatrix[5];
                double z2 = x1 * rotmatrix[6] + y1 * rotmatrix[7] + z1 * rotmatrix[8];
                x2 += center.X;
                y2 += center.Y;
                z2 += center.Z;

                //     x4 += center.X;
                //   y4 += center.Y;
                // z4 += center.Z;

                model.SetPoint(i, x2, y2, z2);
            }
        }
        // transform input point pt1, (rotate "aX, aZ" and move to "center")
        public static void Transform(Mesh3D model, Point3D center, int type)
        {
            double sinAlpha = Math.Sin(Math.PI / 2);
            double cosAlpha = Math.Cos(Math.PI / 2);

            double[] setAxisMatrix;
            switch (type)
            {
            case 1:
                setAxisMatrix = new double[9] {
                    cosAlpha, 0, sinAlpha, 0, 1, 0, -sinAlpha, 0, cosAlpha
                };
                break;

            case 2:
                setAxisMatrix = new double[9] {
                    1, 0, 0, 0, cosAlpha, -sinAlpha, 0, sinAlpha, cosAlpha
                };
                break;

            case 3:
                setAxisMatrix = new double[9] {
                    cosAlpha, -sinAlpha, 0, sinAlpha, cosAlpha, 0, 0, 0, 1
                };
                break;

            default:
                return;
            }

            int nVertNo = model.GetVertexNo();

            for (int i = 0; i < nVertNo; i++)
            {
                Point3D pt1 = model.GetPoint(i);


                double x1 = pt1.X * setAxisMatrix[0] + pt1.Y * setAxisMatrix[1] + pt1.Z * setAxisMatrix[2];
                double y1 = pt1.X * setAxisMatrix[3] + pt1.Y * setAxisMatrix[4] + pt1.Z * setAxisMatrix[5];
                double z1 = pt1.X * setAxisMatrix[6] + pt1.Y * setAxisMatrix[7] + pt1.Z * setAxisMatrix[8];


                x1 += center.X;
                y1 += center.Y;
                z1 += center.Z;



                model.SetPoint(i, x1, y1, z1);
            }
        }
Beispiel #3
0
        // transform input point pt1, (rotate "aX, aZ" and move to "center")
        public static void Transform(Mesh3D model, Point3D center, double aX, double aZ)
        {
            double angleX = 3.1415926f * aX / 180;
            double angleZ = 3.1415926f * aZ / 180;

            int nVertNo = model.GetVertexNo();

            for (int i = 0; i < nVertNo; i++)
            {
                Point3D pt1 = model.GetPoint(i);
                // rotate from z-axis
                double x2 = pt1.X * Math.Cos(angleZ) + pt1.Z * Math.Sin(angleZ);
                double y2 = pt1.Y;
                double z2 = -pt1.X * Math.Sin(angleZ) + pt1.Z * Math.Cos(angleZ);

                double x3 = center.X + x2 * Math.Cos(angleX) - y2 * Math.Sin(angleX);
                double y3 = center.Y + x2 * Math.Sin(angleX) + y2 * Math.Cos(angleX);
                double z3 = center.Z + z2;

                model.SetPoint(i, x3, y3, z3);
            }
        }
Beispiel #4
0
        public static void Transform(Mesh3D model, Point3D center, Double aX, Double aZ)
        {
            var angleX  = 3.1415926 * aX * DegInverse;
            var angleZ  = 3.1415926 * aZ * DegInverse;
            var nVertNo = model.GetVertexNo();

            for (var i = 0; i < nVertNo; i++)
            {
                var pt1 = model.GetPoint(i);

                // rotate from z-axis
                var x2 = pt1.X * Math.Cos(angleZ) + pt1.Z * Math.Sin(angleZ);
                var y2 = pt1.Y;
                var z2 = -pt1.X * Math.Sin(angleZ) + pt1.Z * Math.Cos(angleZ);

                var x3 = center.X + x2 * Math.Cos(angleX) - y2 * Math.Sin(angleX);
                var y3 = center.Y + x2 * Math.Sin(angleX) + y2 * Math.Cos(angleX);
                var z3 = center.Z + z2;

                model.SetPoint(i, x3, y3, z3);
            }
        }
Beispiel #5
0
        // set this ModelVisual3D object from a array of mesh3D objects
        private void SetModel(ArrayList meshs, Material backMaterial)
        {
            int nMeshNo = meshs.Count;

            if (nMeshNo == 0)
            {
                return;
            }

            MeshGeometry3D triangleMesh = new MeshGeometry3D();
            int            nTotalVertNo = 0;

            for (int j = 0; j < nMeshNo; j++)
            {
                Mesh3D mesh    = (Mesh3D)meshs[j];
                int    nVertNo = mesh.GetVertexNo();
                int    nTriNo  = mesh.GetTriangleNo();
                if ((nVertNo <= 0) || (nTriNo <= 0))
                {
                    continue;
                }

                double[] vx = new double[nVertNo];
                double[] vy = new double[nVertNo];
                double[] vz = new double[nVertNo];
                for (int i = 0; i < nVertNo; i++)
                {
                    vx[i] = vy[i] = vz[i] = 0;
                }

                // get normal of each vertex
                for (int i = 0; i < nTriNo; i++)
                {
                    Triangle3D tri = mesh.GetTriangle(i);
                    Vector3D   vN  = mesh.GetTriangleNormal(i);
                    int        n0  = tri.n0;
                    int        n1  = tri.n1;
                    int        n2  = tri.n2;

                    vx[n0] += vN.X;
                    vy[n0] += vN.Y;
                    vz[n0] += vN.Z;
                    vx[n1] += vN.X;
                    vy[n1] += vN.Y;
                    vz[n1] += vN.Z;
                    vx[n2] += vN.X;
                    vy[n2] += vN.Y;
                    vz[n2] += vN.Z;
                }
                for (int i = 0; i < nVertNo; i++)
                {
                    double length = Math.Sqrt(vx[i] * vx[i] + vy[i] * vy[i] + vz[i] * vz[i]);
                    if (length > 1e-20)
                    {
                        vx[i] /= length;
                        vy[i] /= length;
                        vz[i] /= length;
                    }
                    triangleMesh.Positions.Add(mesh.GetPoint(i));
                    Color color = mesh.GetColor(i);
                    Point mapPt = m_mapping.GetMappingPosition(color);
                    triangleMesh.TextureCoordinates.Add(new System.Windows.Point(mapPt.X, mapPt.Y));
                    triangleMesh.Normals.Add(new Vector3D(vx[i], vy[i], vz[i]));
                }

                for (int i = 0; i < nTriNo; i++)
                {
                    Triangle3D tri = mesh.GetTriangle(i);
                    int        n0  = tri.n0;
                    int        n1  = tri.n1;
                    int        n2  = tri.n2;

                    triangleMesh.TriangleIndices.Add(nTotalVertNo + n0);
                    triangleMesh.TriangleIndices.Add(nTotalVertNo + n1);
                    triangleMesh.TriangleIndices.Add(nTotalVertNo + n2);
                }
                nTotalVertNo += nVertNo;
            }
            //Material material = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
            Material material = m_mapping.m_material;

            GeometryModel3D triangleModel = new GeometryModel3D(triangleMesh, material);

            triangleModel.Transform = new Transform3DGroup();
            if (backMaterial != null)
            {
                triangleModel.BackMaterial = backMaterial;
            }

            Content = triangleModel;
        }