public static object procesarMatriz(string sJson) { Matriz3D objMatriz3D = null; string sMensaje = string.Empty; bool bError = false; List <Matriz3D> lstMatriz3D = new List <Matriz3D>(); try { //Se crea una lista de la clase Matriz3D con base a la infomación serializada en formato Json lstMatriz3D = JsonConvert.DeserializeObject <List <Matriz3D> >(sJson); for (int i = 0; i < lstMatriz3D.Count; i++) { objMatriz3D = lstMatriz3D[i]; objMatriz3D.ejecutarOperaciones(); //Se ejecuta el metodo que realiza todas las operaciones } } catch (Exception ex) { bError = true; sMensaje = "Error en procesarMatriz():\n" + ex.Message; } //JsonConvert.SerializeObject(objectPaquete.Datos), sFiltro = sKey }; return(new { Result = JsonConvert.SerializeObject(lstMatriz3D), bError = bError, sMensaje = sMensaje }); }
public void geraCoordCartesianas(Matriz3D matriz) { float[] resultado = matriz.multiplicaVector(new float[4] { this.x, this.y, this.z, this.w }); this.x = resultado[0] / resultado[3]; this.y = resultado[1] / resultado[3]; this.z = resultado[2];// não dividimos para preservar a informação sobre Z this.w = 1.0f; }
public void geraCoordHomogeneas(Matriz3D matriz) { float[] resultado = matriz.multiplicaVector(new float[4] { this.x, this.y, this.z, this.w }); this.x = resultado[0]; this.y = resultado[1]; this.z = resultado[2]; this.w = resultado[3]; }
public ArrayList transforma(float translacaoX, float translacaoY, float translacaoZ, float rotX, float rotY, float rotZ) { ArrayList res = new ArrayList(vertices.Count); int distancia = 400; //cria uma cópia dos vértices originais foreach (Vector3D p in this.vertices) { res.Add(p.Clone()); } // Matriz3D mTrans = Matriz3D.translacao(translacaoX,translacaoY,translacaoz);//construir a matriz translaçao // Matriz3D mProjParalela = Matriz3D.projParalela(); Matriz3D mTrans = Matriz3D.translacao(translacaoX, translacaoY, translacaoZ); Matriz3D mProjParalela = Matriz3D.projParalela(); Matriz3D mProjPerspetiva = Matriz3D.projPerspectiva(distancia);//a câmara está em z=400 Matriz3D rot_X = Matriz3D.rotacaoX(rotX); Matriz3D rot_Y = Matriz3D.rotacaoY(rotY); Matriz3D rot_Z = Matriz3D.rotacaoZ(rotZ); rot_X.printmatriz(); rot_Y.printmatriz(); rot_Z.printmatriz(); for (int i = 0; i < res.Count; i++) { Vector3D p = (Vector3D)res[i]; p.geraCoordHomogeneas(mTrans); p.geraCoordHomogeneas(rot_X); p.geraCoordHomogeneas(rot_Y); p.geraCoordHomogeneas(rot_Z); if (perspetiva) { p.geraCoordCartesianas(mProjPerspetiva); } else { p.geraCoordCartesianas(mProjParalela); } } return(res); }