2001-09-20 05:08:56 +08:00
|
|
|
/*
|
|
|
|
* The 3D Studio File Format Library
|
|
|
|
* Copyright (C) 1996-2001 by J.E. Hoffmann <je-h@gmx.net>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
2001-11-01 02:33:27 +08:00
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or (at
|
2001-09-20 05:08:56 +08:00
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
2001-11-01 02:33:27 +08:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
2001-09-20 05:08:56 +08:00
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
#define LIB3DS_EXPORT
|
2003-01-22 05:02:17 +08:00
|
|
|
#include "shadow.h"
|
|
|
|
#include "chunk.h"
|
|
|
|
#include "readwrite.h"
|
2003-01-24 23:12:54 +08:00
|
|
|
#include <math.h>
|
2001-11-01 02:33:27 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \defgroup shadow Shadow Map Settings
|
|
|
|
*
|
|
|
|
* \author J.E. Hoffmann <je-h@gmx.net>
|
|
|
|
*/
|
|
|
|
|
2001-11-01 02:33:27 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/*!
|
2001-11-01 02:33:27 +08:00
|
|
|
* \ingroup shadow
|
2001-09-20 05:08:56 +08:00
|
|
|
*/
|
|
|
|
Lib3dsBool
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_shadow_read(Lib3dsShadow *shadow, iostream *strm)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-11-01 02:33:27 +08:00
|
|
|
Lib3dsChunk c;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2009-04-22 23:46:24 +08:00
|
|
|
if (!lib3ds_chunk_read(&c, strm)) {
|
2001-11-01 02:33:27 +08:00
|
|
|
return(LIB3DS_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c.chunk) {
|
|
|
|
case LIB3DS_SHADOW_MAP_SIZE:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->map_size=lib3ds_intw_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_LO_SHADOW_BIAS:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->lo_bias=lib3ds_float_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_HI_SHADOW_BIAS:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->hi_bias=lib3ds_float_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_SHADOW_SAMPLES:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->samples=lib3ds_intw_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_SHADOW_RANGE:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->range=lib3ds_intd_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_SHADOW_FILTER:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->filter=lib3ds_float_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LIB3DS_RAY_BIAS:
|
|
|
|
{
|
2009-04-22 23:46:24 +08:00
|
|
|
shadow->ray_bias=lib3ds_float_read(strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(LIB3DS_TRUE);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2001-11-01 02:33:27 +08:00
|
|
|
* \ingroup shadow
|
2001-09-20 05:08:56 +08:00
|
|
|
*/
|
|
|
|
Lib3dsBool
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_shadow_write(Lib3dsShadow *shadow, iostream *strm)
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-11-01 02:33:27 +08:00
|
|
|
if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_LO_SHADOW_BIAS;
|
|
|
|
c.size=10;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_float_write(shadow->lo_bias,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_HI_SHADOW_BIAS;
|
|
|
|
c.size=10;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_float_write(shadow->hi_bias,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_SHADOW_MAP_SIZE;
|
|
|
|
c.size=8;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_intw_write(shadow->map_size,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_SHADOW_SAMPLES;
|
|
|
|
c.size=8;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_intw_write(shadow->samples,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_SHADOW_RANGE;
|
|
|
|
c.size=10;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_intd_write(shadow->range,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_SHADOW_FILTER;
|
|
|
|
c.size=10;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_float_write(shadow->filter,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
|
|
|
|
Lib3dsChunk c;
|
|
|
|
c.chunk=LIB3DS_RAY_BIAS;
|
|
|
|
c.size=10;
|
2009-04-22 23:46:24 +08:00
|
|
|
lib3ds_chunk_write(&c,strm);
|
|
|
|
lib3ds_float_write(shadow->ray_bias,strm);
|
2001-11-01 02:33:27 +08:00
|
|
|
}
|
|
|
|
return(LIB3DS_TRUE);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
\typedef Lib3dsShadow
|
|
|
|
\ingroup shadow
|
|
|
|
\sa _Lib3dsShadow
|
|
|
|
|
|
|
|
*/
|