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


C++ Triangle::GetVertex方法代码示例

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


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

示例1: operator

		bool operator()(const Triangle& tri) const
		{
			bool b = tri.CCEncompasses(m_iterVertex);
			
			if (b)
			{
				HandleEdge(tri.GetVertex(0), tri.GetVertex(1));
				HandleEdge(tri.GetVertex(1), tri.GetVertex(2));
				HandleEdge(tri.GetVertex(2), tri.GetVertex(0));
			}

			return b;
		}
开发者ID:somehow79,项目名称:PolyMapGenerator,代码行数:13,代码来源:DelaunayTriangulation.cpp

示例2: PointInTriangle

bool TerrainBlock::PointInTriangle(Triangle& tri,Vector3& point)
{
	Vector3* a = tri.GetVertex(0);
	Vector3* b = tri.GetVertex(1);
	Vector3* c = tri.GetVertex(2);

	Vector3 v0 = (*b) - (*a);
	Vector3 v1 = (*c)- (*a);
	Vector3 v2 = point - (*a);

	float d00 = v0.dotProduct(v0);
	float d01 = v0.dotProduct(v1);
	float d02 = v0.dotProduct(v2);
	float d11 = v1.dotProduct(v1);
	float d12 = v1.dotProduct(v2);

	float invDenom = 1 / (d00 * d11 - d01 * d01);
	float u = (d11 * d02 - d01*d12) * invDenom;
	float v = (d00 * d12 - d01*d02) * invDenom;

	return (u >=0) && (v>=0) && (u+v<1);
}
开发者ID:LiXizhi,项目名称:NPLRuntime,代码行数:22,代码来源:TerrainBlock.cpp

示例3: CalculateVertexNormals

void Mesh::CalculateVertexNormals()
{
	// Clear all vertex normals
	for( unsigned int i = 0; i < this->_vertices.size(); ++i )
	{
		Vertex* vertex = this->_vertices.at(i);
		if( vertex )
		{
			vertex->Normal() = 0.0f;
		}
	}

	// Sum all adjacent triangle normals
	for( unsigned int i = 0; i < this->_triangles.size(); ++i )
	{
		Triangle* triangle = this->_triangles.at(i);
		if( triangle )
		{
			if( triangle->IsValid() )
			{
				for( unsigned int j = 0; j < 3; ++j )
				{
					Vertex* vertex = triangle->GetVertex(j);
					vertex->Normal() += triangle->GetNormal();
				}
			}
		}
	}

	// Normalize all vertex normals
	for( unsigned int i = 0; i < this->_vertices.size(); ++i )
	{
		Vertex* vertex = this->_vertices.at(i);
		if( vertex )
		{
			vertex->Normal().Normalize();
		}
	}
}
开发者ID:vietjtnguyen,项目名称:ucla-winter09-cs174a-opengl-engine,代码行数:39,代码来源:Mesh.cpp

示例4: IntersectingLineAgainstTriangle

bool BasicPrimitiveTests::IntersectingLineAgainstTriangle(const Line & line, const Triangle & triangle, Eigen::Vector3f & rtn_point)
{
	/*
		Main Idea:
            -> Tests if line's intersection with triangle plane is inside triangle 
                -> Using scalar triple products to compute signed tetrahedral volumes
                    -> Which are then used to compute barycentric coordinates of the line-triangle plane intersection.

        Let:
            -> Triangle ABC
            -> Line through PQ
            -> Intersection point R
                -> between line and triangle's plane

        To only determine intersection:
            -> R must be inside triangle
                -> R must be to left of AB, BC, CA if ABC is counter-clockwise vertex ordering.
            -> Use scalar triple products to determine winding of AB, BC, CA compared to PQ:
                -> u, v, w >= 0
                    -> u = [PQ PC PB]
                    -> v = [PQ PA PC]
                    -> w = [PQ PB PA]

        To obtain intersection point:

            -> Volumes of tetrahedra RBCP, RCAP, RABP, proportional to areas of base triangles RBC, RCA, RAB because they all have same height.

            -> Barycentric points:
                -> u = (     [PQ PC PB]    /    [PQ PC PB] + [PQ PA PC] + [PQ PB PA]    )
                -> v = (     [PQ PA PC]    /    [PQ PC PB] + [PQ PA PC] + [PQ PB PA]    )
                -> w = (     [PQ PB PA]    /    [PQ PC PB] + [PQ PA PC] + [PQ PB PA]    )

	*/

	
	Eigen::Vector3f PQ = -line.GetDirection();
	Eigen::Vector3f PA = triangle.GetVertex(0) - line.GetPoint();
	Eigen::Vector3f PB = triangle.GetVertex(1) - line.GetPoint();
	Eigen::Vector3f PC = triangle.GetVertex(2) - line.GetPoint();

	Eigen::Vector3f barycentric_coords;
	barycentric_coords[0] = ScalarTripleProduct(PQ, PC, PB);
	if (barycentric_coords[0] < 0.0f) return false;
	barycentric_coords[1] = ScalarTripleProduct(PQ, PA, PC);
	if (barycentric_coords[1] < 0.0f) return false;
	barycentric_coords[2] = ScalarTripleProduct(PQ, PB, PA);
	if (barycentric_coords[2] < 0.0f) return false;

	float sum = barycentric_coords[0] + barycentric_coords[1] + barycentric_coords[2];
	if (sum < EPSILON)
	{
		float s, s0, s1, s2, t;

		LineSegment edge_AB = LineSegment(triangle.GetVertex(0), triangle.GetVertex(1));
		if (!IntersectLineAgainstSegment(line, edge_AB, s0, t)) s0 = FLT_MAX;
		LineSegment edge_BC = LineSegment(triangle.GetVertex(1), triangle.GetVertex(2));
		if (!IntersectLineAgainstSegment(line, edge_AB, s1, t)) s1 = FLT_MAX;
		LineSegment edge_AC = LineSegment(triangle.GetVertex(0), triangle.GetVertex(2));
		if (!IntersectLineAgainstSegment(line, edge_AB, s2, t)) s2 = FLT_MAX;
		s = std::min(std::min(s0, s1), s2);
		line.GetPointAt(s, rtn_point);
		return true;
	}

	float denom = 1.0f / sum;
	barycentric_coords *= denom;

	rtn_point = triangle.GetVertex(0) * barycentric_coords[0] + triangle.GetVertex(1) * barycentric_coords[1] + triangle.GetVertex(2) * barycentric_coords[2];

	return true;
	
}
开发者ID:Akranar,项目名称:daguerreo,代码行数:72,代码来源:BPT_IntersectingLineRaysSegments.cpp


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