本文整理汇总了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;
}
示例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();
}
}
}