text stringlengths 0 234 |
|---|
+ Self (p) (2) * Self (p) (2), |
max_Distance_2); |
the_Bounds.Box := (X_Extent => (Min => GL.Double'Min (the_Bounds.Box.X_Extent.Min, Self (p) (0)), |
Max => GL.Double'Max (the_Bounds.Box.X_Extent.Max, Self (p) (0))), |
Y_Extent => (Min => GL.Double'Min (the_Bounds.Box.Y_Extent.Min, Self (p) (1)), |
Max => GL.Double'Max (the_Bounds.Box.Y_Extent.Max, Self (p) (1))), |
Z_Extent => (Min => GL.Double'Min (the_Bounds.Box.Z_Extent.Min, Self (p) (2)), |
Max => GL.Double'Max (the_Bounds.Box.Z_Extent.Max, Self (p) (2)))); |
end loop; |
the_Bounds.Sphere_Radius := Sqrt (max_Distance_2); |
return the_Bounds; |
end Bounds; |
function Bounds (Given_Vertices : GL_Vertex_array; Given_Indices : vertex_Id_array) return GL.Geometry.Bounds_record is |
use GL_Double_EF; |
the_Bounds : Bounds_record := null_Bounds; |
max_Distance_2 : GL.Double := 0.0; -- current maximum distance squared. |
begin |
for Each in Given_Indices'Range loop |
declare |
the_Point : GL_Vertex renames Given_Vertices (Given_Indices (Each)); |
begin |
max_Distance_2 := GL.Double'Max (the_Point (0) * the_Point (0) |
+ the_Point (1) * the_Point (1) |
+ the_Point (2) * the_Point (2), |
max_Distance_2); |
the_Bounds.Box := (X_Extent => (Min => GL.Double'Min (the_Bounds.Box.X_Extent.Min, the_Point (0)), |
Max => GL.Double'Max (the_Bounds.Box.X_Extent.Max, the_Point (0))), |
Y_Extent => (Min => GL.Double'Min (the_Bounds.Box.Y_Extent.Min, the_Point (1)), |
Max => GL.Double'Max (the_Bounds.Box.Y_Extent.Max, the_Point (1))), |
Z_Extent => (Min => GL.Double'Min (the_Bounds.Box.Z_Extent.Min, the_Point (2)), |
Max => GL.Double'Max (the_Bounds.Box.Z_Extent.Max, the_Point (2)))); |
Function Definition: procedure deallocate is new Ada.Unchecked_Deallocation (Geometry_t'Class, p_Geometry); |
Function Body: begin |
destroy (Self.all); |
deallocate (Self); |
end Free; |
function Vertex_Normals (Self : Geometry_t'Class) return GL_Normals_Vertex_Id is |
begin |
case primitive_Id (Self) is |
when TRIANGLES => |
declare |
the_Vertices : GL_Vertex_array renames Vertices (Self); |
the_Indices : vertex_Id_array renames Indices (Self); |
the_Normals : GL_Normals_Vertex_Id (the_Vertices'Range); |
Triangle_Face_Count : constant Positive := the_Indices'Length / 3; |
face_Normals : GL_Normals (1 .. Triangle_Face_Count); |
N : GL.Double_Vector_3D; |
length_N : GL.Double; |
function vertex_Id_for (Face : Positive; point_Id : Positive) return vertex_Id is |
(the_Indices (positive_uInt (3 * (Face - 1) + point_Id))); |
begin |
-- Geometry (Normal of unrotated face) |
-- |
for each_Face in 1 .. Triangle_Face_Count loop |
N := (the_Vertices (vertex_Id_for (each_Face, 2)) - the_Vertices (vertex_Id_for (each_Face, 1))) |
* (the_Vertices (vertex_Id_for (each_Face, 3)) - the_Vertices (vertex_Id_for (each_Face, 1))); |
length_N := Norm (N); |
case Almost_zero (length_N) is |
when True => face_Normals (each_Face) := N; -- 0 vector ! |
when False => face_Normals (each_Face) := (1.0 / length_N) * N; |
end case; |
end loop; |
-- Calculate normal at each vertex. |
-- |
declare |
vertex_adjacent_faces_Count : array (the_Vertices'Range) of Natural := (others => 0); |
the_Vertex : vertex_Id; |
Vertex_Length : Double; |
begin |
for p in the_Vertices'Range loop |
the_Normals (p) := (0.0, 0.0, 0.0); |
end loop; |
for f in 1 .. Triangle_Face_Count loop |
for p in 1 .. 3 loop |
the_Vertex := vertex_Id_for (f, p); |
vertex_adjacent_faces_Count (the_Vertex) := vertex_adjacent_faces_Count (the_Vertex) + 1; |
the_Normals (the_Vertex) := the_Normals (the_Vertex) + face_Normals (f); |
end loop; |
end loop; |
for p in the_Vertices'Range loop |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.