MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/PositionBasedDynamics / updateNormals

Method updateNormals

Utils/IndexedFaceMesh.h:97–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95
96 template<class PositionData>
97 void IndexedFaceMesh::updateNormals(const PositionData &pd, const unsigned int offset)
98 {
99 m_normals.resize(numFaces());
100
101 #pragma omp parallel default(shared)
102 {
103 #pragma omp for schedule(static)
104 for (int i = 0; i < (int) numFaces(); i++)
105 {
106 // Get first three points of face
107 const Vector3r &a = pd.getPosition(m_indices[m_verticesPerFace*i] + offset);
108 const Vector3r &b = pd.getPosition(m_indices[m_verticesPerFace*i + 1] + offset);
109 const Vector3r &c = pd.getPosition(m_indices[m_verticesPerFace*i + 2] + offset);
110
111 // Create normal
112 Vector3r v1 = b - a;
113 Vector3r v2 = c - a;
114
115 m_normals[i] = v1.cross(v2);
116 m_normals[i].normalize();
117 // fix normals of degenerate triangles that can become zero vectors
118 if (m_normals[i].squaredNorm() < 1e-6f)
119 m_normals[i] = Vector3r::UnitX();
120 }
121 }
122 }
123
124 template<class PositionData>
125 void IndexedFaceMesh::updateVertexNormals(const PositionData &pd)

Callers 6

UtilitiesModuleFunction · 0.80
updateMeshNormalsMethod · 0.80
updateMeshNormalsMethod · 0.80
updateMeshNormalsMethod · 0.80
updateVisMeshMethod · 0.80
loadMeshMethod · 0.80

Calls 4

crossMethod · 0.80
resizeMethod · 0.45
normalizeMethod · 0.45
squaredNormMethod · 0.45

Tested by

no test coverage detected