2 * The 3D Studio File Format Library
3 * Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * $Id: atmosphere.c,v 1.9 2001/07/07 19:05:30 jeh Exp $
23 #include <lib3ds/atmosphere.h>
24 #include <lib3ds/chunk.h>
25 #include <lib3ds/io.h>
29 * \defgroup atmosphere Atmosphere Settings
31 * \author J.E. Hoffmann <je-h@gmx.net>
36 fog_read(Lib3dsFog *fog, Lib3dsIo *io)
41 if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, io)) {
44 fog->near_plane = lib3ds_io_read_float(io);
45 fog->near_density=lib3ds_io_read_float(io);
46 fog->far_plane=lib3ds_io_read_float(io);
47 fog->far_density=lib3ds_io_read_float(io);
48 lib3ds_chunk_read_tell(&c, io);
50 while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
52 case LIB3DS_LIN_COLOR_F:
56 fog->col[i]=lib3ds_io_read_float(io);
64 fog->fog_background=LIB3DS_TRUE;
68 lib3ds_chunk_unknown(chunk);
72 lib3ds_chunk_read_end(&c, io);
78 layer_fog_read(Lib3dsLayerFog *fog, Lib3dsIo *io)
82 Lib3dsBool have_lin=LIB3DS_FALSE;
84 if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, io)) {
87 fog->near_y=lib3ds_io_read_float(io);
88 fog->far_y=lib3ds_io_read_float(io);
89 fog->density=lib3ds_io_read_float(io);
90 fog->flags=lib3ds_io_read_dword(io);
91 lib3ds_chunk_read_tell(&c, io);
93 while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
95 case LIB3DS_LIN_COLOR_F:
96 lib3ds_io_read_rgb(io, fog->col);
100 lib3ds_io_read_rgb(io, fog->col);
103 lib3ds_chunk_unknown(chunk);
107 lib3ds_chunk_read_end(&c, io);
113 distance_cue_read(Lib3dsDistanceCue *cue, Lib3dsIo *io)
118 if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, io)) {
119 return(LIB3DS_FALSE);
121 cue->near_plane=lib3ds_io_read_float(io);
122 cue->near_dimming=lib3ds_io_read_float(io);
123 cue->far_plane=lib3ds_io_read_float(io);
124 cue->far_dimming=lib3ds_io_read_float(io);
125 lib3ds_chunk_read_tell(&c, io);
127 while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
129 case LIB3DS_DCUE_BGND:
131 cue->cue_background=LIB3DS_TRUE;
135 lib3ds_chunk_unknown(chunk);
139 lib3ds_chunk_read_end(&c, io);
145 * \ingroup atmosphere
148 lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
152 if (!lib3ds_chunk_read(&c, io)) {
153 return(LIB3DS_FALSE);
159 lib3ds_chunk_read_reset(&c, io);
160 if (!fog_read(&atmosphere->fog, io)) {
161 return(LIB3DS_FALSE);
165 case LIB3DS_LAYER_FOG:
167 lib3ds_chunk_read_reset(&c, io);
168 if (!layer_fog_read(&atmosphere->layer_fog, io)) {
169 return(LIB3DS_FALSE);
173 case LIB3DS_DISTANCE_CUE:
175 lib3ds_chunk_read_reset(&c, io);
176 if (!distance_cue_read(&atmosphere->dist_cue, io)) {
177 return(LIB3DS_FALSE);
183 atmosphere->fog.use=LIB3DS_TRUE;
186 case LIB3DS_USE_LAYER_FOG:
188 atmosphere->fog.use=LIB3DS_TRUE;
191 case LIB3DS_USE_DISTANCE_CUE:
193 atmosphere->dist_cue.use=LIB3DS_TRUE;
203 * \ingroup atmosphere
206 lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
208 if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/
211 if (!lib3ds_chunk_write_start(&c,io)) {
212 return(LIB3DS_FALSE);
214 lib3ds_io_write_float(io, atmosphere->fog.near_plane);
215 lib3ds_io_write_float(io, atmosphere->fog.near_density);
216 lib3ds_io_write_float(io, atmosphere->fog.far_plane);
217 lib3ds_io_write_float(io, atmosphere->fog.far_density);
220 c.chunk=LIB3DS_COLOR_F;
222 lib3ds_chunk_write(&c,io);
223 lib3ds_io_write_rgb(io, atmosphere->fog.col);
225 if (atmosphere->fog.fog_background) {
227 c.chunk=LIB3DS_FOG_BGND;
229 lib3ds_chunk_write(&c,io);
231 if (!lib3ds_chunk_write_end(&c,io)) {
232 return(LIB3DS_FALSE);
236 if (atmosphere->layer_fog.use) { /*---- LIB3DS_LAYER_FOG ----*/
238 c.chunk=LIB3DS_LAYER_FOG;
240 lib3ds_chunk_write(&c,io);
241 lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
242 lib3ds_io_write_float(io, atmosphere->layer_fog.far_y);
243 lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
244 lib3ds_io_write_dword(io, atmosphere->layer_fog.flags);
247 c.chunk=LIB3DS_COLOR_F;
249 lib3ds_chunk_write(&c,io);
250 lib3ds_io_write_rgb(io, atmosphere->fog.col);
254 if (atmosphere->dist_cue.use) { /*---- LIB3DS_DISTANCE_CUE ----*/
256 c.chunk=LIB3DS_DISTANCE_CUE;
257 if (!lib3ds_chunk_write_start(&c,io)) {
258 return(LIB3DS_FALSE);
260 lib3ds_io_write_float(io, atmosphere->dist_cue.near_plane);
261 lib3ds_io_write_float(io, atmosphere->dist_cue.near_dimming);
262 lib3ds_io_write_float(io, atmosphere->dist_cue.far_plane);
263 lib3ds_io_write_float(io, atmosphere->dist_cue.far_dimming);
264 if (atmosphere->dist_cue.cue_background) {
266 c.chunk=LIB3DS_DCUE_BGND;
268 lib3ds_chunk_write(&c,io);
270 if (!lib3ds_chunk_write_end(&c,io)) {
271 return(LIB3DS_FALSE);
275 if (atmosphere->fog.use) { /*---- LIB3DS_USE_FOG ----*/
277 c.chunk=LIB3DS_USE_FOG;
279 lib3ds_chunk_write(&c,io);
282 if (atmosphere->layer_fog.use) { /*---- LIB3DS_USE_LAYER_FOG ----*/
284 c.chunk=LIB3DS_USE_LAYER_FOG;
286 lib3ds_chunk_write(&c,io);
289 if (atmosphere->dist_cue.use) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/
291 c.chunk=LIB3DS_USE_V_GRADIENT;
293 lib3ds_chunk_write(&c,io);
302 \typedef Lib3dsAtmosphere
304 \sa _Lib3dsAtmosphere