Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

werdy666

File Output question

This topic is 6156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!