text
stringlengths
0
234
begin
-- Skip "dead" edge (triangle), 30 - Dec - 2001
if Pn1=0 or else Pn2=0 then return; end if;
-- Detect same point number
if Pn1=Pn2 then
raise_exception (duplicated_vertex'Identity,
o.id & " in face " & Integer'Image (f));
end if;
-- Detect same point coordinates (tolerated in an object,
-- although inefficient, but harms as vertex of the same face!)
if Almost_zero (Norm2 (o.point (Pn1) - o.point (Pn2))) then
raise_exception (duplicated_vertex_location'Identity,
o.id & " in face " & Integer'Image (f));
end if;
end Check_duplicate;
begin
for fa in o.face'Range loop
for edge_num in 1 .. 4 loop
Check (fa, o.face (fa).P (edge_num));
for other_edge in edge_num + 1 .. 4 loop
Check_duplicate (fa, o.face (fa).P (edge_num),
o.face (fa).P (other_edge));
end loop;
end loop;
end loop; -- fa
end Check_faces;
begin
Check_faces;
end Check_object;
--------------------------------------------
-- Object initialization (1x in its life) --
--------------------------------------------
procedure Pre_calculate (o : in out Object_3D) is
use GL, G3DM;
N : Vector_3D;
length_N : Real;
procedure Calculate_face_invariants (
fa : in Face_type;
fi : out Face_invariant_type
) is
l : Natural := 0;
quadri_edge : array (fa.P'Range) of Natural;
ex_U, ex_V : Real;
begin
l := 0;
for qe in fa.P'Range loop
if fa.P (qe) /= 0 then
l := l + 1;
quadri_edge (l) := qe; -- if triangle, "map" edge on a quadri
fi.P_compact (l) := fa.P (qe);
end if;
end loop;
if l in Edge_count then
fi.last_edge := l;
else
raise_exception (bad_edge_number'Identity, o.id);
end if;
-- * Face invariant : Textured face : extremities
for e in 1 .. l loop
if fa.whole_texture then
ex_U := Real (fa.repeat_U);
ex_V := Real (fa.repeat_V);
case quadri_edge (e) is
when 1 => fi.UV_extrema (e) := (0.0, 0.0); -- bottom, left 4 --< --3
when 2 => fi.UV_extrema (e) := (ex_U, 0.0); -- bottom, right | |
when 3 => fi.UV_extrema (e) := (ex_U, ex_V); -- top, right 1 --> --2
when 4 => fi.UV_extrema (e) := (0.0, ex_V); -- top, left
when others => null;
end case;
else
-- Just copy the mapping, but in compact form for triangles:
fi.UV_extrema (e) := fa.texture_edge_map (quadri_edge (e));
end if;
end loop;
-- * Face invariant : Normal of unrotated face
N := (0.0, 0.0, 0.0);
case fi.last_edge is
when 3 =>
Add_Normal_of_3p (o,
fi.P_compact (1),
fi.P_compact (2),
fi.P_compact (3),
N
);
when 4 =>
Add_Normal_of_3p (o, fa.P (1), fa.P (2), fa.P (4), N);
-- We sum other normals for not perfectly flat faces,
-- in order to have a convenient average .. .
Add_Normal_of_3p (o, fa.P (2), fa.P (3), fa.P (1), N);
Add_Normal_of_3p (o, fa.P (3), fa.P (4), fa.P (2), N);
Add_Normal_of_3p (o, fa.P (4), fa.P (1), fa.P (3), N);
end case;
length_N := Norm (N);
if Almost_zero (length_N) then
if strict_geometry then
raise zero_summed_normal;
else
fi.normal := N; -- 0 vector !
end if;
else