raaaaaaa
This commit is contained in:
		
							parent
							
								
									777140f625
								
							
						
					
					
						commit
						7f9cd7ef7c
					
				
					 4 changed files with 37 additions and 4 deletions
				
			
		
							
								
								
									
										2
									
								
								c3d.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								c3d.c
									
										
									
									
									
								
							|  | @ -488,7 +488,7 @@ int main() { | ||||||
|     bool run3d = true; |     bool run3d = true; | ||||||
| 
 | 
 | ||||||
|     if (true) { |     if (true) { | ||||||
|         Object3D t = ReadObjectFromFile("teapot.obj"); |         Object3D t = ReadObjectFromFile("mario.obj"); | ||||||
|         for (int i = 0; i < t.triangles->length; i++) { |         for (int i = 0; i < t.triangles->length; i++) { | ||||||
|             // printf("t: %f\n", t.triangles->arr[i].a.x);
 |             // printf("t: %f\n", t.triangles->arr[i].a.x);
 | ||||||
|             TriArrayAppend(&tarr, t.triangles->arr[i]); |             TriArrayAppend(&tarr, t.triangles->arr[i]); | ||||||
|  |  | ||||||
							
								
								
									
										19
									
								
								c3dtypes.h
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								c3dtypes.h
									
										
									
									
									
								
							|  | @ -22,7 +22,19 @@ struct Tri { | ||||||
|     Vector3 c; |     Vector3 c; | ||||||
| 
 | 
 | ||||||
|     Color color; |     Color color; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	Vector2 auv; | ||||||
|  | 	Vector2 buv; | ||||||
|  | 	Vector2 cuv; | ||||||
|  | 	 | ||||||
| }; | }; | ||||||
|  | 
 | ||||||
|  | struct Mat { | ||||||
|  | 	char * name; | ||||||
|  | 	char * file; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| typedef struct Tri Tri; | typedef struct Tri Tri; | ||||||
| 
 | 
 | ||||||
| struct Tri2D { | struct Tri2D { | ||||||
|  | @ -30,11 +42,18 @@ struct Tri2D { | ||||||
|     Vector2 b; |     Vector2 b; | ||||||
|     Vector2 c; |     Vector2 c; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 	float adepth; | 	float adepth; | ||||||
| 	float bdepth; | 	float bdepth; | ||||||
| 	float cdepth; | 	float cdepth; | ||||||
| 
 | 
 | ||||||
|     Color color; |     Color color; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 	Vector2 auv; | ||||||
|  | 	Vector2 buv; | ||||||
|  | 	Vector2 cuv; | ||||||
| }; | }; | ||||||
| typedef struct Tri2D Tri2D; | typedef struct Tri2D Tri2D; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										18
									
								
								reader.c
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								reader.c
									
										
									
									
									
								
							|  | @ -9,6 +9,15 @@ int TestFunc(int x) { | ||||||
|     return x; |     return x; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | Vector3 BreakDownObjTriElement(char * vert) { | ||||||
|  | 	int vertex = 0; | ||||||
|  | 	int vertextexture = 0; | ||||||
|  | 	int normal = 0; | ||||||
|  | 
 | ||||||
|  | 	sscanf(vert, "%i/%i/%i", &vertex, &vertextexture, &normal); | ||||||
|  | 	return (Vector3) {vertex, vertextexture, normal}; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| Object3D ReadObjectFromFile(char * fname) { | Object3D ReadObjectFromFile(char * fname) { | ||||||
|     Object3D out; |     Object3D out; | ||||||
|     Vector3 *VertexArray = malloc(10000 * sizeof(Vector3)); |     Vector3 *VertexArray = malloc(10000 * sizeof(Vector3)); | ||||||
|  | @ -41,6 +50,9 @@ Object3D ReadObjectFromFile(char * fname) { | ||||||
|             VertexArray[VertexArrayLength].y = atof(v2)*100; |             VertexArray[VertexArrayLength].y = atof(v2)*100; | ||||||
|             VertexArray[VertexArrayLength].z = atof(v3)*100; |             VertexArray[VertexArrayLength].z = atof(v3)*100; | ||||||
|             VertexArrayLength = VertexArrayLength + 1; |             VertexArrayLength = VertexArrayLength + 1; | ||||||
|  |         } | ||||||
|  | 		if (strcmp(objtype, "vt") == 0) { | ||||||
|  | 
 | ||||||
| 		} | 		} | ||||||
|         if (strcmp(objtype, "f") == 0 ) { |         if (strcmp(objtype, "f") == 0 ) { | ||||||
|             // TODO: append face to triarry
 |             // TODO: append face to triarry
 | ||||||
|  | @ -51,15 +63,15 @@ Object3D ReadObjectFromFile(char * fname) { | ||||||
|             temptri.b = VertexArray[ atoi(v2) - 1]; |             temptri.b = VertexArray[ atoi(v2) - 1]; | ||||||
|             temptri.c = VertexArray[ atoi(v3) - 1]; |             temptri.c = VertexArray[ atoi(v3) - 1]; | ||||||
| 
 | 
 | ||||||
| 			printf("OLINE: %s\n", t); | 			//printf("OLINE: %s\n", t);
 | ||||||
| 			printf("adding tri A: %d, B: %d, C: %d\n", atoi(v1), atoi(v2) , atoi(v3) ); | 			//printf("adding tri A: %d, B: %d, C: %d\n", atoi(v1), atoi(v2) , atoi(v3) );
 | ||||||
| 			 | 			 | ||||||
| 			temptri.color = GREEN; | 			temptri.color = GREEN; | ||||||
| 			TriArrayAppend(&tarr, temptri); | 			TriArrayAppend(&tarr, temptri); | ||||||
|         } |         } | ||||||
|         // need to bring in triarray functions into their own file
 |         // need to bring in triarray functions into their own file
 | ||||||
|     } |     } | ||||||
| 
 | 	printf("Loaded model %s with %d tris\n", fname, tarr.length); | ||||||
| 	return out; | 	return out; | ||||||
| 
 | 
 | ||||||
|     // TODO: use file object and read each line
 |     // TODO: use file object and read each line
 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								reader.h
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								reader.h
									
										
									
									
									
								
							|  | @ -4,4 +4,6 @@ | ||||||
| 
 | 
 | ||||||
| int TestFunc(int x); | int TestFunc(int x); | ||||||
| Object3D ReadObjectFromFile(char * fname); | Object3D ReadObjectFromFile(char * fname); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue