Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "T3D.h"
- #define t 1
- struct mat4x1
- {
- double Coord[4];
- struct mat4x1 *next;
- };
- struct mat4x4
- {
- double Mat_transf[4][4];
- };
- void Append(double x, double y, double z, double t, int qnt, Mat4x1 **head){
- Mat4x1 *temp = *head, *prev, *new;
- new = malloc(sizeof(Mat4x1));
- new -> Coord[0] = x;
- new -> Coord[1] = y;
- new -> Coord[2] = z;
- new -> Coord[3] = t;
- new -> qnt = qnt;
- while(temp != NULL){
- prev = temp;
- temp = temp -> next;
- }
- new -> next = prev -> next;
- prev -> next = new;
- }
- void Cria(Mat4x1 *Obj, char* fName)
- {
- Mat 4x1 *buffer;
- int i, qnt;
- double x,y,z;
- FILE* arq;
- buffer = malloc(sizeof(Mat4x1));
- arq = fopen(fName,"r");
- if (arq == NULL) //Módulo de segurança
- return NULL;
- fscanf(arq, "%d", &qnt); //numero de v[4] da matriz
- //Criando a matriz
- while(qnt--){
- fscanf(arq, "%lf%lf%lf", &x,&y,&z);
- Append(x,y,z,t,qnt,&buffer);
- }
- fclose(arq);
- }
- void Imprime(Mat4x1 *Obj, char* fName)
- {
- int i, qnt = 0;
- FILE *arq;
- Mat4x1 *temp;
- temp = Obj;
- temp = temp -> next;
- while(temp != NULL){
- ++qnt;
- temp = temp -> next;
- }
- arq = fopen(fName,"w");
- fprintf(arq, "%d\n", qnt);
- temp = Obj;
- temp = temp -> next;
- while(temp != NULL){
- fprintf(arq,"%.3lf %.3lf %.3lf\n", temp->Coord[0],temp->Coord[1],temp->Coord[2]);
- temp = temp -> next;
- }
- fclose(arq);
- }
Add Comment
Please, Sign In to add comment