⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getobj.cpp

📁 空战游戏flacon源码
💻 CPP
字号:
#include "header.h"

void displayRecord (char *rec);

struct ObjectInfoStruct {
	char	name[256];
	int		namepos;
	int		x, y, z, angle;
	int		flag;
};

ObjectInfoStruct	info;
FILE	*out;

void main (int argc, char *argv[])
{
	char infile[80], outfile[80];

	printf ("\nGetObj v1.0 by Erick Jap\n\n");
	if (argc < 2) {
		puts ("Usage: GetObj fltfile");
		exit (1);
	}
	glConcatFileExtension ((GLbyte *) infile, (GLbyte *) argv[1], (GLbyte *) "FLT");
	glConcatFileExtension ((GLbyte *) outfile, (GLbyte *) argv[1], (GLbyte *) "LST");

	out = fopen (outfile, "w");
	if (!out) {
		printf ("Can not open output file %s\n", outfile);
		exit (1);
	}

	CFileIO myfile;
	if (!myfile.openread (infile)) {
		printf ("Can not open input file %s\n", infile);
		fclose (out);
		exit (1);
	}

	info.flag = info.angle = info.x = info.y = info.z = 0;
	while (!myfile.eof()) {
		char *record = getRecord (myfile);
		if (!record) exit (1);
		swapRecord (record);
		displayRecord (record);
		free (record);
	}
	if (info.flag) {
		fprintf (out, "%-20s\t%8d\t%8d\t%8d\t%3d\n", info.name+info.namepos,info.x, info.y, info.z, info.angle);
	}
	fclose (out);
}

int	vertexsize;
int	vertexno;
int	stackcounter=0, substackcounter=0;
int	polycounter;
void displayRecord (char *rec)
{
	short rectype, reclen;
	short *srec = (short *) rec;

	rectype = *srec++;
	reclen = *srec++;

	switch (rectype) {
		case OPCODE_HEADER:
		case OPCODE_GROUP:
		case OPCODE_OBJECT:
		case OPCODE_BINARY_SEPARATING_PLANE:
		case OPCODE_SHARED_VERTEX_TABLE:
		case OPCODE_VERTEX_COORDINATE:
		case OPCODE_VERTEX_WITH_NORMAL:
		case OPCODE_VERTEX_WITH_UV:
		case OPCODE_VERTEX_WITH_NORMAL_AND_UV:
		case OPCODE_VERTEX_LIST:
		case OPCODE_POLYGON:
		case OPCODE_COLOR_TABLE:
		case OPCODE_MATERIAL_TABLE:
		case OPCODE_PUSH_LEVEL:
		case OPCODE_POP_LEVEL:
		case OPCODE_PUSH_SUBFACE:
		case OPCODE_POP_SUBFACE:
		case OPCODE_LONG_IDENTIFIER:
		case OPCODE_TEXTURE_REFERENCE_RECORD:
		case OPCODE_PUT_TRANSFORM:
			break;

		case OPCODE_TRANSFORMATION_MATRIX:
			{
			flt_TransformationMatrixRecord *trec = (flt_TransformationMatrixRecord *) rec;
			float	x, y;
			x = trec -> matrix[1];
			y = trec -> matrix[5];
			double angle = (atan2 (x, y) * 180.0/3.141592654);
			if (angle >= 0.0) info.angle = (int) (angle + 0.5);
			else info.angle = (int) (angle - 0.5);
			if (trec -> matrix[12] >= 0.0f)
				info.x = (int) (trec -> matrix[12]+0.5f);
			else info.x = (int) (trec -> matrix[12]-0.5f);
			if (trec -> matrix[13] >= 0.0f)
				info.y = (int) (trec -> matrix[13]+0.5f);
			else info.y = (int) (trec -> matrix[13]-0.5f);
			if (trec -> matrix[14] >= 0.0f)
				info.z = (int) (trec -> matrix[14]+0.5f);
			else info.z = (int) (trec -> matrix[14]-0.5f);
			info.flag |= 1;
			break;
			}
		case OPCODE_EXTERNAL_REFERENCE:
			{
				if (info.flag & 2) {
					fprintf (out, "%-20s\t%8d\t%8d\t%8d\t%3d\n", info.name+info.namepos,info.x, info.y, info.z, info.angle);
					info.flag = 0;
				}
				flt_ExternalReferenceRecord *ext = (flt_ExternalReferenceRecord *) rec;
				int i = getUnixFilename (ext -> filename);
				strncpy (info.name, ext -> filename, 255);
				info.namepos = i;
				if (info.flag) {
					fprintf (out, "%-20s\t%8d\t%8d\t%8d\t%3d\n", info.name+info.namepos,info.x, info.y, info.z, info.angle);
					info.flag = 0;
				}
				info.flag |= 2;
				info.angle = info.x = info.y = info.z = 0;
			}
			break;

		default:
//			printf ("\n-----Unsupported Record Type!!!\n");
//			printf ("Record type is ");
//			DisplayUnsupportedType (rectype);
//			printf (" Record len is %d\n", reclen);
			break;
	}
}


