view Renderer/Engine/matrix.cc @ 1087:20f09564c586 draft

fix (not yet tested)
author root@localhost.localdomain
date Fri, 17 Dec 2010 18:34:29 +0900
parents 294bc9364bee
children
line wrap: on
line source

#include "matrix.h"

// 完全にMac仕様。。sg_matrix を allocate してやらないといけないよ。
float*
copy_matrix(SceneGraphPtr sg, TaskManager *manager) {

  float *matrix = sg->matrix;
  float *real_matrix = sg->real_matrix;

  //変換行列は4x4 なんで、16。が二つで32.と言い訳を書いてみる。
  float *sg_matrix = (float*)manager->allocate(sizeof(float)*32);

  for (int i = 0; i < 16; i++) {
    sg_matrix[i] = matrix[i];
    sg_matrix[i+16] = real_matrix[i];
  }

  return sg_matrix;

}

void
print_matrix(float *matrix) {

  for (int i = 0; i < 32; i++) {
    printf("%f\n",matrix[i]);
  }

}

void
add_matrix_list(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {

    MatrixList *matrix_list = (MatrixList*)manager->allocate(sizeof(MatrixList));

#if SPE_CREATE_POLYGON_CHECK
    print_matrix(sg->sg_matrix);
#endif    

    matrix_list->matrix = copy_matrix(sg, manager);;
    matrix_list->next = NULL;

    
    if (info->last != NULL) {
        info->last->next = matrix_list;
    }

    info->last = matrix_list;
    info->list_length += 1;

}

void
new_matrix_info(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {

    MatrixListInfo *next = NULL;

  if (info->id == -1) {

    info->id = sg->sgid;
    info->list_length = 1;
    info->coord_pack = sg->coord_pack;
    info->coord_pack_size = sg->coord_pack_size;
    next = info;

  } else {

    MatrixListInfo* t;

    for (t = info; t->next != NULL; t = t->next) {
    }

    next = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
    next->id = sg->sgid;
    next->list_length = 1;
    next->coord_pack = sg->coord_pack;
    next->coord_pack_size = sg->coord_pack_size;
    next->next = NULL;
    t->next = next;

  }

    MatrixList *new_list = (MatrixList*)manager->allocate(sizeof(MatrixList));
    new_list->matrix = copy_matrix(sg, manager);

#if SPE_CREATE_POLYGON_CHECK
    print_matrix(sg->sg_matrix);
#endif

    new_list->next = NULL;

    next->first = new_list;
    next->last = new_list;

}

void
collect_matrix(SceneGraphPtr sg, MatrixListInfo *matrix_info, TaskManager *manager) {
  
  matrix_info->id = -1;
  matrix_info->list_length = 0;
  matrix_info->next = NULL;
  matrix_info->first = NULL;
  matrix_info->last = NULL;

  while (sg) {
    
    if (sg->flag_drawable) {
      
      int flag = 0;
      
      for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
	if (sg->sgid == t->id) {
	  add_matrix_list(sg, manager, t);
	  flag = 1;
	}	    	    	    
      }
      
      if (flag != 1) {
	new_matrix_info(sg, manager, matrix_info);  
      }
      
      // search SceneGraph. でも、ただのリストがあったハズだから、あとでそれに直す。はず・・
      if (sg->children != NULL) {
	  sg = sg->children;
      } else if (sg->brother != NULL) {
	sg = sg->brother;
      } else {
	while (sg) {
	  if (sg->brother != NULL) {
	    sg = sg->brother;
	      break;
	  } else {
	    if (sg->parent == NULL) {
	      sg = NULL;
	      break;
	    } else {
	      sg = sg->parent;
	    }
	  }
	}
      } 
    } 
  }
}

void
check_matrix(MatrixListInfo *matrix_info,SceneGraphPtr sg) {

  for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
    for (MatrixList* u = t->first; u != NULL; u = u->next) {
      print_matrix(u->matrix);
    }
  }

}



/* end */