diff --git a/3-mid/opengl/source/lean/model/opengl-model-polygon-lit_textured.adb b/3-mid/opengl/source/lean/model/opengl-model-polygon-lit_textured.adb index 08af152..fed8453 100644 --- a/3-mid/opengl/source/lean/model/opengl-model-polygon-lit_textured.adb +++ b/3-mid/opengl/source/lean/model/opengl-model-polygon-lit_textured.adb @@ -144,28 +144,28 @@ is declare use openGL.Texture.Coordinates; - the_Vertices : Geometry.lit_textured.Vertex_array (1 .. the_Sites'Length + 1); - the_Coords : constant Coordinates_2D := to_Coordinates (the_Sites); - Centroid : Vector_2 := (0.0, 0.0); + the_Vertices : Geometry.lit_textured.Vertex_array (1 .. the_Sites'Length + 1); + Coords_and_Centroid : constant Coords_2D_and_Centroid := to_Coordinates (the_Sites); + -- Centroid : Vector_2 := (0.0, 0.0); begin --- Calculate the centroid and min/max of x and y. -- - for i in the_Sites'Range - loop - Centroid := Centroid + the_Sites (i); - end loop; - - Centroid := Centroid / Real (the_Sites'Length); + -- for i in the_Sites'Range + -- loop + -- Centroid := Centroid + the_Sites (i); + -- end loop; + -- + -- Centroid := Centroid / Real (the_Sites'Length); for i in the_Sites'Range loop the_Vertices (Index_t (i)) := (Site => Vector_3 (the_Sites (i) & 0.0), Normal => Normal, - Coords => the_Coords (Index_t (i)), + Coords => Coords_and_Centroid.Coords (Index_t (i)), Shine => default_Shine); end loop; - the_Vertices (the_Vertices'Last) := (Site => Vector_3 (Centroid & 0.0), + the_Vertices (the_Vertices'Last) := (Site => Vector_3 (Coords_and_Centroid.Centroid & 0.0), Normal => Normal, Coords => (0.5, 0.5), Shine => default_Shine); @@ -173,7 +173,7 @@ is upper_Face := new_Face (Vertices => the_Vertices); end; - return (1 => upper_Face.all'Access); + return [1 => upper_Face.all'Access]; end to_GL_Geometries; diff --git a/3-mid/opengl/source/lean/opengl-texture-coordinates.adb b/3-mid/opengl/source/lean/opengl-texture-coordinates.adb index 7cfd427..86e045b 100644 --- a/3-mid/opengl/source/lean/opengl-texture-coordinates.adb +++ b/3-mid/opengl/source/lean/opengl-texture-coordinates.adb @@ -1,14 +1,14 @@ package body openGL.Texture.Coordinates is - function to_Coordinates (the_Vertices : in Vector_2_array) return Coordinates_2D + function to_Coordinates (the_Vertices : in Vector_2_array) return Coords_2D_and_Centroid is - Centroid : Vector_2 := (0.0, 0.0); - Min : Vector_2 := (Real'Last, Real'Last); - Max : Vector_2 := (Real'First, Real'First); + Centroid : Vector_2 := [0.0, 0.0]; + Min : Vector_2 := [Real'Last, Real'Last]; + Max : Vector_2 := [Real'First, Real'First]; Coords : Vector_2; - Result : Coordinates_2D (1 .. the_Vertices'Length); + Result : Coords_2D_and_Centroid (coords_Count => the_Vertices'Length); begin --- Calculate the centroid and min/max of x and y. -- @@ -16,44 +16,43 @@ is loop Centroid := Centroid + the_Vertices (i); - Min (1) := Real'Min (Min (1), - the_Vertices (i) (1)); - Min (2) := Real'Min (Min (2), - the_Vertices (i) (2)); + Min (1) := Real'Min (Min (1), the_Vertices (i) (1)); + Min (2) := Real'Min (Min (2), the_Vertices (i) (2)); - Max (1) := Real'Max (Max (1), - the_Vertices (i) (1)); - Max (2) := Real'Max (Max (2), - the_Vertices (i) (2)); + Max (1) := Real'Max (Max (1), the_Vertices (i) (1)); + Max (2) := Real'Max (Max (2), the_Vertices (i) (2)); end loop; + Centroid := Centroid / Real (the_Vertices'Length); + declare half_Width : constant Real := (Max (1) - Min (1)) / 2.0; half_Height : constant Real := (Max (2) - Min (2)) / 2.0; begin for i in the_Vertices'Range loop - Coords := the_Vertices (i) - Centroid; -- The centroid is now the origin. + Coords := the_Vertices (i) - Centroid; -- The centroid is now the origin. Coords (1) := Coords (1) / half_Width; Coords (2) := Coords (2) / half_Height; -- The coords are now in range -1.0 .. 1.0. - Coords (1) := (Coords (1) + 1.0) / 2.0; - Coords (2) := (Coords (2) + 1.0) / 2.0; -- The coords are now in range 0.0 .. 1.0. + Coords (1) := (Coords (1) + 1.0) / 2.0; + Coords (2) := (Coords (2) + 1.0) / 2.0; -- The coords are now in range 0.0 .. 1.0. - Result (Index_t (i)) := (Coords (1), Coords (2)); + Result.Coords (Index_t (i)) := (Coords (1), + Coords (2)); end loop; end; + + Result.Centroid := Centroid; return Result; end to_Coordinates; - - overriding function to_Coordinates (Self : in xz_Generator; the_Vertices : access Sites) return Coordinates_2D is diff --git a/3-mid/opengl/source/lean/opengl-texture-coordinates.ads b/3-mid/opengl/source/lean/opengl-texture-coordinates.ads index 9be1050..8663a9e 100644 --- a/3-mid/opengl/source/lean/opengl-texture-coordinates.ads +++ b/3-mid/opengl/source/lean/opengl-texture-coordinates.ads @@ -8,7 +8,14 @@ is --- 2D -- - function to_Coordinates (the_Vertices : in Vector_2_array) return Coordinates_2D; + type Coords_2D_and_Centroid (coords_Count : Index_t) is + record + Coords : Coordinates_2D (1 .. coords_Count); + Centroid : Vector_2; + end record; + + + function to_Coordinates (the_Vertices : in Vector_2_array) return Coords_2D_and_Centroid; -- -- Maps the vertices to texture coordinates.