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


C++ Surface::NumPolys方法代码示例

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


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

示例1: xform

int
TerrainPatch::CheckRayIntersection(Point obj_pos, Point dir, double len, Point& ipt, bool ttpas)
{
	Point  light_pos = obj_pos + dir * len;
	int    impact    = light_pos.y < -100;

	// Special case for illumination -
	// just check if sun is above or below the horizon:

	if (illuminating || impact) {
		return impact;
	}

	if (obj_pos.x != 0 || obj_pos.y != 0 || obj_pos.z != 0) {
		return impact;
	}

	// the rest of this code is only used for eclipsing
	// the solar lens flare:

	// check right angle spherical distance:
	Point  d0 = loc;
	Point  d1 = d0.cross(dir);
	double dlen = d1.length();          // distance of point from line

	if (dlen > radius)                  // clean miss
	return 0;                        // (no impact)

	// make sure some part of this patch falls between
	// the camera and the sun:

	Point closest = loc + dir * radius;

	if (closest * dir < 0)
	return 0;

	// probable hit at this point...
	// test for polygon intersection:
	if (!model)
	return 0;

	Surface* s = model->GetSurfaces().first();

	if (!s)
	return 0;


	// transform ray into object space:
	Matrix xform(Orientation());

	Vec3 tmp = dir;

	dir.x = tmp * Vec3(xform(0,0), xform(0,1), xform(0,2));
	dir.y = tmp * Vec3(xform(1,0), xform(1,1), xform(1,2));
	dir.z = tmp * Vec3(xform(2,0), xform(2,1), xform(2,2));

	tmp = obj_pos-loc;

	obj_pos.x = tmp * Vec3(xform(0,0), xform(0,1), xform(0,2));
	obj_pos.y = tmp * Vec3(xform(1,0), xform(1,1), xform(1,2));
	obj_pos.z = tmp * Vec3(xform(2,0), xform(2,1), xform(2,2));

	double min = 2 * len;

	// check each polygon:
	Poly*    p = s->GetPolys();

	for (int i = 0; i < s->NumPolys(); i++) {
		Point  v = p->plane.normal;
		double d = p->plane.distance;

		double denom = dir*v;

		if (denom < -1.0e-5) {
			Point  P    = v * d;
			double ilen = ((P-obj_pos)*v)/denom;

			if (ilen > 0 && ilen < min) {
				Point intersect = obj_pos + dir * ilen;

				if (p->Contains(intersect)) {
					ipt = intersect;
					min = ilen;
					impact = 1;
				}
			}
		}

		p++;
	}

	// xform impact point back into world coordinates:

	if (impact) {
		ipt = (ipt * Orientation()) + loc;
	}

	return impact;
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:99,代码来源:TerrainPatch.cpp

示例2: if


//.........这里部分代码省略.........
					else {
						p->verts[0] = v;
						p->verts[1] = v+1;
						p->verts[2] = v+3;
						p->verts[3] = v+2;
					}

					if (level >= 2) {
						int layer = CalcLayer(p) + 1;
						p->material = materials.at(layer);
						p->sortval  = layer;
					}

					p++;
				}
			}
		}

		// update the poly planes:
		for (i = 0; i < total; i++) {
			Poly*   p      = s->GetPolys() + i;
			Plane&  plane  = p->plane;
			WORD*   v      = p->verts;

			plane = Plane(vset->loc[v[0]] + loc,
			vset->loc[v[1]] + loc,
			vset->loc[v[2]] + loc);
		}

		s->Normalize();

		// create continguous segments for each material:
		// sort the polys by material index:
		qsort((void*) s->GetPolys(), s->NumPolys(), sizeof(Poly), mcomp);

		// then assign them to cohesive segments:
		Segment* segment = 0;
		Poly*    spolys  = s->GetPolys();

		for (int n = 0; n < s->NumPolys(); n++) {
			if (segment && segment->material == spolys[n].material) {
				segment->npolys++;
			}
			else {
				segment = 0;
			}

			if (!segment) {
				segment = new(__FILE__,__LINE__) Segment;

				segment->npolys   = 1;
				segment->polys    = &spolys[n];
				segment->material = segment->polys->material;
				segment->model    = model;

				s->GetSegments().append(segment);
			}
		}

		Solid::EnableCollision(false);
		model->AddSurface(s);
		Solid::EnableCollision(true);

		// copy vertex normals:
		const Vec3B* tnorms = terrain->Normals();
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:66,代码来源:TerrainPatch.cpp


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