#include "./def.hpp"
#include "./structs.hpp"

void init_vec3(vec3& vec)
{
  vec[0]= vec[1]= vec[2]= 0;
};

void init_vec4(vec4& vec)
{
  vec[0]= vec[1]= vec[2]= vec[3]= 0;
};

void init_mat4(mat4& mat)
{
  for(int i= 0; i< 4; i++)
    for(int j= 0; j< 4; j++)    
      mat[i*4 + j]= (i== j)? 1.0f: 0.0f;
};

void vec3_from_node(TiXmlElement* node, vec3& vec)
{
  char* contRaw= (char*)node->GetText();
  vec[0]= atof(strtok(contRaw, " "));
  vec[1]= atof(strtok(NULL, " "));
  vec[2]= atof(strtok(NULL, " "));
};

void vec4_from_node(TiXmlElement* node, vec4& vec)
{
  char* contRaw= (char*)node->GetText();
  vec[0]= atof(strtok(contRaw, " "));
  vec[1]= atof(strtok(NULL, " "));
  vec[2]= atof(strtok(NULL, " "));
  vec[3]= atof(strtok(NULL, " "));
};

void mat4_from_node(TiXmlElement* node, mat4& mat)
{
  char* contRaw= (char*)node->GetText();
  mat[0]= atof(strtok(contRaw, " "));
  for(int j= 1; j<16; j++)
    mat[j]= atof(strtok(NULL, " "));
};
