|
#include "Lib3ds_background.h"
#include <math.h>
Lib3ds_background::Lib3ds_background()
{
}
bool Lib3ds_background::solid_bgnd_read(Lib3dsBackground *background)
{
Lib3dsChunk c;
uint16_t chunk;
int have_lin = FALSE;
if(!lib3ds_chunk_read_start(&c, CHK_SOLID_BGND))
{
return false;
}
while ((chunk = lib3ds_chunk_read_next(&c)) != 0)
{
switch (chunk)
{
case CHK_LIN_COLOR_F:
lib3ds_io_read_rgb(background->setting.solid_color);
have_lin = TRUE;
break;
case CHK_COLOR_F:
lib3ds_io_read_rgb(background->setting.solid_color);
break;
default:
lib3ds_chunk_unknown(chunk);
}
}
lib3ds_chunk_read_end(&c);
return true;
}
bool Lib3ds_background::v_gradient_read(Lib3dsBackground *background)
{
Lib3dsChunk c;
uint16_t chunk;
int index[2];
float col[2][3][3];
int have_lin = 0;
if(!lib3ds_chunk_read_start(&c, CHK_V_GRADIENT))
{
return false;
}
background->setting.gradient_percent = lib3ds_io_read_float();
lib3ds_chunk_read_tell(&c);
index[0] = index[1] = 0;
while ((chunk = lib3ds_chunk_read_next(&c)) != 0)
{
switch (chunk)
{
case CHK_COLOR_F:
lib3ds_io_read_rgb(col[0][index[0]]);
index[0]++;
break;
case CHK_LIN_COLOR_F:
lib3ds_io_read_rgb(col[1][index[1]]);
index[1]++;
have_lin = 1;
break;
default:
lib3ds_chunk_unknown(chunk);
}
}
{
int i;
for (i = 0; i < 3; ++i)
{
background->setting.gradient_top[i] = col[have_lin][0][i];
background->setting.gradient_middle[i] = col[have_lin][1][i];
background->setting.gradient_bottom[i] = col[have_lin][2][i];
}
}
lib3ds_chunk_read_end(&c);
return true;
}
bool Lib3ds_background::lib3ds_background_read(Lib3dsBackground *background)
{
Lib3dsChunk c;
if(!lib3ds_chunk_read(&c))
{
return false;
}
switch (c.chunk)
{
case CHK_BIT_MAP:
{
if(!lib3ds_io_read_string(background->bitmap_name.bitmap_name, 64))
{
return false;
}
break;
}
case CHK_SOLID_BGND:
{
lib3ds_chunk_read_reset(&c);
if(!solid_bgnd_read(background))
{
return false;
}
break;
}
case CHK_V_GRADIENT:
{
lib3ds_chunk_read_reset(&c);
if(!v_gradient_read(background))
{
return false;
}
break;
}
case CHK_USE_BIT_MAP:
{
background->setting.use_bitmap = TRUE;
break;
}
case CHK_USE_SOLID_BGND:
{
background->setting.use_solid = TRUE;
break;
}
case CHK_USE_V_GRADIENT:
{
background->setting.use_gradient = TRUE;
break;
}
}
return true;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.