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)
83 if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, io)) {
86 fog->near_y=lib3ds_io_read_float(io);
87 fog->far_y=lib3ds_io_read_float(io);
88 fog->density=lib3ds_io_read_float(io);
89 fog->flags=lib3ds_io_read_dword(io);
90 lib3ds_chunk_read_tell(&c, io);
92 while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
94 case LIB3DS_LIN_COLOR_F:
95 lib3ds_io_read_rgb(io, fog->col);
98 lib3ds_io_read_rgb(io, fog->col);
101 lib3ds_chunk_unknown(chunk);
105 lib3ds_chunk_read_end(&c, io);
111 distance_cue_read(Lib3dsDistanceCue *cue, Lib3dsIo *io)
116 if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, io)) {
117 return(LIB3DS_FALSE);
119 cue->near_plane=lib3ds_io_read_float(io);
120 cue->near_dimming=lib3ds_io_read_float(io);
121 cue->far_plane=lib3ds_io_read_float(io);
122 cue->far_dimming=lib3ds_io_read_float(io);
123 lib3ds_chunk_read_tell(&c, io);
125 while ((chunk=lib3ds_chunk_read_next(&c, io))!=0) {
127 case LIB3DS_DCUE_BGND:
129 cue->cue_background=LIB3DS_TRUE;
133 lib3ds_chunk_unknown(chunk);
137 lib3ds_chunk_read_end(&c, io);
143 * \ingroup atmosphere
146 lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
150 if (!lib3ds_chunk_read(&c, io)) {
151 return(LIB3DS_FALSE);
157 lib3ds_chunk_read_reset(&c, io);
158 if (!fog_read(&atmosphere->fog, io)) {
159 return(LIB3DS_FALSE);
163 case LIB3DS_LAYER_FOG:
165 lib3ds_chunk_read_reset(&c, io);
166 if (!layer_fog_read(&atmosphere->layer_fog, io)) {
167 return(LIB3DS_FALSE);
171 case LIB3DS_DISTANCE_CUE:
173 lib3ds_chunk_read_reset(&c, io);
174 if (!distance_cue_read(&atmosphere->dist_cue, io)) {
175 return(LIB3DS_FALSE);
181 atmosphere->fog.use=LIB3DS_TRUE;
184 case LIB3DS_USE_LAYER_FOG:
186 atmosphere->fog.use=LIB3DS_TRUE;
189 case LIB3DS_USE_DISTANCE_CUE:
191 atmosphere->dist_cue.use=LIB3DS_TRUE;
201 * \ingroup atmosphere
204 lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, Lib3dsIo *io)
206 if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/
209 if (!lib3ds_chunk_write_start(&c,io)) {
210 return(LIB3DS_FALSE);
212 lib3ds_io_write_float(io, atmosphere->fog.near_plane);
213 lib3ds_io_write_float(io, atmosphere->fog.near_density);
214 lib3ds_io_write_float(io, atmosphere->fog.far_plane);
215 lib3ds_io_write_float(io, atmosphere->fog.far_density);
218 c.chunk=LIB3DS_COLOR_F;
220 lib3ds_chunk_write(&c,io);
221 lib3ds_io_write_rgb(io, atmosphere->fog.col);
223 if (atmosphere->fog.fog_background) {
225 c.chunk=LIB3DS_FOG_BGND;
227 lib3ds_chunk_write(&c,io);
229 if (!lib3ds_chunk_write_end(&c,io)) {
230 return(LIB3DS_FALSE);
234 if (atmosphere->layer_fog.use) { /*---- LIB3DS_LAYER_FOG ----*/
236 c.chunk=LIB3DS_LAYER_FOG;
238 lib3ds_chunk_write(&c,io);
239 lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
240 lib3ds_io_write_float(io, atmosphere->layer_fog.far_y);
241 lib3ds_io_write_float(io, atmosphere->layer_fog.near_y);
242 lib3ds_io_write_dword(io, atmosphere->layer_fog.flags);
245 c.chunk=LIB3DS_COLOR_F;
247 lib3ds_chunk_write(&c,io);
248 lib3ds_io_write_rgb(io, atmosphere->fog.col);
252 if (atmosphere->dist_cue.use) { /*---- LIB3DS_DISTANCE_CUE ----*/
254 c.chunk=LIB3DS_DISTANCE_CUE;
255 if (!lib3ds_chunk_write_start(&c,io)) {
256 return(LIB3DS_FALSE);
258 lib3ds_io_write_float(io, atmosphere->dist_cue.near_plane);
259 lib3ds_io_write_float(io, atmosphere->dist_cue.near_dimming);
260 lib3ds_io_write_float(io, atmosphere->dist_cue.far_plane);
261 lib3ds_io_write_float(io, atmosphere->dist_cue.far_dimming);
262 if (atmosphere->dist_cue.cue_background) {
264 c.chunk=LIB3DS_DCUE_BGND;
266 lib3ds_chunk_write(&c,io);
268 if (!lib3ds_chunk_write_end(&c,io)) {
269 return(LIB3DS_FALSE);
273 if (atmosphere->fog.use) { /*---- LIB3DS_USE_FOG ----*/
275 c.chunk=LIB3DS_USE_FOG;
277 lib3ds_chunk_write(&c,io);
280 if (atmosphere->layer_fog.use) { /*---- LIB3DS_USE_LAYER_FOG ----*/
282 c.chunk=LIB3DS_USE_LAYER_FOG;
284 lib3ds_chunk_write(&c,io);
287 if (atmosphere->dist_cue.use) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/
289 c.chunk=LIB3DS_USE_V_GRADIENT;
291 lib3ds_chunk_write(&c,io);
300 \typedef Lib3dsAtmosphere
302 \sa _Lib3dsAtmosphere