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


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

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


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

示例1: GetAABB

AABB TMesh::GetAABB(){
	AABB retval = AABB(verts[0]);

	for(int i = 0; i < vertsN; i++){
		retval.AddPoint(verts[i]);
	}

	return retval;
}
开发者ID:ehissey,项目名称:CS434-1,代码行数:9,代码来源:tmesh.cpp

示例2: Rasterize

void FrameBuffer::Rasterize(PPC* ppc, const M33 &camMat, const Vertex &p0, const Vertex &p1, const Vertex &p2) {
	AABB box;

	// if one of the vertices are behind the camera, skip this triangle
	if (p0.pv.x() == std::numeric_limits<float>::max() ||
		p1.pv.x() == std::numeric_limits<float>::max() ||
		p2.pv.x() == std::numeric_limits<float>::max()) return;

	// compute the bounding box
	box.AddPoint(p0.pv);
	box.AddPoint(p1.pv);
	box.AddPoint(p2.pv);

	// the bounding box should be inside the screen
	int u_min = (int)box.minCorner().x();
	if (u_min < 0) u_min = 0;;
	int u_max = (int)box.maxCorner().x();
	if (u_max >= w) u_max = w - 1;
	int v_min = (int)box.minCorner().y();
	if (v_min < 0) v_min = 0;
	int v_max = (int)box.maxCorner().y();
	if (v_max >= h) v_max = h - 1;

	// setup some variables
	float denom = ((p1.pv - p0.pv) ^ (p2.pv - p0.pv)).z();
	M33 Q;
	Q.SetColumn(0, p0.v - ppc->C);
	Q.SetColumn(1, p1.v - ppc->C);
	Q.SetColumn(2, p2.v - ppc->C);
	Q = Q.Inverted() * camMat;

	for (int u = u_min; u <= u_max; u++) {
		for (int v = v_min; v <= v_max; v++) {
			V3 pp((u + 0.5f) * ppc->a.Length(), (v + 0.5f) * ppc->b.Length(), 0.0f);

			float s = ((pp - p0.pv) ^ (p2.pv - p0.pv)).z() / denom;
			float t = -((pp - p0.pv) ^ (p1.pv - p0.pv)).z() / denom;

			// if the point is outside the triangle, skip it.
			if (s < 0 || s > 1 || t < 0 || t > 1 || s + t > 1) continue;
			//if (s < -0.01f || s > 1.01f || t < -0.01f || t > 1.01f || s + t > 1.01f) continue;
				
			V3 a = Q * V3((float)u + 0.5f, (float)v + 0.5f, 1.0f);
			float w2 = a.x() + a.y() + a.z();
			float s2 = a.y() / w2;
			float t2 = a.z() / w2;

			// locate the corresponding point in the model space.
			V3 p = p0.v * (1 - s2 - t2) + p1.v * s2 + p2.v * t2;

			// if the point is behind the camera, skip this pixel.
			if (!ppc->Project(p, pp)) continue;

			// check if the point is occluded by other triangles.
			if (zb[(h-1-v)*w+u] >= pp.z()) continue;
			
			V3 c1 = GetColor(ppc, p, p0, p1, p2, s2, t2);

			// draw the pixel (u,v) with the interpolated color.
			Set(u, v, c1.GetColor(), pp.z());
		}
	}
}
开发者ID:gnishida,项目名称:Graphics5,代码行数:63,代码来源:FrameBuffer.cpp

示例3: Render

