Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CMesh2::CalcNormals()
- {
- normal_data_type_ = NormalDataType::VertexNormal;
- normal_directions_.clear();
- normal_indices_.clear();
- normal_directions_.resize(vertex_positions_.size());
- for (auto& triangle : draw_triangles_)
- {
- auto& a = triangle[0];
- auto& b = triangle[1];
- auto& c = triangle[2];
- auto normal = (vertex_positions_[b] - vertex_positions_[a]) ^ (vertex_positions_[c] - vertex_positions_[a]);
- normal_directions_[a] += normal;
- normal_directions_[b] += normal;
- normal_directions_[c] += normal;
- }
- for (auto& normal : normal_directions_)
- {
- if(normal != Cenit::Math::vector3_f::null())
- {
- normal.normalize();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement