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


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

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


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

示例1: if


//.........这里部分代码省略.........

						*pSpec++ = blend;
						*pTu++   = (float) (-j*dtt);
						*pTv++   = (float) ( i*dtt);
					}

					else {
						*pTu++   = (float) (tu0 - j*dt);
						*pTv++   = (float) (tv0 + i*dt);
					}

					vl.y     = -5000.0f;

					*pVert++ = vl;

					if (level >= 2) {
						*pSpec++ = blend;
						*pTu++   = (float) (-j*dtt);
						*pTv++   = (float) ( i*dtt);
					}

					else {
						*pTu++   = (float) (tu0 - j*dt);
						*pTv++   = (float) (tv0 + i*dt);
					}
				}
			}
		}

		Material* m = materials.first();

		// initialize the polys
		for (i = 0; i < npolys; i++) {
			Poly* p        = s->GetPolys() + i;
			p->nverts      = 3;
			p->vertex_set  = vset;
			p->visible     = 1;
			p->sortval     = 0;
			p->material    = m;

			if (level >= 2 && !water) {
				p->material = materials.at(1);
				p->sortval  = 1;
			}
		}

		for (i = npolys; i < total; i++) {
			Poly* p        = s->GetPolys() + i;
			p->nverts      = 4;
			p->vertex_set  = vset;
			p->visible     = 1;
			p->sortval     = 0;
			p->material    = m;
		}

		int index = 0;

		// build main patch polys:
		for (i = 0; i < detail_size; i++) {
			for (j = 0; j < detail_size; j++) {
				int v[4] = {
					(ds1 * (i  ) + (j  )),
					(ds1 * (i  ) + (j+1)),
					(ds1 * (i+1) + (j  )),
					(ds1 * (i+1) + (j+1)) };
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:66,代码来源:TerrainPatch.cpp

示例2: 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

示例3: new

void
Hoop::CreatePolys()
{
    Material* mtl = new(__FILE__,__LINE__) Material;

    mtl->tex_diffuse   = hoop_texture;
    mtl->blend         = Material::MTL_ADDITIVE;

    int w = width /2;
    int h = height/2;

    model     = new(__FILE__,__LINE__) Model;
    own_model = 1;

    Surface* surface = new(__FILE__,__LINE__) Surface;

    surface->SetName("hoop");
    surface->CreateVerts(4);
    surface->CreatePolys(2);

    VertexSet*  vset  = surface->GetVertexSet();
    Poly*       polys = surface->GetPolys();

    ZeroMemory(polys, sizeof(Poly) * 2);

    for (int i = 0; i < 4; i++) {
        int   x = w;
        int   y = h;
        float u = 0;
        float v = 0;

        if (i == 0 || i == 3)
        x = -x;
        else
        u = 1;

        if (i < 2)
        y = -y;
        else
        v = 1;

        vset->loc[i]   = Vec3(x, y, 0);
        vset->nrm[i]   = Vec3(0, 0, 0);

        vset->tu[i]    = u;
        vset->tv[i]    = v;
    }

    for (int i = 0; i < 2; i++) {
        Poly& poly        = polys[i];

        poly.nverts       = 4;
        poly.vertex_set   = vset;
        poly.material     = mtl;

        poly.verts[0]     = i ? 3 : 0;
        poly.verts[1]     = i ? 2 : 1;
        poly.verts[2]     = i ? 1 : 2;
        poly.verts[3]     = i ? 0 : 3;

        poly.plane        = Plane(vset->loc[poly.verts[0]],
        vset->loc[poly.verts[2]],
        vset->loc[poly.verts[1]]);

        surface->AddIndices(6);
    }

    // then assign them to cohesive segments:
    Segment* segment = new(__FILE__,__LINE__) Segment;
    segment->npolys   = 2;
    segment->polys    = &polys[0];
    segment->material = segment->polys->material;

    surface->GetSegments().append(segment);

    model->AddSurface(surface);


    SetLuminous(true);
}
开发者ID:Banbury,项目名称:starshatter-open,代码行数:80,代码来源:Hoop.cpp


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