当前位置: 首页>>代码示例>>C++>>正文


C++ AABB::d方法代码示例

本文整理汇总了C++中AABB::d方法的典型用法代码示例。如果您正苦于以下问题:C++ AABB::d方法的具体用法?C++ AABB::d怎么用?C++ AABB::d使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AABB的用法示例。


在下文中一共展示了AABB::d方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Encompassing

static AABB Encompassing(const std::vector<Object*> &e) {
  AABB *t;
  int i;
  float min_x = FLT_MAX, max_x = -FLT_MAX,
      min_y = FLT_MAX, max_y = -FLT_MAX,
      min_z = FLT_MAX, max_z = -FLT_MAX;
  for (i = 0; i < e.size(); i++) {
    t = e[i]->b();
    // X
    if (t->x() < min_x) {
      min_x = t->x();
    }
    if (t->x() + t->w() > max_x) {
      max_x = t->x() + t->w();
    }
    // Y
    if (t->y() < min_y) {
      min_y = t->y();
    }
    if (t->y() + t->h() > max_y) {
      max_y = t->y() + t->h();
    }
    // Z
    if (t->z() < min_z) {
      min_z = t->z();
    }
    if (t->z() + t->d() > max_z) {
      max_z = t->z() + t->d();
    }
  }
  AABB r(min_x, min_y, min_z, max_x - min_x, max_y - min_y, max_z - min_z);
  return r;
}
开发者ID:bntmorgan,项目名称:l2,代码行数:33,代码来源:aabbtree.cpp

示例2: color

AABBCell *AABBTree::Pass(const std::vector<Object*> &e, AABBCell *p,
    int depth){
  if (e.size() == 0) {
    return NULL;
  }
  AABBCell *c = new AABBCell;
  AABB eb = Encompassing(e), *cb;
  c->parent = p;
  c->e_box = eb;
  c->boxes = e;
  // Add it into the debug boxes
  Vector4f color(1.f - (0.05f * depth), 0.f, 0.05f * depth, 0.5f);
  boxes_.push_back(new Object(&c->e_box, new CCube(color)));
  // XXX Maybe modify the stop condition
  if (e.size() == 1 || depth == max_depth_ || (eb.w() <= 1.f && eb.h() <= 1.f &&
        eb.d() <= 1.f)) {
    return c;
  }
  int ld = eb.LargestDim();
  std::vector<Object*> l_child, r_child;
  int i;
  float t;
  switch (ld) {
    case AXIS_X:
      t = eb.x() + eb.w() / 2;
      break;
    case AXIS_Y:
      t = eb.y() + eb.h() / 2;
      break;
    case AXIS_Z:
      t = eb.z() + eb.d() / 2;
      break;
    default:
      printf("Error dude axis %d doesn't exists\n", ld);
      exit(1);
  }
  // Compute left and right child
  for (i = 0; i < e.size(); i++) {
    cb = e[i]->b();
    switch (ld) {
      case AXIS_X:
        if (cb->x() + cb->w() <= t) {
          l_child.push_back(e[i]);
        } else {
          r_child.push_back(e[i]);
        }
        break;
      case AXIS_Y:
        if (cb->y() + cb->h() <= t) {
          l_child.push_back(e[i]);
        } else {
          r_child.push_back(e[i]);
        }
        break;
      case AXIS_Z:
        if (cb->z() + cb->d() <= t) {
          l_child.push_back(e[i]);
        } else {
          r_child.push_back(e[i]);
        }
        break;
      default:
        printf("Error dude axis %d doesn't exists\n", ld);
        exit(1);
    }
  }
  // Recursive call
  c->l_child = Pass(l_child, c, depth + 1);
  c->r_child = Pass(r_child, c, depth + 1);
  return c;
}
开发者ID:bntmorgan,项目名称:l2,代码行数:71,代码来源:aabbtree.cpp


注:本文中的AABB::d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。