Show
Ignore:
Timestamp:
04/22/09 17:46:24 (6 years ago)
Author:
robert
Message:

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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/3ds/camera.cpp

    r1563 r10076  
    9797 */ 
    9898Lib3dsBool 
    99 lib3ds_camera_read(Lib3dsCamera *camera, FILE *f) 
     99lib3ds_camera_read(Lib3dsCamera *camera, iostream *strm) 
    100100{ 
    101101  Lib3dsChunk c; 
    102102  Lib3dsWord chunk; 
    103103 
    104   if (!lib3ds_chunk_read_start(&c, LIB3DS_N_CAMERA, f)) { 
     104  if (!lib3ds_chunk_read_start(&c, LIB3DS_N_CAMERA, strm)) { 
    105105    return(LIB3DS_FALSE); 
    106106  } 
     
    108108    int i; 
    109109    for (i=0; i<3; ++i) { 
    110       camera->position[i]=lib3ds_float_read(f); 
     110      camera->position[i]=lib3ds_float_read(strm); 
    111111    } 
    112112    for (i=0; i<3; ++i) { 
    113       camera->target[i]=lib3ds_float_read(f); 
    114     } 
    115   } 
    116   camera->roll=lib3ds_float_read(f); 
     113      camera->target[i]=lib3ds_float_read(strm); 
     114    } 
     115  } 
     116  camera->roll=lib3ds_float_read(strm); 
    117117  { 
    118118    float s; 
    119     s=lib3ds_float_read(f); 
     119    s=lib3ds_float_read(strm); 
    120120    if (fabs(s)<LIB3DS_EPSILON) { 
    121121      camera->fov=45.0; 
     
    125125    } 
    126126  } 
    127   lib3ds_chunk_read_tell(&c, f); 
     127  lib3ds_chunk_read_tell(&c, strm); 
    128128   
    129   while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) { 
     129  while ((chunk=lib3ds_chunk_read_next(&c, strm))!=0) { 
    130130    switch (chunk) { 
    131131      case LIB3DS_CAM_SEE_CONE: 
     
    136136      case LIB3DS_CAM_RANGES: 
    137137        { 
    138           camera->near_range=lib3ds_float_read(f); 
    139           camera->far_range=lib3ds_float_read(f); 
     138          camera->near_range=lib3ds_float_read(strm); 
     139          camera->far_range=lib3ds_float_read(strm); 
    140140        } 
    141141        break; 
     
    145145  } 
    146146   
    147   lib3ds_chunk_read_end(&c, f); 
     147  lib3ds_chunk_read_end(&c, strm); 
    148148  return(LIB3DS_TRUE); 
    149149} 
     
    154154 */ 
    155155Lib3dsBool 
    156 lib3ds_camera_write(Lib3dsCamera *camera, FILE *f) 
     156lib3ds_camera_write(Lib3dsCamera *camera, iostream *strm) 
    157157{ 
    158158  Lib3dsChunk c; 
    159159 
    160160  c.chunk=LIB3DS_N_CAMERA; 
    161   if (!lib3ds_chunk_write_start(&c,f)) { 
     161  if (!lib3ds_chunk_write_start(&c,strm)) { 
    162162    return(LIB3DS_FALSE); 
    163163  } 
    164164 
    165   lib3ds_vector_write(camera->position, f); 
    166   lib3ds_vector_write(camera->target, f); 
    167   lib3ds_float_write(camera->roll, f); 
     165  lib3ds_vector_write(camera->position, strm); 
     166  lib3ds_vector_write(camera->target, strm); 
     167  lib3ds_float_write(camera->roll, strm); 
    168168  if (fabs(camera->fov)<LIB3DS_EPSILON) { 
    169     lib3ds_float_write(2400.0f/45.0f, f); 
     169    lib3ds_float_write(2400.0f/45.0f, strm); 
    170170  } 
    171171  else { 
    172     lib3ds_float_write(2400.0f/camera->fov, f); 
     172    lib3ds_float_write(2400.0f/camera->fov, strm); 
    173173  } 
    174174 
     
    177177    c.chunk=LIB3DS_CAM_SEE_CONE; 
    178178    c.size=6; 
    179     lib3ds_chunk_write(&c, f); 
     179    lib3ds_chunk_write(&c, strm); 
    180180  } 
    181181  { 
     
    183183    c.chunk=LIB3DS_CAM_RANGES; 
    184184    c.size=14; 
    185     lib3ds_chunk_write(&c, f); 
    186     lib3ds_float_write(camera->near_range, f); 
    187     lib3ds_float_write(camera->far_range, f); 
    188   } 
    189  
    190   if (!lib3ds_chunk_write_end(&c,f)) { 
     185    lib3ds_chunk_write(&c, strm); 
     186    lib3ds_float_write(camera->near_range, strm); 
     187    lib3ds_float_write(camera->far_range, strm); 
     188  } 
     189 
     190  if (!lib3ds_chunk_write_end(&c,strm)) { 
    191191    return(LIB3DS_FALSE); 
    192192  }