Subversion Repositories gelsvn

Rev

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

Rev 541 Rev 567
Line 73... Line 73...
73
				if(l_vert_rw > 0.0f)
73
				if(l_vert_rw > 0.0f)
74
					normals.vertex_rw(i) /= sqrt(l_vert_rw);
74
					normals.vertex_rw(i) /= sqrt(l_vert_rw);
75
			}
75
			}
76
	}
76
	}
77
 
77
 
-
 
78
	void TriMesh::compute_areas()
-
 
79
	{
-
 
80
    int no_of_faces = geometry.no_faces();
-
 
81
    surface_area = 0.0f;
-
 
82
    face_areas.resize(no_of_faces);
-
 
83
    face_area_cdf.resize(no_of_faces);
-
 
84
		for(int i = 0; i < no_of_faces; ++i)
-
 
85
    {
-
 
86
			const Vec3i& f  = geometry.face(i);
-
 
87
			const Vec3f& p0 = geometry.vertex(f[0]);
-
 
88
			const Vec3f& a  = geometry.vertex(f[1]) - p0;
-
 
89
			const Vec3f& b  = geometry.vertex(f[2]) - p0;
-
 
90
      face_areas[i] = 0.5f*cross(a, b).length();
-
 
91
      face_area_cdf[i] = surface_area + face_areas[i];
-
 
92
      surface_area += face_areas[i];
-
 
93
    }
-
 
94
    if(surface_area > 0.0f)
-
 
95
      for(int i = 0; i < no_of_faces; ++i)
-
 
96
        face_area_cdf[i] /= surface_area;
-
 
97
	}
78
 
98
 
79
  bool TriMesh::get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const
99
  bool TriMesh::get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const
80
  {
100
  {
81
    if(geometry.no_vertices() == 0)
101
    if(geometry.no_vertices() == 0)
82
      return false;
102
      return false;
Line 107... Line 127...
107
  void TriMesh::transform(CGLA::Mat4x4f m)
127
  void TriMesh::transform(CGLA::Mat4x4f m)
108
  {
128
  {
109
    for(int i = 0; i < geometry.no_vertices(); ++i)
129
    for(int i = 0; i < geometry.no_vertices(); ++i)
110
      geometry.vertex_rw(i) = m.mul_3D_point(geometry.vertex(i));
130
      geometry.vertex_rw(i) = m.mul_3D_point(geometry.vertex(i));
111
    for(int i = 0; i < normals.no_vertices(); ++i)
131
    for(int i = 0; i < normals.no_vertices(); ++i)
112
      normals.vertex_rw(i) = m.mul_3D_vector(normals.vertex(i));
132
      normals.vertex_rw(i) = normalize(m.mul_3D_vector(normals.vertex(i)));
113
  }
133
  }
114
}
134
}