Changeset 10076 for OpenSceneGraph/trunk/src/osgPlugins/3ds/light.cpp
- Timestamp:
- 04/22/09 17:46:24 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/light.cpp
r1563 r10076 122 122 */ 123 123 static Lib3dsBool 124 spotlight_read(Lib3dsLight *light, FILE *f)124 spotlight_read(Lib3dsLight *light, iostream *strm) 125 125 { 126 126 Lib3dsChunk c; … … 128 128 int i; 129 129 130 if (!lib3ds_chunk_read_start(&c, LIB3DS_DL_SPOTLIGHT, f)) {130 if (!lib3ds_chunk_read_start(&c, LIB3DS_DL_SPOTLIGHT, strm)) { 131 131 return(LIB3DS_FALSE); 132 132 } 133 133 light->spot_light=LIB3DS_TRUE; 134 134 for (i=0; i<3; ++i) { 135 light->spot[i]=lib3ds_float_read( f);136 } 137 light->hot_spot = lib3ds_float_read( f);138 light->fall_off = lib3ds_float_read( f);139 lib3ds_chunk_read_tell(&c, f);135 light->spot[i]=lib3ds_float_read(strm); 136 } 137 light->hot_spot = lib3ds_float_read(strm); 138 light->fall_off = lib3ds_float_read(strm); 139 lib3ds_chunk_read_tell(&c, strm); 140 140 141 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {141 while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 142 142 switch (chunk) { 143 143 case LIB3DS_DL_SPOT_ROLL: 144 144 { 145 light->roll=lib3ds_float_read( f);145 light->roll=lib3ds_float_read(strm); 146 146 } 147 147 break; … … 153 153 case LIB3DS_DL_LOCAL_SHADOW2: 154 154 { 155 light->shadow_bias=lib3ds_float_read( f);156 light->shadow_filter=lib3ds_float_read( f);157 light->shadow_size=lib3ds_intw_read( f);155 light->shadow_bias=lib3ds_float_read(strm); 156 light->shadow_filter=lib3ds_float_read(strm); 157 light->shadow_size=lib3ds_intw_read(strm); 158 158 } 159 159 break; … … 170 170 case LIB3DS_DL_SPOT_ASPECT: 171 171 { 172 light->spot_aspect=lib3ds_float_read( f);172 light->spot_aspect=lib3ds_float_read(strm); 173 173 } 174 174 break; … … 176 176 { 177 177 light->use_projector=LIB3DS_TRUE; 178 if (!lib3ds_string_read(light->projector, 64, f)) {178 if (!lib3ds_string_read(light->projector, 64, strm)) { 179 179 return(LIB3DS_FALSE); 180 180 } … … 187 187 case LIB3DS_DL_RAY_BIAS: 188 188 { 189 light->ray_bias=lib3ds_float_read( f);189 light->ray_bias=lib3ds_float_read(strm); 190 190 } 191 191 break; … … 200 200 } 201 201 202 lib3ds_chunk_read_end(&c, f);202 lib3ds_chunk_read_end(&c, strm); 203 203 return(LIB3DS_TRUE); 204 204 } … … 209 209 */ 210 210 Lib3dsBool 211 lib3ds_light_read(Lib3dsLight *light, FILE *f)211 lib3ds_light_read(Lib3dsLight *light, iostream * strm) 212 212 { 213 213 Lib3dsChunk c; 214 214 Lib3dsWord chunk; 215 215 216 if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, f)) {216 if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, strm)) { 217 217 return(LIB3DS_FALSE); 218 218 } … … 220 220 int i; 221 221 for (i=0; i<3; ++i) { 222 light->position[i]=lib3ds_float_read( f);223 } 224 } 225 lib3ds_chunk_read_tell(&c, f);222 light->position[i]=lib3ds_float_read(strm); 223 } 224 } 225 lib3ds_chunk_read_tell(&c, strm); 226 226 227 while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {227 while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 228 228 switch (chunk) { 229 229 case LIB3DS_COLOR_F: … … 231 231 int i; 232 232 for (i=0; i<3; ++i) { 233 light->color[i]=lib3ds_float_read( f);233 light->color[i]=lib3ds_float_read(strm); 234 234 } 235 235 } … … 242 242 case LIB3DS_DL_OUTER_RANGE: 243 243 { 244 light->outer_range=lib3ds_float_read( f);244 light->outer_range=lib3ds_float_read(strm); 245 245 } 246 246 break; 247 247 case LIB3DS_DL_INNER_RANGE: 248 248 { 249 light->inner_range=lib3ds_float_read( f);249 light->inner_range=lib3ds_float_read(strm); 250 250 } 251 251 break; 252 252 case LIB3DS_DL_MULTIPLIER: 253 253 { 254 light->multiplier=lib3ds_float_read( f);254 light->multiplier=lib3ds_float_read(strm); 255 255 } 256 256 break; … … 262 262 case LIB3DS_DL_ATTENUATE: 263 263 { 264 light->attenuation=lib3ds_float_read( f);264 light->attenuation=lib3ds_float_read(strm); 265 265 } 266 266 break; 267 267 case LIB3DS_DL_SPOTLIGHT: 268 268 { 269 lib3ds_chunk_read_reset(&c, f);270 if (!spotlight_read(light, f)) {269 lib3ds_chunk_read_reset(&c, strm); 270 if (!spotlight_read(light, strm)) { 271 271 return(LIB3DS_FALSE); 272 272 } … … 278 278 } 279 279 280 lib3ds_chunk_read_end(&c, f);280 lib3ds_chunk_read_end(&c, strm); 281 281 return(LIB3DS_TRUE); 282 282 } … … 287 287 */ 288 288 Lib3dsBool 289 lib3ds_light_write(Lib3dsLight *light, FILE *f)289 lib3ds_light_write(Lib3dsLight *light, iostream *strm) 290 290 { 291 291 Lib3dsChunk c; 292 292 293 293 c.chunk=LIB3DS_N_DIRECT_LIGHT; 294 if (!lib3ds_chunk_write_start(&c, f)) {294 if (!lib3ds_chunk_write_start(&c,strm)) { 295 295 return(LIB3DS_FALSE); 296 296 } 297 lib3ds_vector_write(light->position, f);297 lib3ds_vector_write(light->position, strm); 298 298 { /*---- LIB3DS_COLOR_F ----*/ 299 299 Lib3dsChunk c; 300 300 c.chunk=LIB3DS_COLOR_F; 301 301 c.size=18; 302 lib3ds_chunk_write(&c, f);303 lib3ds_rgb_write(light->color, f);302 lib3ds_chunk_write(&c, strm); 303 lib3ds_rgb_write(light->color,strm); 304 304 } 305 305 if (light->off) { /*---- LIB3DS_DL_OFF ----*/ … … 307 307 c.chunk=LIB3DS_DL_OFF; 308 308 c.size=6; 309 lib3ds_chunk_write(&c, f);309 lib3ds_chunk_write(&c, strm); 310 310 } 311 311 { /*---- LIB3DS_DL_OUTER_RANGE ----*/ … … 313 313 c.chunk=LIB3DS_DL_OUTER_RANGE; 314 314 c.size=10; 315 lib3ds_chunk_write(&c, f);316 lib3ds_float_write(light->outer_range, f);315 lib3ds_chunk_write(&c, strm); 316 lib3ds_float_write(light->outer_range,strm); 317 317 } 318 318 { /*---- LIB3DS_DL_INNER_RANGE ----*/ … … 320 320 c.chunk=LIB3DS_DL_INNER_RANGE; 321 321 c.size=10; 322 lib3ds_chunk_write(&c, f);323 lib3ds_float_write(light->inner_range, f);322 lib3ds_chunk_write(&c, strm); 323 lib3ds_float_write(light->inner_range,strm); 324 324 } 325 325 { /*---- LIB3DS_DL_MULTIPLIER ----*/ … … 327 327 c.chunk=LIB3DS_DL_MULTIPLIER; 328 328 c.size=10; 329 lib3ds_chunk_write(&c, f);330 lib3ds_float_write(light->multiplier, f);329 lib3ds_chunk_write(&c, strm); 330 lib3ds_float_write(light->multiplier, strm); 331 331 } 332 332 if (light->attenuation) { /*---- LIB3DS_DL_ATTENUATE ----*/ … … 334 334 c.chunk=LIB3DS_DL_ATTENUATE; 335 335 c.size=6; 336 lib3ds_chunk_write(&c, f);336 lib3ds_chunk_write(&c, strm); 337 337 } 338 338 … … 341 341 342 342 c.chunk=LIB3DS_DL_SPOTLIGHT; 343 if (!lib3ds_chunk_write_start(&c, f)) {343 if (!lib3ds_chunk_write_start(&c,strm)) { 344 344 return(LIB3DS_FALSE); 345 345 } 346 lib3ds_vector_write(light->spot, f);347 lib3ds_float_write(light->hot_spot, f);348 lib3ds_float_write(light->fall_off, f);346 lib3ds_vector_write(light->spot, strm); 347 lib3ds_float_write(light->hot_spot, strm); 348 lib3ds_float_write(light->fall_off, strm); 349 349 350 350 { /*---- LIB3DS_DL_SPOT_ROLL ----*/ … … 352 352 c.chunk=LIB3DS_DL_SPOT_ROLL; 353 353 c.size=10; 354 lib3ds_chunk_write(&c, f);355 lib3ds_float_write(light->roll, f);354 lib3ds_chunk_write(&c, strm); 355 lib3ds_float_write(light->roll,strm); 356 356 } 357 357 if (light->shadowed) { /*---- LIB3DS_DL_SHADOWED ----*/ … … 359 359 c.chunk=LIB3DS_DL_SHADOWED; 360 360 c.size=6; 361 lib3ds_chunk_write(&c, f);361 lib3ds_chunk_write(&c, strm); 362 362 } 363 363 if ((fabs(light->shadow_bias)>LIB3DS_EPSILON) || … … 367 367 c.chunk=LIB3DS_DL_LOCAL_SHADOW2; 368 368 c.size=16; 369 lib3ds_chunk_write(&c, f);370 lib3ds_float_write(light->shadow_bias, f);371 lib3ds_float_write(light->shadow_filter, f);372 lib3ds_intw_write(light->shadow_size, f);369 lib3ds_chunk_write(&c, strm); 370 lib3ds_float_write(light->shadow_bias,strm); 371 lib3ds_float_write(light->shadow_filter,strm); 372 lib3ds_intw_write(light->shadow_size,strm); 373 373 } 374 374 if (light->see_cone) { /*---- LIB3DS_DL_SEE_CONE ----*/ … … 376 376 c.chunk=LIB3DS_DL_SEE_CONE; 377 377 c.size=6; 378 lib3ds_chunk_write(&c, f);378 lib3ds_chunk_write(&c, strm); 379 379 } 380 380 if (light->rectangular_spot) { /*---- LIB3DS_DL_SPOT_RECTANGULAR ----*/ … … 382 382 c.chunk=LIB3DS_DL_SPOT_RECTANGULAR; 383 383 c.size=6; 384 lib3ds_chunk_write(&c, f);384 lib3ds_chunk_write(&c, strm); 385 385 } 386 386 if (fabs(light->spot_aspect)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_SPOT_ASPECT ----*/ … … 388 388 c.chunk=LIB3DS_DL_SPOT_ASPECT; 389 389 c.size=10; 390 lib3ds_chunk_write(&c, f);391 lib3ds_float_write(light->spot_aspect, f);390 lib3ds_chunk_write(&c, strm); 391 lib3ds_float_write(light->spot_aspect,strm); 392 392 } 393 393 if (light->use_projector) { /*---- LIB3DS_DL_SPOT_PROJECTOR ----*/ … … 395 395 c.chunk=LIB3DS_DL_SPOT_PROJECTOR; 396 396 c.size=10; 397 lib3ds_chunk_write(&c, f);398 lib3ds_string_write(light->projector, f);397 lib3ds_chunk_write(&c, strm); 398 lib3ds_string_write(light->projector,strm); 399 399 } 400 400 if (light->spot_overshoot) { /*---- LIB3DS_DL_SPOT_OVERSHOOT ----*/ … … 402 402 c.chunk=LIB3DS_DL_SPOT_OVERSHOOT; 403 403 c.size=6; 404 lib3ds_chunk_write(&c, f);404 lib3ds_chunk_write(&c, strm); 405 405 } 406 406 if (fabs(light->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_RAY_BIAS ----*/ … … 408 408 c.chunk=LIB3DS_DL_RAY_BIAS; 409 409 c.size=10; 410 lib3ds_chunk_write(&c, f);411 lib3ds_float_write(light->ray_bias, f);410 lib3ds_chunk_write(&c, strm); 411 lib3ds_float_write(light->ray_bias,strm); 412 412 } 413 413 if (light->ray_shadows) { /*---- LIB3DS_DL_RAYSHAD ----*/ … … 415 415 c.chunk=LIB3DS_DL_RAYSHAD; 416 416 c.size=6; 417 lib3ds_chunk_write(&c, f);418 } 419 if (!lib3ds_chunk_write_end(&c, f)) {417 lib3ds_chunk_write(&c, strm); 418 } 419 if (!lib3ds_chunk_write_end(&c,strm)) { 420 420 return(LIB3DS_FALSE); 421 421 } 422 422 } 423 if (!lib3ds_chunk_write_end(&c, f)) {423 if (!lib3ds_chunk_write_end(&c,strm)) { 424 424 return(LIB3DS_FALSE); 425 425 }
