-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibinf.c
195 lines (168 loc) · 4.89 KB
/
libinf.c
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* libinf.c - general info routines.
*
* Author: Eric Haines
*
* Modified: 1 December 2012 - Support for named textures.
* Fix non-const initialiser.
* Sam [sbt] Thompson
*
*/
/*-----------------------------------------------------------------*/
/* include section */
/*-----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "lib.h"
#include "drv.h"
/*-----------------------------------------------------------------*/
/* defines/constants section */
/*-----------------------------------------------------------------*/
#ifdef OUTPUT_TO_FILE
FILE * gStdout_file = NULL;
#endif /* OUTPUT_TO_FILE */
/*-----------------------------------------------------------------*/
/* Here are some local variables that are used to control things like
the current output file, current texture, ... */
/* MS VC, MinGW and clang complain about non-const initialiser */
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__clang__)
FILE *gOutfile = NULL;
#else
FILE *gOutfile = stdout;
#endif
char *gTexture_name = NULL;
int gTexture_max_count = 0;
int gTexture_count = 0;
int gObject_count = 0;
double gTexture_ior = 1.0;
int gRT_out_format = OUTPUT_NFF;
int gRT_orig_format = OUTPUT_NFF;
int gU_resolution = OUTPUT_RESOLUTION;
int gV_resolution = OUTPUT_RESOLUTION;
COORD3 gBkgnd_color = {0.0, 0.0, 0.0};
COORD3 gFgnd_color = {0.0, 0.0, 0.0};
double gView_bounds[2][3];
int gView_init_flag = 0;
char *gLib_version_str = LIB_VERSION;
surface_ptr gLib_surfaces = NULL;
object_ptr gLib_objects = NULL;
light_ptr gLib_lights = NULL;
viewpoint gViewpoint = {
{0, 0, -10},
{0, 0, 0},
{0, 1, 0},
45, 1, 1.0e-3, 10, 128, 128,
{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }
};
/* Globals for tracking indentation level of output file */
int gTab_width = 4;
int gTab_level = 0;
/*-----------------------------------------------------------------*/
void tab_indent PARAMS((void))
{
int k;
/* Q&D way to do it... */
for (k=0; k<gTab_width*gTab_level; k++)
putc(' ', gOutfile);
} /* tab_printf */
/*-----------------------------------------------------------------*/
void tab_inc PARAMS((void))
{
gTab_level++;
} /* tab_inc */
/*-----------------------------------------------------------------*/
void tab_dec PARAMS((void))
{
gTab_level--;
if (gTab_level < 0)
gTab_level = 0;
} /* tab_dec */
/* Library info functions */
/*-----------------------------------------------------------------*/
char *
lib_get_version_str PARAMS((void))
{
return gLib_version_str;
} /* lib_get_version_str */
/*-----------------------------------------------------------------*/
/*
* Routines to set/reset the various output parameters
*/
/*-----------------------------------------------------------------*/
#ifdef ANSI_FN_DEF
void lib_set_output_file (FILE *new_outfile)
#else
void lib_set_output_file(new_outfile)
FILE *new_outfile;
#endif
{
if (new_outfile == NULL)
gOutfile = stdout;
else
gOutfile = new_outfile;
}
/*-----------------------------------------------------------------*/
#ifdef ANSI_FN_DEF
void lib_set_default_texture (char *default_texture)
#else
void lib_set_default_texture(default_texture)
char *default_texture;
#endif
{
gTexture_name = default_texture;
}
/*-----------------------------------------------------------------*/
#ifdef ANSI_FN_DEF
void lib_set_raytracer(int default_tracer)
#else
void lib_set_raytracer(default_tracer)
int default_tracer;
#endif
{
if (default_tracer < OUTPUT_VIDEO ||
default_tracer > OUTPUT_DELAYED) {
fprintf(stderr, "Unknown renderer index: %d\n", default_tracer);
exit(1);
}
gRT_out_format = default_tracer;
}
/*-----------------------------------------------------------------*/
#ifdef ANSI_FN_DEF
void lib_set_polygonalization(int u_steps, int v_steps)
#else
void lib_set_polygonalization(u_steps, v_steps)
int u_steps, v_steps;
#endif
{
if ((u_steps > 0) && (v_steps > 0)) {
gU_resolution = u_steps;
gV_resolution = v_steps;
}
}
/*-----------------------------------------------------------------*/
#ifdef ANSI_FN_DEF
void lookup_surface_stats(int index, int *tcount, double *tior, char **tname)
#else
void lookup_surface_stats(index, tcount, tior, tname)
int index, *tcount;
double *tior;
char **tname;
#endif
{
surface_ptr temp_ptr = gLib_surfaces;
while (temp_ptr != NULL && (int)temp_ptr->surf_index != index)
temp_ptr = temp_ptr->next;
if (temp_ptr != NULL) {
*tior = temp_ptr->ior;
if (*tior < 1.0) *tior = 1.0;
*tcount = temp_ptr->surf_index;
*tname = temp_ptr->surf_name;
}
else {
*tior = 1.0;
*tcount = 0;
*tname = NULL;
}
}