void TMesh::Render(PPC * ppc, FrameBuffer *fb, PointLight *pl, bool wireframe, Envmap *env){
	if(trisN == 0 && vertsN != 0){
		RenderPoints(ppc,fb,3);
		return;
	}else if(trisN == 0 && vertsN == 0){
		return;
	}
	
	Vector3D *projVerts = new Vector3D[vertsN];

	for(int i = 0; i < vertsN; i++){
		projVerts[i] = Vector3D(FLT_MAX, FLT_MAX, FLT_MAX);
		ppc->Project(verts[i], projVerts[i]);
	}

	for(int i = 0; i < trisN; i++){
		int currTri = i;

		unsigned int vinds[3];
		vinds[0] = tris[3*i+0];
		vinds[1] = tris[3*i+1];
		vinds[2] = tris[3*i+2];

		if(wireframe){
			for(int j = 0; j < 3; j++){
				fb->DrawSegment(projVerts[vinds[j]], projVerts[vinds[(j+1)%3]], cols[vinds[j]], cols[vinds[(j+1)%3]]);
			}

			continue;
		}

		//Setup Rasterization

		//Create AABB
		AABB aabb = AABB(projVerts[vinds[0]]);
		aabb.AddPoint(projVerts[vinds[1]]);
		aabb.AddPoint(projVerts[vinds[2]]);

		if(!aabb.Clip(fb->w, fb->h)){
			continue;
		}

		int top = (int) (0.5f + aabb.corners[0][1]);
		int left = (int) (0.5f + aabb.corners[0][0]);
		int bottom = (int) (-0.5f + aabb.corners[1][1]);
		int right = (int) (-0.5f + aabb.corners[1][0]);

		//Edge equations
		Vector3D eeqs[3];

		for(int i = 0; i < 3; i++){
			int _i = (i+1)%3;

			eeqs[i][0] = projVerts[vinds[_i]][1] - projVerts[vinds[i]][1];
			eeqs[i][1] = projVerts[vinds[i]][0] - projVerts[vinds[_i]][0];
			eeqs[i][2] = projVerts[vinds[i]][1] * (-eeqs[i][1]) - projVerts[vinds[i]][0] * eeqs[i][0];

			int _i2 = (i+2)%3;

			Vector3D v3 = Vector3D(projVerts[vinds[_i2]][0], projVerts[vinds[_i2]][1], 1.0f);

			if(v3*eeqs[i] < 0){
				eeqs[i] = -1.0f * eeqs[i];
			}
		}

		//Screen Space Interpolation
		Matrix3x3 ssii = Matrix3x3();
		ssii[0] = projVerts[vinds[0]]; ssii[0][2] = 1.0f;
		ssii[1] = projVerts[vinds[1]]; ssii[1][2] = 1.0f;
		ssii[2] = projVerts[vinds[2]]; ssii[2][2] = 1.0f;
		ssii = ssii.inverse();

		//Color interpolation
		Matrix3x3 tcols = Matrix3x3();
		tcols[0] = cols[vinds[0]];
		tcols[1] = cols[vinds[1]];
		tcols[2] = cols[vinds[2]];

		if(gouraud){ //Apply lighting before creating interpolation matrix
			Vector3D toPL;
			Vector3D norm;

			Vector3D eyeV;
			Vector3D reflectedToPL;

			for(int i = 0; i < 3; i++){
				toPL = (pl->pos - verts[vinds[i]]).normalize();
				norm = (normals[vinds[i]]).normalize();

				eyeV = (ppc->C - verts[vinds[i]]).normalize();
				reflectedToPL = (2.0f * norm * (norm * toPL) - toPL).normalize();

				kdiff = toPL * norm;
				if(kdiff < 0.0f){
					kdiff = 0.0f;
				}

				float temp = reflectedToPL * eyeV;

//.........这里部分代码省略.........
开发者ID:ehissey,项目名称:CS434-1,代码行数:101,代码来源:tmesh.cpp

示例4: ComputeAABB

/**
 * Compute 3D axis aligned bouding box.
 *
 * @param p0	the corner with the minimum coordinates
 * @param p1	the corner with the maximum coordinates
 */
void TMesh::ComputeAABB(AABB &aabb) {
	for (int i = 0; i < vertsN; i++) {
		aabb.AddPoint(verts[i].v);
	}
}
开发者ID:gnishida,项目名称:Graphics3,代码行数:11,代码来源:TMesh.cpp


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