/*
void displayRecord (char *rec)
{
	short rectype, reclen;
	short *srec = (short *) rec;

	rectype = *srec++;
	reclen = *srec++;

	switch (rectype) {
		case OPCODE_HEADER:
		case OPCODE_GROUP:
		case OPCODE_OBJECT:
		case OPCODE_BINARY_SEPARATING_PLANE:
		case OPCODE_SHARED_VERTEX_TABLE:
		case OPCODE_VERTEX_COORDINATE:
		case OPCODE_VERTEX_WITH_NORMAL:
		case OPCODE_VERTEX_WITH_UV:
		case OPCODE_VERTEX_WITH_NORMAL_AND_UV:
		case OPCODE_VERTEX_LIST:
		case OPCODE_POLYGON:
		case OPCODE_COLOR_TABLE:
		case OPCODE_MATERIAL_TABLE:
		case OPCODE_PUSH_LEVEL:
		case OPCODE_POP_LEVEL:
		case OPCODE_PUSH_SUBFACE:
		case OPCODE_POP_SUBFACE:
		case OPCODE_LONG_IDENTIFIER:
		case OPCODE_TEXTURE_REFERENCE_RECORD:
		case OPCODE_PUT_TRANSFORM:
			break;

		case OPCODE_TRANSLATE_TRANSFORM:
			{
				flt_TranslateRecord *trec = (flt_TranslateRecord *) rec;
				if (trec -> deltax >= 0.0f)
					info.x = (int) (trec -> deltax+0.5f);
				else info.x = (int) (trec -> deltax-0.5f);
				if (trec -> deltay >= 0.0f)
					info.y = (int) (trec -> deltay+0.5f);
				else info.y = (int) (trec -> deltay-0.5f);
				if (trec -> deltaz >= 0.0f)
					info.z = (int) (trec -> deltaz+0.5f);
				else info.z = (int) (trec -> deltaz-0.5f);
				info.flag |= 1;
			}
			break;
		case OPCODE_ROTATE_ABOUT_POINT_TRANSFORM:
			{
				flt_RotatePointRecord *rot = (flt_RotatePointRecord *) rec;
				info.angle = (int) (rot -> angle);
				info.flag |= 2;
			}
			break;
		case OPCODE_EXTERNAL_REFERENCE:
			{
				if (info.flag & 4) {
					fprintf (out, "%-20s\t%8d\t%8d\t%8d\t%3d\n", info.name+info.namepos,info.x, info.y, info.z, info.angle);
					info.flag = 0;
				}
				flt_ExternalReferenceRecord *ext = (flt_ExternalReferenceRecord *) rec;
				int i = getUnixFilename (ext -> filename);
				strncpy (info.name, ext -> filename, 255);
				info.namepos = i;
				if (info.flag) {
					fprintf (out, "%-20s\t%8d\t%8d\t%8d\t%3d\n", info.name+info.namepos,info.x, info.y, info.z, info.angle);
					info.flag = 0;
				}
				info.flag |= 4;
				info.angle = info.x = info.y = info.z = 0;
			}
			break;

		default:
//			printf ("\n-----Unsupported Record Type!!!\n");
//			printf ("Record type is ");
//			DisplayUnsupportedType (rectype);
//			printf (" Record len is %d\n", reclen);
			break;
	}
}


*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -