zenilib: zenilib/jni/external/lib3ds/src/lib3ds_atmosphere.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lib3ds_atmosphere.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3 All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 2.1 of the License, or
8 (at your option) any later version.
9
10 Thisprogram is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "lib3ds_impl.h"
19
20
21 static void
22 fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io) {
23 Lib3dsChunk c;
24 uint16_t chunk;
25
26 lib3ds_chunk_read_start(&c, CHK_FOG, io);
27
28 at->fog_near_plane = lib3ds_io_read_float(io);
29 at->fog_near_density = lib3ds_io_read_float(io);
30 at->fog_far_plane = lib3ds_io_read_float(io);
31 at->fog_far_density = lib3ds_io_read_float(io);
32 lib3ds_chunk_read_tell(&c, io);
33
34 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
35 switch (chunk) {
36 case CHK_LIN_COLOR_F: {
37 int i;
38 for (i = 0; i < 3; ++i) {
39 at->fog_color[i] = lib3ds_io_read_float(io);
40 }
41 }
42 break;
43
44 case CHK_COLOR_F:
45 break;
46
47 case CHK_FOG_BGND: {
48 at->fog_background = TRUE;
49 }
50 break;
51
52 default:
53 lib3ds_chunk_unknown(chunk, io);
54 }
55 }
56
57 lib3ds_chunk_read_end(&c, io);
58 }
59
60
61 static void
62 layer_fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io) {
63 Lib3dsChunk c;
64 uint16_t chunk;
65 int have_lin = FALSE;
66
67 lib3ds_chunk_read_start(&c, CHK_LAYER_FOG, io);
68
69 at->layer_fog_near_y = lib3ds_io_read_float(io);
70 at->layer_fog_far_y = lib3ds_io_read_float(io);
71 at->layer_fog_density = lib3ds_io_read_float(io);
72 at->layer_fog_flags = lib3ds_io_read_dword(io);
73 lib3ds_chunk_read_tell(&c, io);
74
75 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
76 switch (chunk) {
77 case CHK_LIN_COLOR_F:
78 lib3ds_io_read_rgb(io, at->layer_fog_color);
79 have_lin = TRUE;
80 break;
81
82 case CHK_COLOR_F:
83 lib3ds_io_read_rgb(io, at->layer_fog_color);
84 break;
85
86 default:
87 lib3ds_chunk_unknown(chunk, io);
88 }
89 }
90
91 lib3ds_chunk_read_end(&c, io);
92 }
93
94
95 static void
96 distance_cue_read(Lib3dsAtmosphere *at, Lib3dsIo *io) {
97 Lib3dsChunk c;
98 uint16_t chunk;
99
100 lib3ds_chunk_read_start(&c, CHK_DISTANCE_CUE, io);
101
102 at->dist_cue_near_plane = lib3ds_io_read_float(io);
103 at->dist_cue_near_dimming = lib3ds_io_read_float(io);
104 at->dist_cue_far_plane = lib3ds_io_read_float(io);
105 at->dist_cue_far_dimming = lib3ds_io_read_float(io);
106 lib3ds_chunk_read_tell(&c, io);
107
108 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
109 switch (chunk) {
110 case CHK_DCUE_BGND: {
111 at->dist_cue_background = TRUE;
112 }
113 break;
114
115 default:
116 lib3ds_chunk_unknown(chunk, io);
117 }
118 }
119
120 lib3ds_chunk_read_end(&c, io);
121 }
122
123
124 void
125 lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) {
126 Lib3dsChunk c;
127
128 lib3ds_chunk_read(&c, io);
129 switch (c.chunk) {
130 case CHK_FOG: {
131 lib3ds_chunk_read_reset(&c, io);
132 fog_read(atmosphere, io);
133 break;
134 }
135
136 case CHK_LAYER_FOG: {
137 lib3ds_chunk_read_reset(&c, io);
138 layer_fog_read(atmosphere, io);
139 break;
140 }
141
142 case CHK_DISTANCE_CUE: {
143 lib3ds_chunk_read_reset(&c, io);
144 distance_cue_read(atmosphere, io);
145 break;
146 }
147
148 case CHK_USE_FOG: {
149 atmosphere->use_fog = TRUE;
150 break;
151 }
152
153 case CHK_USE_LAYER_FOG: {
154 atmosphere->use_layer_fog = TRUE;
155 break;
156 }
157
158 case CHK_USE_DISTANCE_CUE: {
159 atmosphere->use_dist_cue = TRUE;
160 break;
161 }
162 }
163 }
164
165
166 void
167 lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io) {
168 if (atmosphere->use_fog) { /*---- LIB3DS_FOG ----*/
169 Lib3dsChunk c;
170 c.chunk = CHK_FOG;
171 lib3ds_chunk_write_start(&c, io);
172
173 lib3ds_io_write_float(io, atmosphere->fog_near_plane);
174 lib3ds_io_write_float(io, atmosphere->fog_near_density);
175 lib3ds_io_write_float(io, atmosphere->fog_far_plane);
176 lib3ds_io_write_float(io, atmosphere->fog_far_density);
177 {
178 Lib3dsChunk c;
179 c.chunk = CHK_COLOR_F;
180 c.size = 18;
181 lib3ds_chunk_write(&c, io);
182 lib3ds_io_write_rgb(io, atmosphere->fog_color);
183 }
184 if (atmosphere->fog_background) {
185 Lib3dsChunk c;
186 c.chunk = CHK_FOG_BGND;
187 c.size = 6;
188 lib3ds_chunk_write(&c, io);
189 }
190
191 lib3ds_chunk_write_end(&c, io);
192 }
193
194 if (atmosphere->use_layer_fog) { /*---- LIB3DS_LAYER_FOG ----*/
195 Lib3dsChunk c;
196 c.chunk = CHK_LAYER_FOG;
197 c.size = 40;
198 lib3ds_chunk_write(&c, io);
199 lib3ds_io_write_float(io, atmosphere->layer_fog_near_y);
200 lib3ds_io_write_float(io, atmosphere->layer_fog_far_y);
201 lib3ds_io_write_float(io, atmosphere->layer_fog_near_y);
202 lib3ds_io_write_dword(io, atmosphere->layer_fog_flags);
203 {
204 Lib3dsChunk c;
205 c.chunk = CHK_COLOR_F;
206 c.size = 18;
207 lib3ds_chunk_write(&c, io);
208 lib3ds_io_write_rgb(io, atmosphere->fog_color);
209 }
210 }
211
212 if (atmosphere->use_dist_cue) { /*---- LIB3DS_DISTANCE_CUE ----*/
213 Lib3dsChunk c;
214 c.chunk = CHK_DISTANCE_CUE;
215 lib3ds_chunk_write_start(&c, io);
216
217 lib3ds_io_write_float(io, atmosphere->dist_cue_near_plane);
218 lib3ds_io_write_float(io, atmosphere->dist_cue_near_dimming);
219 lib3ds_io_write_float(io, atmosphere->dist_cue_far_plane);
220 lib3ds_io_write_float(io, atmosphere->dist_cue_far_dimming);
221 if (atmosphere->dist_cue_background) {
222 Lib3dsChunk c;
223 c.chunk = CHK_DCUE_BGND;
224 c.size = 6;
225 lib3ds_chunk_write(&c, io);
226 }
227
228 lib3ds_chunk_write_end(&c, io);
229 }
230
231 if (atmosphere->use_fog) { /*---- LIB3DS_USE_FOG ----*/
232 Lib3dsChunk c;
233 c.chunk = CHK_USE_FOG;
234 c.size = 6;
235 lib3ds_chunk_write(&c, io);
236 }
237
238 if (atmosphere->use_layer_fog) { /*---- LIB3DS_USE_LAYER_FOG ----*/
239 Lib3dsChunk c;
240 c.chunk = CHK_USE_LAYER_FOG;
241 c.size = 6;
242 lib3ds_chunk_write(&c, io);
243 }
244
245 if (atmosphere->use_dist_cue) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/
246 Lib3dsChunk c;
247 c.chunk = CHK_USE_V_GRADIENT;
248 c.size = 6;
249 lib3ds_chunk_write(&c, io);
250 }
251 }
252
253
CHK_USE_FOG
Definition: lib3ds_impl.h:107
Lib3dsAtmosphere::use_dist_cue
int use_dist_cue
Definition: lib3ds.h:81
chunk
else Out of place iCCP chunk
Definition: pngrutil.c:1260
CHK_DISTANCE_CUE
Definition: lib3ds_impl.h:105
Lib3dsChunk
Definition: lib3ds_impl.h:295
Lib3dsAtmosphere::dist_cue_near_plane
float dist_cue_near_plane
Definition: lib3ds.h:83
Lib3dsAtmosphere::fog_background
int fog_background
Definition: lib3ds.h:70
Lib3dsAtmosphere::layer_fog_color
float layer_fog_color[3]
Definition: lib3ds.h:77
uint16_t
unsigned short uint16_t
Definition: SDL_config_windows.h:60
layer_fog_read
static void layer_fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
Definition: lib3ds_atmosphere.c:62
lib3ds_chunk_unknown
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
lib3ds_chunk_read
void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:34
lib3ds_atmosphere_read
void lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
Definition: lib3ds_atmosphere.c:125
lib3ds_io_read_dword
uint32_t lib3ds_io_read_dword(Lib3dsIo *io)
Definition: lib3ds_io.c:172
Lib3dsChunk::size
uint32_t size
Definition: lib3ds_impl.h:297
lib3ds_chunk_read_next
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
CHK_LIN_COLOR_F
Definition: lib3ds_impl.h:80
CHK_FOG
Definition: lib3ds_impl.h:102
Lib3dsAtmosphere
Definition: lib3ds.h:67
lib3ds_chunk_write_start
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
CHK_DCUE_BGND
Definition: lib3ds_impl.h:106
Lib3dsAtmosphere::dist_cue_far_dimming
float dist_cue_far_dimming
Definition: lib3ds.h:86
lib3ds_io_write_float
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
lib3ds_chunk_read_reset
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
Lib3dsAtmosphere::layer_fog_far_y
float layer_fog_far_y
Definition: lib3ds.h:79
c
const GLfloat * c
Definition: glew.h:14913
Lib3dsAtmosphere::fog_far_plane
float fog_far_plane
Definition: lib3ds.h:73
Lib3dsAtmosphere::fog_color
float fog_color[3]
Definition: lib3ds.h:69
Lib3dsAtmosphere::fog_far_density
float fog_far_density
Definition: lib3ds.h:74
lib3ds_io_read_float
float lib3ds_io_read_float(Lib3dsIo *io)
Definition: lib3ds_io.c:237
Lib3dsAtmosphere::fog_near_density
float fog_near_density
Definition: lib3ds.h:72
CHK_FOG_BGND
Definition: lib3ds_impl.h:103
CHK_USE_LAYER_FOG
Definition: lib3ds_impl.h:108
FALSE
#define FALSE
Definition: ftobjs.h:57
Lib3dsAtmosphere::layer_fog_density
float layer_fog_density
Definition: lib3ds.h:80
fog_read
static void fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
Definition: lib3ds_atmosphere.c:22
distance_cue_read
static void distance_cue_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
Definition: lib3ds_atmosphere.c:96
Lib3dsAtmosphere::use_layer_fog
int use_layer_fog
Definition: lib3ds.h:75
Lib3dsAtmosphere::dist_cue_near_dimming
float dist_cue_near_dimming
Definition: lib3ds.h:84
lib3ds_chunk_read_end
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
CHK_COLOR_F
Definition: lib3ds_impl.h:77
lib3ds_chunk_read_tell
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
Lib3dsAtmosphere::dist_cue_background
int dist_cue_background
Definition: lib3ds.h:82
Lib3dsIo
Definition: lib3ds.h:56
Lib3dsAtmosphere::use_fog
int use_fog
Definition: lib3ds.h:68
CHK_USE_V_GRADIENT
Definition: lib3ds_impl.h:101
lib3ds_io_read_rgb
void lib3ds_io_read_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:267
lib3ds_chunk_write
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
lib3ds_chunk_read_start
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
CHK_USE_DISTANCE_CUE
Definition: lib3ds_impl.h:109
Lib3dsAtmosphere::fog_near_plane
float fog_near_plane
Definition: lib3ds.h:71
Lib3dsAtmosphere::layer_fog_flags
unsigned layer_fog_flags
Definition: lib3ds.h:76
CHK_LAYER_FOG
Definition: lib3ds_impl.h:104
Lib3dsChunk::chunk
uint16_t chunk
Definition: lib3ds_impl.h:296
i
int i
Definition: pngrutil.c:1377
Lib3dsAtmosphere::dist_cue_far_plane
float dist_cue_far_plane
Definition: lib3ds.h:85
Lib3dsAtmosphere::layer_fog_near_y
float layer_fog_near_y
Definition: lib3ds.h:78
lib3ds_io_write_dword
void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d)
Definition: lib3ds_io.c:338
TRUE
#define TRUE
Definition: ftobjs.h:53
lib3ds_impl.h
lib3ds_io_write_rgb
void lib3ds_io_write_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:431
lib3ds_chunk_write_end
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
lib3ds_atmosphere_write
void lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
Definition: lib3ds_atmosphere.c:167