File Output question

Started by
2 comments, last by werdy666 22 years, 2 months ago
Hi, I was hoping someone could help me. I read in a unreal *.t3d map file and read all the vertex information from it, then write to a new file with only the vertex information. I have set it up to also count how many polygons are in the map file. But I want to put in my new file something like "Number of Polygons : 6". So after writing to my file with the vertex information, how can I go back to the start and insert the number of polygons into the file? Another question is can someone give me some tips on converting the 4 sided polygon information in these t3d files to 2 triangles instead of 1 polygon/quad. Here is my source so far. P.S. Yes I am very much a beginner...
    
#include "stdafx.h"

#include <stdio.h>

int num_of_vertex = 0;
int num_of_polygon = 0;
int polygonsides = 0;

char line[500];

FILE  *txt_file;
FILE  *write_file;

int main(void)
{
	txt_file = fopen("test.t3d", "r");
	write_file = fopen("myconvertedmap.txt", "w");

	if (txt_file == NULL)
	{
		printf("Unable to load data file!\n");
		return -1;
	}
	while(!feof(txt_file))  
	{ 
	fgets(line, 500, txt_file);
	float x = 0, y = 0, z = 0;
		if(sscanf(line,"Vertex %f,%f,%f", &x, &y, &z) == 3)
		{
				if(polygonsides==0)
				{
				num_of_polygon++;
				fprintf(write_file, "\nPolygon : %d\n",num_of_polygon);
				}
			polygonsides++;
			fprintf(write_file, "Vertex %f,%f,%f\n", x, y, z); 
		
			if (polygonsides==4)
			{
				polygonsides=0;
			}
		}
	}
		fclose(txt_file);
		fclose(write_file);
		return 0;
}
    
Werdy666 :D Edited by - werdy666 on February 2, 2002 9:27:58 AM
Advertisement
Hi,

I''m working too on a T3D converter.

On my site, you''ll find the last version (0.5) of my program.
You''ll see soon that reading and converting a T3D file is hard ...

There''re many things to keep for correctly loading a T3D file in your engine.

I''m using the 0.6 version for my program and I''m very happy with the result.

Now, I can load a T3D map.

Here''s a map made under UnrealEd 2.0 and my engine can load the same.



If you have any question, don''t hesitate ...





========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Oups, sorry, your questions ...

- In my program I use 3 files :
- Temp file for vertex
- Temp file for textures
- Temp file for informations (number of polys, textures)
After I read the 3 files and I write them in a more simple format to use.

And for you, you can use this :

rewind(your_file) ==> Not tested





- And for tranforming a quad in 2 triangles, no idea. Search a splitting algoritme (not sure)

========================
Leyder Dylan
http://ibelgique.ifrance.com/Slug-Production/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Splitting a quad in 2 tris is simple if the vertices are stored in order (clockwise or counterclockwise) :

quad : ABCD ====> tri 1 : ABC ,tri 2 : ADC


A------------B
|00000000000|
|00000000000|
D------------C


In your mind draw a line between B and D

(don't mind the 0's, using spaces doesn't seem to get the vertical lines right)



Edited by - George2 on February 4, 2002 7:32:17 AM

Edited by - George2 on February 4, 2002 7:32:59 AM
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon

This topic is closed to new replies.

Advertisement