C:/jkyprian/devel/lib3ds/lib3ds/shadow.c

00001 /*
00002  * The 3D Studio File Format Library
00003  * Copyright (C) 1996-2007 by Jan Eric Kyprianidis <www.kyprianidis.com>
00004  * All rights reserved.
00005  *
00006  * This program is  free  software;  you can redistribute it and/or modify it
00007  * under the terms of the  GNU Lesser General Public License  as published by 
00008  * the  Free Software Foundation;  either version 2.1 of the License,  or (at 
00009  * your option) any later version.
00010  *
00011  * This  program  is  distributed in  the  hope that it will  be useful,  but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013  * or  FITNESS FOR A  PARTICULAR PURPOSE.  See the  GNU Lesser General Public  
00014  * License for more details.
00015  *
00016  * You should  have received  a copy of the GNU Lesser General Public License
00017  * along with  this program;  if not, write to the  Free Software Foundation,
00018  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  *
00020  * $Id: shadow.c,v 1.11 2007/06/20 17:04:09 jeh Exp $
00021  */
00022 #include <lib3ds/shadow.h>
00023 #include <lib3ds/chunk.h>
00024 #include <lib3ds/io.h>
00025 #include <math.h>
00026 
00027 
00036 Lib3dsBool
00037 lib3ds_shadow_read(Lib3dsShadow *shadow, Lib3dsIo *io)
00038 {
00039   Lib3dsChunk c;
00040 
00041   if (!lib3ds_chunk_read(&c, io)) {
00042     return(LIB3DS_FALSE);
00043   }
00044   
00045   switch (c.chunk) {
00046     case LIB3DS_SHADOW_MAP_SIZE:
00047       {
00048         shadow->map_size=lib3ds_io_read_intw(io);
00049       }
00050       break;
00051     case LIB3DS_LO_SHADOW_BIAS:
00052       {
00053           shadow->lo_bias=lib3ds_io_read_float(io);
00054       }
00055       break;
00056     case LIB3DS_HI_SHADOW_BIAS:
00057       {
00058         shadow->hi_bias=lib3ds_io_read_float(io);
00059       }
00060       break;
00061     case LIB3DS_SHADOW_SAMPLES:
00062       {
00063         shadow->samples=lib3ds_io_read_intw(io);
00064       }
00065       break;
00066     case LIB3DS_SHADOW_RANGE:
00067       {
00068         shadow->range=lib3ds_io_read_intd(io);
00069       }
00070       break;
00071     case LIB3DS_SHADOW_FILTER:
00072       {
00073         shadow->filter=lib3ds_io_read_float(io);
00074       }
00075       break;
00076     case LIB3DS_RAY_BIAS:
00077       {
00078         shadow->ray_bias=lib3ds_io_read_float(io);
00079       }
00080       break;
00081   }
00082   
00083   return(LIB3DS_TRUE);
00084 }
00085 
00086 
00090 Lib3dsBool
00091 lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io)
00092 {
00093   if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
00094     Lib3dsChunk c;
00095     c.chunk=LIB3DS_LO_SHADOW_BIAS;
00096     c.size=10;
00097     lib3ds_chunk_write(&c,io);
00098     lib3ds_io_write_float(io, shadow->lo_bias);
00099   }
00100 
00101   if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
00102     Lib3dsChunk c;
00103     c.chunk=LIB3DS_HI_SHADOW_BIAS;
00104     c.size=10;
00105     lib3ds_chunk_write(&c,io);
00106     lib3ds_io_write_float(io, shadow->hi_bias);
00107   }
00108 
00109   if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
00110     Lib3dsChunk c;
00111     c.chunk=LIB3DS_SHADOW_MAP_SIZE;
00112     c.size=8;
00113     lib3ds_chunk_write(&c,io);
00114     lib3ds_io_write_intw(io, shadow->map_size);
00115   }
00116   
00117   if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
00118     Lib3dsChunk c;
00119     c.chunk=LIB3DS_SHADOW_SAMPLES;
00120     c.size=8;
00121     lib3ds_chunk_write(&c,io);
00122     lib3ds_io_write_intw(io, shadow->samples);
00123   }
00124 
00125   if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
00126     Lib3dsChunk c;
00127     c.chunk=LIB3DS_SHADOW_RANGE;
00128     c.size=10;
00129     lib3ds_chunk_write(&c,io);
00130     lib3ds_io_write_intd(io, shadow->range);
00131   }
00132 
00133   if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
00134     Lib3dsChunk c;
00135     c.chunk=LIB3DS_SHADOW_FILTER;
00136     c.size=10;
00137     lib3ds_chunk_write(&c,io);
00138     lib3ds_io_write_float(io, shadow->filter);
00139   }
00140   if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
00141     Lib3dsChunk c;
00142     c.chunk=LIB3DS_RAY_BIAS;
00143     c.size=10;
00144     lib3ds_chunk_write(&c,io);
00145     lib3ds_io_write_float(io, shadow->ray_bias);
00146   }
00147   return(LIB3DS_TRUE);
00148 }
00149 

Hosted by
SourceForge.net Logo
Generated at Wed Jun 20 18:51:36 2007 by Doxygen 1.5.2