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


C++ HitInfo::clear方法代码示例

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


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

示例1: intersects

HitInfo CSGNode::intersects(Point3D origin, Vector3D dir) const {
  HitInfo info;
  origin = get_inverse() * origin;
  dir = get_inverse() * dir;
  bool first = true;

  for (ChildList::const_iterator it = m_children.begin(); it != m_children.end(); ++it) {
	HitInfo h = (*it)->intersects(origin, dir);
	for (unsigned int i = 0; i < h.hits.size(); i++) {
 	  h.hits.at(i).intersection = get_transform() * h.hits.at(i).intersection;
	  h.hits.at(i).normal = get_inverse().transpose() * h.hits.at(i).normal;
	}
	for (unsigned int i = 0; i < h.lines.size(); i++) {
	  h.lines.at(i).first.intersection = get_transform() * 
	  	h.lines.at(i).first.intersection;
	  h.lines.at(i).second.intersection = get_transform() * 
	  	h.lines.at(i).second.intersection;	
	  h.lines.at(i).first.normal = get_inverse().transpose() * 
	  	h.lines.at(i).first.normal;
	  h.lines.at(i).second.normal = get_inverse().transpose() * 
	  	h.lines.at(i).second.normal;
	}

	switch(m_type) {
	  case UNION: {
		info = HitInfo::merge_info(info, h);
		break;
	  }
	  case INTERSECTION: {
		if (first) {
		  info = h;
		} else if (h.empty()) {
		  info.clear();
		  return info;
		} else {
		  std::vector<HitInfo::LineSegment> lines;
		  for (unsigned int i = 0; i < info.lines.size(); i++) {
			HitInfo::LineSegment line = info.lines.at(i);
			for (unsigned int j = 0; j < h.lines.size(); j++) {
			  HitInfo::LineSegment sub = h.lines.at(j);

			  if (line.first.t >= sub.first.t && line.second.t <= sub.second.t) {
				// subtracting line contains the first line
				lines = HitInfo::insert_line_in_order(lines, line);
			  } else if (line.first.t < sub.first.t && line.second.t > sub.second.t) {
				// first line contains subtracting line
				lines = HitInfo::insert_line_in_order(lines, sub);
			  } else if (line.first.t > sub.first.t && line.first.t < sub.second.t && 
						 line.second.t > sub.second.t) {
				// tail end of line overlaps with subtracting line.
				double len = (sub.second.intersection-line.first.intersection).length();
				if (len > EPSILON) {
				  lines = HitInfo::insert_line_in_order(lines, 
				    std::make_pair(line.first, sub.second));				
				}
			  } else if (line.first.t < sub.first.t && line.second.t > sub.first.t && 
						 line.second.t < sub.second.t) {
				// head end of line overlaps with subtracting line
				double len = (line.second.intersection-sub.first.intersection).length();
				if (len > EPSILON) {
				  lines = HitInfo::insert_line_in_order(lines,
				    std::make_pair(sub.first, line.second));				
				}
			  } else {
				// no overlap, do nothing
				continue;
			  }
			}
		  }
		  info.lines = lines;
		  std::vector<Hit> hits;
		  for (unsigned i = 0; i < info.hits.size(); i++) {
			Hit hit = info.hits.at(i);
			for (unsigned j = 0; j < h.lines.size(); j++) {
			  HitInfo::LineSegment sub = h.lines.at(j);
			  if (hit.t > sub.first.t && hit.t < sub.second.t) {
				hits.push_back(hit);
				break;
			  }
			}
		  }
		  info.hits = hits;
		}
		break;
	  }
	  case DIFFERENCE: {
		if (first && h.empty()) {
		  return info;
		} else if (first && !h.empty()) {
		  info = HitInfo::merge_info(info, h);
		} else if (!h.empty()) {
		  std::vector<HitInfo::LineSegment> lines;
		  for (unsigned int i = 0; i < info.lines.size(); i++) {
			HitInfo::LineSegment line = info.lines.at(i);
			for (unsigned int j = 0; j < h.lines.size(); j++) {
			  HitInfo::LineSegment sub = h.lines.at(j);

			  if (line.first.t >= sub.first.t && line.second.t <= sub.second.t) {
				// subtracting line contains the first line
				continue;
//.........这里部分代码省略.........
开发者ID:t2munika,项目名称:raytracer,代码行数:101,代码来源:scene.cpp


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