Browse Source

read .OBJ file, second step

tonton th 3 months ago
parent
commit
0b5dd38b58
4 changed files with 43 additions and 3 deletions
  1. 1
    0
      .gitignore
  2. 36
    1
      importobj.c
  3. 1
    1
      tools/Makefile
  4. 5
    1
      tools/read_obj.c

+ 1
- 0
.gitignore View File

@@ -8,4 +8,5 @@ dummy-file
8 8
 
9 9
 tools/covid-19.obj
10 10
 tools/read_obj
11
+tools/xyz
11 12
 

+ 36
- 1
importobj.c View File

@@ -10,16 +10,51 @@
10 10
 
11 11
 #include  "bubulles.h"
12 12
 
13
+extern int		verbosity;
14
+
13 15
 /* --------------------------------------------------------------------- */
14 16
 
17
+#define LINE_SZ 666
18
+
15 19
 int try_to_read_an_OBJ_file(char *fname, int notused)
16 20
 {
17 21
 FILE		*fpin;
22
+char		line[LINE_SZ+1], *cptr;
23
+float		x, y, z;
24
+int		foo;
18 25
 
19 26
 #if DEBUG_LEVEL
20
-fprintf(stderr, ">>> %s ( '%s' %d)\n", fname, notused);
27
+fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused);
21 28
 #endif
22 29
 
30
+if (NULL==(fpin=fopen(fname, "r"))) {
31
+	perror(fname);
32
+	exit(1);
33
+	}
34
+
35
+while(cptr=fgets(line, LINE_SZ, fpin)) {
36
+
37
+	if (verbosity>1) fputs(line, stderr);
38
+
39
+	cptr = strtok(line, " ");
40
+	if (strcmp(cptr, "v"))	continue;
41
+
42
+	cptr = strtok(NULL, " ");
43
+	foo = sscanf(cptr, "%f", &x);
44
+	cptr = strtok(NULL, " ");
45
+	foo = sscanf(cptr, "%f", &y);
46
+	cptr = strtok(NULL, " ");
47
+	foo = sscanf(cptr, "%f", &z);
48
+
49
+	fprintf(stdout, "%16g   %16g   %16g\n", x, y, z);
50
+
51
+	}
52
+
53
+
54
+ 
55
+
56
+fclose(fpin);
57
+
23 58
 return -7800;
24 59
 }
25 60
 

+ 1
- 1
tools/Makefile View File

@@ -2,4 +2,4 @@
2 2
 BBFUNCS = ../libbubulles.a 
3 3
 
4 4
 read_obj:	read_obj.c Makefile ${BBFUNCS}
5
-	gcc -Wall  $< ${BBFUNCS} -o $@
5
+	gcc -Wall -DDEBUG_LEVEL=1  $< ${BBFUNCS} -o $@

+ 5
- 1
tools/read_obj.c View File

@@ -6,6 +6,9 @@
6 6
 #include	<stdlib.h>
7 7
 #include	"../bubulles.h"
8 8
 
9
+int try_to_read_an_OBJ_file(char *fname, int notused);
10
+int	verbosity;
11
+
9 12
 int main(int argc, char *argv[])
10 13
 {
11 14
 int		foo;
@@ -15,8 +18,9 @@ if (2 != argc) {
15 18
 	exit(0);
16 19
 	}
17 20
 
21
+verbosity = 0;
18 22
 
19
-// foo = try_to_read_an_OBJ_file(argv[1], 0);
23
+foo = try_to_read_an_OBJ_file(argv[1], 0);
20 24
 
21 25
 
22 26
 

Loading…
Cancel
Save