Subversion Repositories gelsvn

Rev

Rev 178 | Rev 371 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 178 Rev 295
Line 51... Line 51...
51
				
51
				
52
				// Add the angle weighted normal to each vertex
52
				// Add the angle weighted normal to each vertex
53
				for(int j=0;j<3; ++j)
53
				for(int j=0;j<3; ++j)
54
					{
54
					{
55
						const Vec3f p0 = geometry.vertex(f[j]);
55
						const Vec3f p0 = geometry.vertex(f[j]);
56
						const Vec3f a = normalize(geometry.vertex(f[(j+1)%3]) - p0);
56
						Vec3f a = geometry.vertex(f[(j+1)%3]) - p0;
-
 
57
						float l_a = sqr_length(a);
-
 
58
						if(l_a > 0.0f)
-
 
59
							a /= sqrt(l_a);
57
						const Vec3f b = normalize(geometry.vertex(f[(j+2)%3]) - p0);
60
						Vec3f b = geometry.vertex(f[(j+2)%3]) - p0;
-
 
61
						float l_b = sqr_length(b);
-
 
62
						if(l_b > 0.0f)
-
 
63
							b /= sqrt(l_b);
58
						float d = max(-1.0f, min(1.0f, dot(a,b)));
64
						float d = max(-1.0f, min(1.0f, dot(a,b)));
59
						normals.vertex_rw(f[j]) += face_normal * acos(d);
65
						normals.vertex_rw(f[j]) += face_normal * acos(d);
60
					}
66
					}
61
      }
67
      }
62
 
68
 
63
		// Normalize all normals
69
		// Normalize all normals
64
    for(i=0;i<NV; ++i)
70
    for(i=0;i<NV; ++i)
65
			{
71
			{
-
 
72
				float l_vert_rw = sqr_length(normals.vertex_rw(i));
-
 
73
				if(l_vert_rw > 0.0f)
66
				normals.vertex_rw(i).normalize();
74
					normals.vertex_rw(i) /= l_vert_rw;
67
			}
75
			}
68
	}
76
	}
69
 
77
 
70
 
78
 
71
  void TriMesh::get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const
79
  void TriMesh::get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const