Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. void CMesh2::CalcNormals()
  2. {
  3. normal_data_type_ = NormalDataType::VertexNormal;
  4.  
  5. normal_directions_.clear();
  6. normal_indices_.clear();
  7.  
  8. normal_directions_.resize(vertex_positions_.size());
  9. for (auto& triangle : draw_triangles_)
  10. {
  11. auto& a = triangle[0];
  12. auto& b = triangle[1];
  13. auto& c = triangle[2];
  14. auto normal = (vertex_positions_[b] - vertex_positions_[a]) ^ (vertex_positions_[c] - vertex_positions_[a]);
  15. normal_directions_[a] += normal;
  16. normal_directions_[b] += normal;
  17. normal_directions_[c] += normal;
  18. }
  19.  
  20. for (auto& normal : normal_directions_)
  21. {
  22. if(normal != Cenit::Math::vector3_f::null())
  23. {
  24. normal.normalize();
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement