Example #1
0
/*!
 * Writes a signed byte in a file stream.
 */
void
lib3ds_io_write_intb(Lib3dsIo *io, int8_t b) {
    assert(io);
    if (lib3ds_io_write(io, &b, 1) != 1) {
        lib3ds_io_write_error(io);
    }
}
Example #2
0
/*!
 * \ingroup io
 *
 * Writes a zero-terminated string into a file stream.
 */
Lib3dsBool
lib3ds_io_write_string(Lib3dsIo *io, const char *s)
{
  ASSERT(s);
  ASSERT(io);
  lib3ds_io_write(io, s, strlen(s)+1);
  return(!lib3ds_io_error(io));
}
Example #3
0
/*!
 * \ingroup io
 *
 * Writes a signed byte in a file stream.
 */
Lib3dsBool
lib3ds_io_write_intb(Lib3dsIo *io, Lib3dsIntb b)
{
  ASSERT(io);
  if (lib3ds_io_write(io, &b, 1)!=1) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Example #4
0
/*!
 * Writes a zero-terminated string into a file stream.
 */
void
lib3ds_io_write_string(Lib3dsIo *io, const char *s) {
    size_t len;
    assert(io && s);
    len = strlen(s);
    if (lib3ds_io_write(io, s, len + 1) != len +1) {
        lib3ds_io_write_error(io);
    }
}
Example #5
0
/*!
 * Writes a signed word into a little endian file stream.
 */
void
lib3ds_io_write_intw(Lib3dsIo *io, int16_t w) {
    uint8_t b[2];

    assert(io);
    b[1] = ((uint16_t)w & 0xFF00) >> 8;
    b[0] = ((uint16_t)w & 0x00FF);
    if (lib3ds_io_write(io, b, 2) != 2) {
        lib3ds_io_write_error(io);
    }
}
Example #6
0
/*!
 * Writes a word into a little endian file stream.
 */
void
lib3ds_io_write_word(Lib3dsIo *io, uint16_t w) {
    uint8_t b[2];

    assert(io);
    b[1] = (uint8_t)((w & 0xFF00) >> 8);
    b[0] = (uint8_t)(w & 0x00FF);
    if (lib3ds_io_write(io, b, 2) != 2) {
        lib3ds_io_write_error(io);
    }
}
Example #7
0
/*!
 * \ingroup io
 *
 * Writes a signed word into a little endian file stream.
 */
Lib3dsBool
lib3ds_io_write_intw(Lib3dsIo *io, Lib3dsIntw w)
{
  Lib3dsByte b[2];

  ASSERT(io);
  b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
  b[0]=((Lib3dsWord)w & 0x00FF);
  if (lib3ds_io_write(io, b, 2)!=2) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Example #8
0
/*!
 * Writes a signed dword into a little endian file stream.
 */
void
lib3ds_io_write_intd(Lib3dsIo *io, int32_t d) {
    uint8_t b[4];

    assert(io);
    b[3] = (uint8_t)(((uint32_t)d & 0xFF000000) >> 24);
    b[2] = (uint8_t)(((uint32_t)d & 0x00FF0000) >> 16);
    b[1] = (uint8_t)(((uint32_t)d & 0x0000FF00) >> 8);
    b[0] = (uint8_t)(((uint32_t)d & 0x000000FF));
    if (lib3ds_io_write(io, b, 4) != 4) {
        lib3ds_io_write_error(io);
    }
}
Example #9
0
/*!
 * \ingroup io
 *
 * Writes a signed dword into a little endian file stream.
 */
Lib3dsBool
lib3ds_io_write_intd(Lib3dsIo *io, Lib3dsIntd d)
{
  Lib3dsByte b[4];

  ASSERT(io);
  b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
  b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
  b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
  b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
  if (lib3ds_io_write(io, b, 4)!=4) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Example #10
0
/*!
 * Writes a float into a little endian file stream.
 */
void
lib3ds_io_write_float(Lib3dsIo *io, float l) {
    uint8_t b[4];
    Lib3dsDwordFloat d;

    assert(io);
    d.float_value = l;
    b[3] = (uint8_t)(((uint32_t)d.dword_value & 0xFF000000) >> 24);
    b[2] = (uint8_t)(((uint32_t)d.dword_value & 0x00FF0000) >> 16);
    b[1] = (uint8_t)(((uint32_t)d.dword_value & 0x0000FF00) >> 8);
    b[0] = (uint8_t)(((uint32_t)d.dword_value & 0x000000FF));
    if (lib3ds_io_write(io, b, 4) != 4) {
        lib3ds_io_write_error(io);
    }
}
Example #11
0
/*!
 * \ingroup io
 *
 * Writes a float into a little endian file stream.
 */
Lib3dsBool
lib3ds_io_write_float(Lib3dsIo *io, Lib3dsFloat l)
{
  Lib3dsByte b[4];
  Lib3dsDword d;

  ASSERT(io);
  d=*((Lib3dsDword*)&l);
  b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
  b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
  b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
  b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
  if (lib3ds_io_write(io, b, 4)!=4) {
    return(LIB3DS_FALSE);
  }
  return(LIB3DS_TRUE);
}
Example #12
0
/*!
 * \ingroup viewport 
 */
Lib3dsBool
lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io)
{
  if (viewport->layout.views) {
    Lib3dsChunk c;
    unsigned i;

    c.chunk=LIB3DS_VIEWPORT_LAYOUT;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }

    lib3ds_io_write_word(io, viewport->layout.style);
    lib3ds_io_write_intw(io, viewport->layout.active);
    lib3ds_io_write_intw(io, 0);
    lib3ds_io_write_intw(io, viewport->layout.swap);
    lib3ds_io_write_intw(io, 0);
    lib3ds_io_write_intw(io, viewport->layout.swap_prior);
    lib3ds_io_write_intw(io, viewport->layout.swap_view);
    
    {
      Lib3dsChunk c;
      c.chunk=LIB3DS_VIEWPORT_SIZE;
      c.size=14;
      lib3ds_chunk_write(&c,io);
      lib3ds_io_write_intw(io, viewport->layout.position[0]);
      lib3ds_io_write_intw(io, viewport->layout.position[1]);
      lib3ds_io_write_intw(io, viewport->layout.size[0]);
      lib3ds_io_write_intw(io, viewport->layout.size[1]);
    }

    for (i=0; i<viewport->layout.views; ++i) {
      Lib3dsChunk c;
      c.chunk=LIB3DS_VIEWPORT_DATA_3;
      c.size=55;
      lib3ds_chunk_write(&c,io);

      lib3ds_io_write_intw(io, 0);
      lib3ds_io_write_word(io, viewport->layout.viewL[i].axis_lock);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[0]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].position[1]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[0]);
      lib3ds_io_write_intw(io, viewport->layout.viewL[i].size[1]);
      lib3ds_io_write_word(io, viewport->layout.viewL[i].type);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].zoom);
      lib3ds_io_write_vector(io, viewport->layout.viewL[i].center);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].horiz_angle);
      lib3ds_io_write_float(io, viewport->layout.viewL[i].vert_angle);
      lib3ds_io_write(io, viewport->layout.viewL[i].camera,11);
    }

    if (!lib3ds_chunk_write_end(&c,io)) {
      return(LIB3DS_FALSE);
    }
  }

  if (viewport->default_view.type) {
    Lib3dsChunk c;

    c.chunk=LIB3DS_DEFAULT_VIEW;
    if (!lib3ds_chunk_write_start(&c,io)) {
      return(LIB3DS_FALSE);
    }

    switch (viewport->default_view.type) {
      case LIB3DS_VIEW_TYPE_TOP:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_TOP;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_BOTTOM:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_BOTTOM;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_LEFT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_LEFT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_RIGHT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_RIGHT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_FRONT:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_FRONT;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_BACK:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_BACK;
          c.size=22;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
        }
        break;
      case LIB3DS_VIEW_TYPE_USER:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_USER;
          c.size=34;
          lib3ds_chunk_write(&c,io);
          lib3ds_io_write_vector(io, viewport->default_view.position);
          lib3ds_io_write_float(io, viewport->default_view.width);
          lib3ds_io_write_float(io, viewport->default_view.horiz_angle);
          lib3ds_io_write_float(io, viewport->default_view.vert_angle);
          lib3ds_io_write_float(io, viewport->default_view.roll_angle);
        }
        break;
      case LIB3DS_VIEW_TYPE_CAMERA:
        {
          Lib3dsChunk c;
          c.chunk=LIB3DS_VIEW_CAMERA;
          c.size=17;
          lib3ds_chunk_write(&c, io);
          lib3ds_io_write(io, viewport->default_view.camera, 11);
        }
        break;
    }

    if (!lib3ds_chunk_write_end(&c, io)) {
      return(LIB3DS_FALSE);
    }
  }
  return(LIB3DS_TRUE);
}