view TaskManager/Test/simple_render/create_sgp.cpp @ 26:3f68b2ef4fb0

*** empty log message ***
author gongo
date Sun, 10 Feb 2008 18:31:48 +0900
parents
children 6a77b5e755ab
line wrap: on
line source

#include <iostream>
#include "scene_graph_pack.h"
#include "polygon.h"
using namespace std;


int create_sgp(SceneGraphPack *sgp, Polygon *sg)
{
  int i = 0;
  int nnpn = -1;

  Polygon *t;
  t = sg;

  while(t)
    {
      sgp->node[i].size = t->size;
      int d,tex;
      for(d=0,tex=0; d<t->size*3; d+=3,tex+=2)
	{
	  sgp->node[i].vertex[d] = t->data[d];
	  sgp->node[i].vertex[d+1] = t->data[d+1];
	  sgp->node[i].vertex[d+2] = t->data[d+2];
	  sgp->node[i].texture[tex] = t->data[d+t->size*6];
	  sgp->node[i].texture[tex+1] = t->data[d+t->size*6+1];
	}

      sgp->node[i].obj_pos[0] = 0;
      sgp->node[i].obj_pos[1] = 0;
      sgp->node[i].obj_pos[2] = 0;
      sgp->node[i].obj_pos[3] = 1;
      sgp->node[i].angle[0] = 0;
      sgp->node[i].angle[1] = 0;
      sgp->node[i].angle[2] = 0;
      sgp->node[i].angle[3] = 1;

      for(int tm=0; tm<16; tm++)
        {
          sgp->node[i].translation[tm] = 0;
        }
      sgp->node[i].id = 0;
      sgp->node[i].move = 0;
      sgp->node[i].interaction = 0;
      sgp->node[i].pn = nnpn;

      if(t->child != NULL)
	{
	  nnpn = i;
	  t = t->child;
	}
      else if(t->brother != NULL)
	{
	  nnpn = sgp->node[i].pn;
	  t = t->brother;
	}
      else
	{
	  while(t)
	    {
	      if(t->brother != NULL)
		{
		  t = t->brother;
		  break;
		}
	      else
		{
		  if(t->parent == NULL)
		    {
		      t = NULL;
		      break;
		    }
		  nnpn = sgp->node[nnpn].pn;
		  t = t->parent;
		}
	    }
	}
      i++;
    }
  sgp->info.size = i;

  return sizeof(SceneGraphPack);
}