root/OpenSceneGraph/trunk/src/osgPlugins/3ds/shadow.cpp @ 10076

Revision 10076, 3.8 kB (checked in by robert, 5 years ago)

From Neil Hughes, converted across to use istream for reading data from file to enable reading .3ds files over http (use OSG's libcurl plugin).

From Robert Osfield, ammendments of the above to better support reading of files from local directories.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[8]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
[151]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
[8]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
[151]13 * or  FITNESS FOR A  PARTICULAR PURPOSE.  See the  GNU Lesser General Public 
[8]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$
21 */
22#define LIB3DS_EXPORT
[1531]23#include "shadow.h"
24#include "chunk.h"
25#include "readwrite.h"
[1563]26#include <math.h>
[8]27
[151]28
[8]29/*!
30 * \defgroup shadow Shadow Map Settings
31 *
32 * \author J.E. Hoffmann <je-h@gmx.net>
33 */
34
[151]35
[8]36/*!
[151]37 * \ingroup shadow
[8]38 */
39Lib3dsBool
[10076]40lib3ds_shadow_read(Lib3dsShadow *shadow, iostream *strm)
[8]41{
[151]42  Lib3dsChunk c;
[8]43
[10076]44  if (!lib3ds_chunk_read(&c, strm)) {
[151]45    return(LIB3DS_FALSE);
46  }
47 
48  switch (c.chunk) {
49    case LIB3DS_SHADOW_MAP_SIZE:
50      {
[10076]51        shadow->map_size=lib3ds_intw_read(strm);
[151]52      }
53      break;
54    case LIB3DS_LO_SHADOW_BIAS:
55      {
[10076]56          shadow->lo_bias=lib3ds_float_read(strm);
[151]57      }
58      break;
59    case LIB3DS_HI_SHADOW_BIAS:
60      {
[10076]61        shadow->hi_bias=lib3ds_float_read(strm);
[151]62      }
63      break;
64    case LIB3DS_SHADOW_SAMPLES:
65      {
[10076]66        shadow->samples=lib3ds_intw_read(strm);
[151]67      }
68      break;
69    case LIB3DS_SHADOW_RANGE:
70      {
[10076]71        shadow->range=lib3ds_intd_read(strm);
[151]72      }
73      break;
74    case LIB3DS_SHADOW_FILTER:
75      {
[10076]76        shadow->filter=lib3ds_float_read(strm);
[151]77      }
78      break;
79    case LIB3DS_RAY_BIAS:
80      {
[10076]81        shadow->ray_bias=lib3ds_float_read(strm);
[151]82      }
83      break;
84  }
85 
86  return(LIB3DS_TRUE);
[8]87}
88
89
90/*!
[151]91 * \ingroup shadow
[8]92 */
93Lib3dsBool
[10076]94lib3ds_shadow_write(Lib3dsShadow *shadow, iostream *strm)
[8]95{
[151]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;
[10076]100    lib3ds_chunk_write(&c,strm);
101    lib3ds_float_write(shadow->lo_bias,strm);
[151]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;
[10076]108    lib3ds_chunk_write(&c,strm);
109    lib3ds_float_write(shadow->hi_bias,strm);
[151]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;
[10076]116    lib3ds_chunk_write(&c,strm);
117    lib3ds_intw_write(shadow->map_size,strm);
[151]118  }
119 
120  if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
121    Lib3dsChunk c;
122    c.chunk=LIB3DS_SHADOW_SAMPLES;
123    c.size=8;
[10076]124    lib3ds_chunk_write(&c,strm);
125    lib3ds_intw_write(shadow->samples,strm);
[151]126  }
127
128  if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
129    Lib3dsChunk c;
130    c.chunk=LIB3DS_SHADOW_RANGE;
131    c.size=10;
[10076]132    lib3ds_chunk_write(&c,strm);
133    lib3ds_intd_write(shadow->range,strm);
[151]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;
[10076]140    lib3ds_chunk_write(&c,strm);
141    lib3ds_float_write(shadow->filter,strm);
[151]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;
[10076]147    lib3ds_chunk_write(&c,strm);
148    lib3ds_float_write(shadow->ray_bias,strm);
[151]149  }
150  return(LIB3DS_TRUE);
[8]151}
152
153
154/*!
155
156\typedef Lib3dsShadow
157  \ingroup shadow
158  \sa _Lib3dsShadow
159
160*/
Note: See TracBrowser for help on using the browser.