Пример #1
0
void TransformReader::get_node_mat(float mat[4][4],
                                   COLLADAFW::Node *node,
                                   std::map<COLLADAFW::UniqueId, Animation> *animation_map,
                                   Object *ob,
                                   float parent_mat[4][4])
{
  float cur[4][4];
  float copy[4][4];

  unit_m4(mat);

  for (unsigned int i = 0; i < node->getTransformations().getCount(); i++) {

    COLLADAFW::Transformation *tm = node->getTransformations()[i];
    COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();

    switch (type) {
      case COLLADAFW::Transformation::MATRIX:
        // When matrix AND Trans/Rot/Scale are defined for a node,
        // then this is considered as redundant information.
        // So if we find a Matrix we use that and return.
        dae_matrix_to_mat4(tm, mat);
        if (parent_mat) {
          mul_m4_m4m4(mat, parent_mat, mat);
        }
        return;
      case COLLADAFW::Transformation::TRANSLATE:
        dae_translate_to_mat4(tm, cur);
        break;
      case COLLADAFW::Transformation::ROTATE:
        dae_rotate_to_mat4(tm, cur);
        break;
      case COLLADAFW::Transformation::SCALE:
        dae_scale_to_mat4(tm, cur);
        break;
      case COLLADAFW::Transformation::LOOKAT:
        fprintf(stderr, "|!     LOOKAT transformations are not supported yet.\n");
        break;
      case COLLADAFW::Transformation::SKEW:
        fprintf(stderr, "|!     SKEW transformations are not supported yet.\n");
        break;
    }

    copy_m4_m4(copy, mat);
    mul_m4_m4m4(mat, copy, cur);

    if (animation_map) {
      // AnimationList that drives this Transformation
      const COLLADAFW::UniqueId &anim_list_id = tm->getAnimationList();

      // store this so later we can link animation data with ob
      Animation anim = {ob, node, tm};
      (*animation_map)[anim_list_id] = anim;
    }
  }

  if (parent_mat) {
    mul_m4_m4m4(mat, parent_mat, mat);
  }
}
Пример #2
0
void TransformReader::get_node_mat(float mat[4][4], COLLADAFW::Node *node, std::map<COLLADAFW::UniqueId, Animation> *animation_map, Object *ob)
{
	float cur[4][4];
	float copy[4][4];

	unit_m4(mat);
	
	for (unsigned int i = 0; i < node->getTransformations().getCount(); i++) {

		COLLADAFW::Transformation *tm = node->getTransformations()[i];
		COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();

		switch (type) {
			case COLLADAFW::Transformation::MATRIX:
				// XXX why does this return and discard all following transformations?
				dae_matrix_to_mat4(tm, mat);
				return;
			case COLLADAFW::Transformation::TRANSLATE:
				dae_translate_to_mat4(tm, cur);
				break;
			case COLLADAFW::Transformation::ROTATE:
				dae_rotate_to_mat4(tm, cur);
				break;
			case COLLADAFW::Transformation::SCALE:
				dae_scale_to_mat4(tm, cur);
				break;
			case COLLADAFW::Transformation::LOOKAT:
			case COLLADAFW::Transformation::SKEW:
				fprintf(stderr, "LOOKAT and SKEW transformations are not supported yet.\n");
				break;
		}

		copy_m4_m4(copy, mat);
		mul_m4_m4m4(mat, copy, cur);
		
		if (animation_map) {
			// AnimationList that drives this Transformation
			const COLLADAFW::UniqueId& anim_list_id = tm->getAnimationList();
		
			// store this so later we can link animation data with ob
			Animation anim = {ob, node, tm};
			(*animation_map)[anim_list_id] = anim;
		}
	}
}