added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / libs / lib3ds / shadow.c
1 /*
2  * The 3D Studio File Format Library
3  * Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
4  * All rights reserved.
5  *
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.
10  *
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.
15  *
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.
19  *
20  * $Id: shadow.c,v 1.8 2001/07/07 19:05:30 jeh Exp $
21  */
22 #define LIB3DS_EXPORT
23 #include <lib3ds/shadow.h>
24 #include <lib3ds/chunk.h>
25 #include <lib3ds/io.h>
26 #include <math.h>
27
28
29 /*!
30  * \defgroup shadow Shadow Map Settings
31  *
32  * \author J.E. Hoffmann <je-h@gmx.net>
33  */
34
35
36 /*!
37  * \ingroup shadow 
38  */
39 Lib3dsBool
40 lib3ds_shadow_read(Lib3dsShadow *shadow, Lib3dsIo *io)
41 {
42   Lib3dsChunk c;
43
44   if (!lib3ds_chunk_read(&c, io)) {
45     return(LIB3DS_FALSE);
46   }
47   
48   switch (c.chunk) {
49     case LIB3DS_SHADOW_MAP_SIZE:
50       {
51         shadow->map_size=lib3ds_io_read_intw(io);
52       }
53       break;
54     case LIB3DS_LO_SHADOW_BIAS:
55       {
56           shadow->lo_bias=lib3ds_io_read_float(io);
57       }
58       break;
59     case LIB3DS_HI_SHADOW_BIAS:
60       {
61         shadow->hi_bias=lib3ds_io_read_float(io);
62       }
63       break;
64     case LIB3DS_SHADOW_SAMPLES:
65       {
66         shadow->samples=lib3ds_io_read_intw(io);
67       }
68       break;
69     case LIB3DS_SHADOW_RANGE:
70       {
71         shadow->range=lib3ds_io_read_intd(io);
72       }
73       break;
74     case LIB3DS_SHADOW_FILTER:
75       {
76         shadow->filter=lib3ds_io_read_float(io);
77       }
78       break;
79     case LIB3DS_RAY_BIAS:
80       {
81         shadow->ray_bias=lib3ds_io_read_float(io);
82       }
83       break;
84   }
85   
86   return(LIB3DS_TRUE);
87 }
88
89
90 /*!
91  * \ingroup shadow 
92  */
93 Lib3dsBool
94 lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io)
95 {
96   if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
97     Lib3dsChunk c;
98     c.chunk=LIB3DS_LO_SHADOW_BIAS;
99     c.size=10;
100     lib3ds_chunk_write(&c,io);
101     lib3ds_io_write_float(io, shadow->lo_bias);
102   }
103
104   if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
105     Lib3dsChunk c;
106     c.chunk=LIB3DS_HI_SHADOW_BIAS;
107     c.size=10;
108     lib3ds_chunk_write(&c,io);
109     lib3ds_io_write_float(io, shadow->hi_bias);
110   }
111
112   if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
113     Lib3dsChunk c;
114     c.chunk=LIB3DS_SHADOW_MAP_SIZE;
115     c.size=8;
116     lib3ds_chunk_write(&c,io);
117     lib3ds_io_write_intw(io, shadow->map_size);
118   }
119   
120   if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
121     Lib3dsChunk c;
122     c.chunk=LIB3DS_SHADOW_SAMPLES;
123     c.size=8;
124     lib3ds_chunk_write(&c,io);
125     lib3ds_io_write_intw(io, shadow->samples);
126   }
127
128   if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
129     Lib3dsChunk c;
130     c.chunk=LIB3DS_SHADOW_RANGE;
131     c.size=10;
132     lib3ds_chunk_write(&c,io);
133     lib3ds_io_write_intd(io, shadow->range);
134   }
135
136   if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
137     Lib3dsChunk c;
138     c.chunk=LIB3DS_SHADOW_FILTER;
139     c.size=10;
140     lib3ds_chunk_write(&c,io);
141     lib3ds_io_write_float(io, shadow->filter);
142   }
143   if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
144     Lib3dsChunk c;
145     c.chunk=LIB3DS_RAY_BIAS;
146     c.size=10;
147     lib3ds_chunk_write(&c,io);
148     lib3ds_io_write_float(io, shadow->ray_bias);
149   }
150   return(LIB3DS_TRUE);
151 }
152
153
154 /*!
155
156 \typedef Lib3dsShadow
157   \ingroup shadow
158   \sa _Lib3dsShadow
159
160 */