File: VWriteObject.c

package info (click to toggle)
acm 5.0-19
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,852 kB
  • ctags: 4,792
  • sloc: ansic: 42,427; makefile: 706; cpp: 293; perl: 280; sh: 198
file content (158 lines) | stat: -rw-r--r-- 4,290 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 *  Copyright (c) 1994, Riley Rainey,  riley@netcon.com
 *
 *  Permission to use, copy, modify and distribute (without charge) this
 *  software, documentation, images, etc. is granted, provided that this 
 *  comment and the author's name is retained.
 *
 *  This software is provided by the author as is, and without any expressed
 *  or implied warranties, including, but not limited to, the implied
 *  warranties of merchantability and fitness for a particular purpose.  In no
 *  event shall the author be liable for any direct, indirect, incidental, or
 *  consequential damages arising in any way out of the use of this software.
 */

#include <Xm/Xm.h>
#include <stdio.h>
#include "gedit.h"

int WriteVFile (name)
char	*name;
{

	int	 i, j, k, points = 0, polygons = 0, error;
	register point_t	*p;
	FILE	*f;
	char	ivname[1024], *p1;

	if ((f = fopen (name, "w")) == (FILE *) NULL) {
		perror ("can't open file");
	}

/*
 *  Total the number of vertices in all of the object's polygons
 */

	for (i=sel_polygon; i >= 0; i = polygon_list[i].next) {
		polygons ++;
		points += polygon_list[i].num_points;
	}

	for (i=unsel_polygon; i >= 0; i = polygon_list[i].next) {
		polygons ++;
		points += polygon_list[i].num_points;
	}

/*
 *  Print the header
 */

	fprintf (f, "%s\n%d %d\n", "object", points, polygons);

/*
 *  Print the point list
 */

	k = 1;

	for (i=sel_polygon; i >= 0; i = polygon_list[i].next) {
		for (j=0; j < polygon_list[i].num_points; ++j) {
			p = &polygon_list[i].point[j];
			fprintf (f, "%d %lg %lg %lg\n", k, p->point.x,
				p->point.y, p->point.z);
			++k;
		}
	}

	for (i=unsel_polygon; i >= 0; i = polygon_list[i].next) {
		for (j=0; j < polygon_list[i].num_points; ++j) {
			p = &polygon_list[i].point[j];
			fprintf (f, "%d %lg %lg %lg\n", k, p->point.x,
				p->point.y, p->point.z);
			++k;
		}
	}


/*
 *  Print the polygon list
 */

	k = 1;

	for (i=sel_polygon; i >= 0; i = polygon_list[i].next) {
		fprintf(f, "%s %d", "gray44", polygon_list[i].num_points);
		for (j=0; j < polygon_list[i].num_points; ++j) {
			fprintf(f, " %d", k++);
		}
		fprintf (f, "\n");
	}

	for (i=unsel_polygon; i >= 0; i = polygon_list[i].next) {
		fprintf(f, "%s %d", "gray44", polygon_list[i].num_points);
		for (j=0; j < polygon_list[i].num_points; ++j) {
			fprintf(f, " %d", k++);
		}
		fprintf (f, "\n");
	}

	error = ferror(f) ? -1 : 0;

	fclose (f);

/*
 *  Now write the aircraft inventory information
 */
 	
	strcpy (ivname, name);
	if ((p1 = strrchr (ivname, '.'))) {
		strcpy (p1, ".inv");
	}
	else {
		strcat (ivname, ".inv");
	}

	if ((f = fopen (ivname, "w")) == (FILE *) NULL) {
	}

	c.viewPoint = marker_list[MARKER_HEAD].location.point;

	fprintf (f, "aircraft \"%s\" {\n\n", c.name);
	fprintf (f, "\tWingArea\t%lg\n", c.wingS);
	fprintf (f, "\tWingHalfSpan\t%lg\n", c.wings);
	fprintf (f, "\tChord\t\t%lg\n", c.c);
	fprintf (f, "\tEmptyWeight\t%lg\n", c.emptyWeight);
	fprintf (f, "\tMaxFuel\t\t%lg\n", c.maxFuel);
	fprintf (f, "\tIxx\t\t%lg\n", c.I.m[0][0]);
	fprintf (f, "\tIyy\t\t%lg\n", c.I.m[1][1]);
	fprintf (f, "\tIzz\t\t%lg\n", c.I.m[2][2]);	
	fprintf (f, "\tRm\t\t{%lg,  %lg,  %lg}\n", c.rm.x, c.rm.y, c.rm.z);
	fprintf (f, "\tRn\t\t{%lg,  %lg,  %lg}\n", c.rn.x, c.rn.y, c.rn.z);
	fprintf (f, "\tKm\t\t%lg\n", c.Km);
	fprintf (f, "\tKn\t\t%lg\n", c.Kn);
	fprintf (f, "\tGm\t\t%lg\n", c.Gm);
	fprintf (f, "\tGn\t\t%lg\n", c.Gn);
	fprintf (f, "\tCmMax\t\t%lg\n", c.cmMax);
	fprintf (f, "\tCnMax\t\t%lg\n", c.cnMax);
	fprintf (f, "\tGroundingPoint\t{0.0, 0.0, %lg}\n", c.groundingPoint.z);
	fprintf (f, "\tViewPoint\t{%lg, %lg, %lg}\n",
		c.viewPoint.x, c.viewPoint.y, c.viewPoint.z);
	fprintf (f, "\n");
	fprintf (f, "\tMaxThrust\t%lg\n", c.maxThrust);
	fprintf (f, "\tMaxABThrust\t%lg\n", c.maxABThrust);
	fprintf (f, "\tSpFuelConsump\t%lg\n", c.spFuelConsump);
	fprintf (f, "\tSpABFuelConsump\t%lg\n", c.spABFuelConsump);
	fprintf (f, "\tEngineLag\t%lg\n", c.engineLag);
	fprintf (f, "\n");
	fprintf (f, "\tClda\t\t%lg\n", c.Clda);
	fprintf (f, "\tCldr\t\t%lg\n", c.Cldr);
	fprintf (f, "\tClp\t\t%lg\n", c.Clp);
	fprintf (f, "\tCmq\t\t%lg\n", c.Cmq);
	fprintf (f, "\tCnr\t\t%lg\n", c.Cnr);
	fprintf (f, "\tCmAlpha\t\t%lg\n", c.cmSlope);
	fprintf (f, "\tCmFactor\t%lg\n", c.cmFactor);
	fprintf (f, "\t}\n");
	fclose (f);

	return error;
}