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


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

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


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

示例1: GetIntersection

Intersection Mesh::GetIntersection(Ray r){
    Ray r_loc = r.GetTransformedCopy(transform.invT());
    Intersection closest;
    for(int i = 0; i < faces.size(); i++){
        Intersection isx = faces[i]->GetIntersection(r_loc);
        if(isx.object_hit != NULL && isx.t > 0 && (isx.t < closest.t || closest.t < 0)){
            closest = isx;
        }
    }
    if(closest.object_hit != NULL)
    {
        Triangle* tri = (Triangle*)closest.object_hit;
        glm::vec4 P = glm::vec4(closest.t * r_loc.direction + r_loc.origin, 1);
        closest.point = glm::vec3(transform.T() * P);
        closest.normal = glm::normalize(glm::vec3(transform.invTransT() * tri->GetNormal(P)));
        closest.object_hit = this;
        closest.t = glm::distance(closest.point, r.origin);//The t used for the closest triangle test was in object space
        //TODO: Store the tangent and bitangent
    }
    return closest;
}
开发者ID:aksris,项目名称:PathTracer,代码行数:21,代码来源:mesh.cpp

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


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