zenilib  0.5.3.0
 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
23  Lib3dsChunk c;
25 
27 
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
63  Lib3dsChunk c;
65  int have_lin = FALSE;
66 
68 
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:
79  have_lin = TRUE;
80  break;
81 
82  case CHK_COLOR_F:
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
97  Lib3dsChunk c;
99 
101 
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: {
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
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
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;
215  lib3ds_chunk_write_start(&c, io);
216 
219  lib3ds_io_write_float(io, atmosphere->dist_cue_far_plane);
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;
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;
248  c.size = 6;
249  lib3ds_chunk_write(&c, io);
250  }
251 }
252 
253 
int use_dist_cue
Definition: lib3ds.h:81
else Out of place iCCP chunk
Definition: pngrutil.c:1260
float dist_cue_near_plane
Definition: lib3ds.h:83
int fog_background
Definition: lib3ds.h:70
float layer_fog_color[3]
Definition: lib3ds.h:77
unsigned short uint16_t
static void layer_fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
void lib3ds_chunk_read(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:34
void lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
uint32_t lib3ds_io_read_dword(Lib3dsIo *io)
Definition: lib3ds_io.c:172
uint32_t size
Definition: lib3ds_impl.h:297
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
float dist_cue_far_dimming
Definition: lib3ds.h:86
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
void lib3ds_chunk_read_reset(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:90
float layer_fog_far_y
Definition: lib3ds.h:79
const GLfloat * c
Definition: glew.h:14913
float fog_far_plane
Definition: lib3ds.h:73
float fog_color[3]
Definition: lib3ds.h:69
float fog_far_density
Definition: lib3ds.h:74
float lib3ds_io_read_float(Lib3dsIo *io)
Definition: lib3ds_io.c:237
float fog_near_density
Definition: lib3ds.h:72
#define FALSE
Definition: ftobjs.h:57
float layer_fog_density
Definition: lib3ds.h:80
static void fog_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
static void distance_cue_read(Lib3dsAtmosphere *at, Lib3dsIo *io)
int use_layer_fog
Definition: lib3ds.h:75
float dist_cue_near_dimming
Definition: lib3ds.h:84
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
int dist_cue_background
Definition: lib3ds.h:82
void lib3ds_io_read_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:267
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
float fog_near_plane
Definition: lib3ds.h:71
unsigned layer_fog_flags
Definition: lib3ds.h:76
uint16_t chunk
Definition: lib3ds_impl.h:296
int i
Definition: pngrutil.c:1377
float dist_cue_far_plane
Definition: lib3ds.h:85
float layer_fog_near_y
Definition: lib3ds.h:78
void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d)
Definition: lib3ds_io.c:338
#define TRUE
Definition: ftobjs.h:53
void lib3ds_io_write_rgb(Lib3dsIo *io, float rgb[3])
Definition: lib3ds_io.c:431
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
void lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)