root/OpenSceneGraph/trunk/src/osgPlugins/3ds/lib3ds/lib3ds_shadow.c @ 10853

Revision 10853, 2.9 kB (checked in by robert, 4 years ago)

From Sukender,
"Here is our freshly baked 3DS reader/writer (named 'v0.5' to differentiate from previous one). Changes are against trunk rev. 10819.
Short changelog (from rev 10819):
- Added 3DS writer
- Sync'd with latest lib3DS
- Added options, especially "flattenMatrixTransforms" to get the "old" behaviour (else the reader correctly maps to OSG the transforms from the 3DS file).

What should be done:
- Check with pivot points, with and without "flattenMatrixTransforms" option.
- We ran tests on it, but we can never be 100% sure there is no bug. Testing from the community would of course be helpful."

RevLine 
[10853]1/*
2    Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3    All rights reserved.
4   
5    This program is free  software: you can redistribute it and/or modify
6    it under the terms of the GNU Lesser General Public License as published
7    by the Free Software Foundation, either version 2.1 of the License, or
8    (at your option) any later version.
9
10    Thisprogram  is  distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU Lesser General Public License for more details.
14   
15    You should  have received a copy of the GNU Lesser General Public License
16    along with  this program; If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "lib3ds_impl.h"
19
20
21void
22lib3ds_shadow_read(Lib3dsShadow *shadow, Lib3dsIo *io) {
23    Lib3dsChunk c;
24
25    lib3ds_chunk_read(&c, io);
26    switch (c.chunk) {
27        case CHK_SHADOW_MAP_SIZE: {
28            shadow->map_size = lib3ds_io_read_intw(io);
29            break;
30        }
31
32        case CHK_LO_SHADOW_BIAS: {
33            shadow->low_bias = lib3ds_io_read_float(io);
34            break;
35        }
36
37        case CHK_HI_SHADOW_BIAS: {
38            shadow->hi_bias = lib3ds_io_read_float(io);
39            break;
40        }
41
42        case CHK_SHADOW_FILTER: {
43            shadow->filter = lib3ds_io_read_float(io);
44            break;
45        }
46
47        case CHK_RAY_BIAS: {
48            shadow->ray_bias = lib3ds_io_read_float(io);
49            break;
50        }
51    }
52}
53
54
55void
56lib3ds_shadow_write(Lib3dsShadow *shadow, Lib3dsIo *io) {
57    if (fabs(shadow->low_bias) > LIB3DS_EPSILON) { /*---- CHK_LO_SHADOW_BIAS ----*/
58        Lib3dsChunk c;
59        c.chunk = CHK_LO_SHADOW_BIAS;
60        c.size = 10;
61        lib3ds_chunk_write(&c, io);
62        lib3ds_io_write_float(io, shadow->low_bias);
63    }
64
65    if (fabs(shadow->hi_bias) > LIB3DS_EPSILON) { /*---- CHK_HI_SHADOW_BIAS ----*/
66        Lib3dsChunk c;
67        c.chunk = CHK_HI_SHADOW_BIAS;
68        c.size = 10;
69        lib3ds_chunk_write(&c, io);
70        lib3ds_io_write_float(io, shadow->hi_bias);
71    }
72
73    if (shadow->map_size) { /*---- CHK_SHADOW_MAP_SIZE ----*/
74        Lib3dsChunk c;
75        c.chunk = CHK_SHADOW_MAP_SIZE;
76        c.size = 8;
77        lib3ds_chunk_write(&c, io);
78        lib3ds_io_write_intw(io, shadow->map_size);
79    }
80
81    if (fabs(shadow->filter) > LIB3DS_EPSILON) { /*---- CHK_SHADOW_FILTER ----*/
82        Lib3dsChunk c;
83        c.chunk = CHK_SHADOW_FILTER;
84        c.size = 10;
85        lib3ds_chunk_write(&c, io);
86        lib3ds_io_write_float(io, shadow->filter);
87    }
88    if (fabs(shadow->ray_bias) > LIB3DS_EPSILON) { /*---- CHK_RAY_BIAS ----*/
89        Lib3dsChunk c;
90        c.chunk = CHK_RAY_BIAS;
91        c.size = 10;
92        lib3ds_chunk_write(&c, io);
93        lib3ds_io_write_float(io, shadow->ray_bias);
94    }
95}
Note: See TracBrowser for help on using the browser.