ulfben

normalize

Feb 26th, 2021
1,018
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Mesh_normalize( Mesh *myself )
  2. {
  3.     Vert     *vert = myself->vert;
  4.     Triangle *face = myself->face;
  5.  
  6.     for( int i=0; i<myself->mNumVerts; i++ ) vert[i].normal = vec3(0.0f);
  7.  
  8.     for( int i=0; i<myself->mNumFaces; i++ )
  9.     {
  10.         const int ia = face[i].v[0];
  11.         const int ib = face[i].v[1];
  12.         const int ic = face[i].v[2];
  13.  
  14.         const vec3 e1 = vert[ia].pos - vert[ib].pos;
  15.         const vec3 e2 = vert[ic].pos - vert[ib].pos;
  16.         const vec3 no = cross( e1, e2 );
  17.  
  18.         vert[ia].normal += no;
  19.         vert[ib].normal += no;
  20.         vert[ic].normal += no;
  21.     }
  22.  
  23.     for( i=0; i<myself->mNumVerts; i++ ) verts[i].normal = normalize( verts[i].normal );
  24. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×