I am drawing a series of rows from the bottom of the screen towards the top. Each row contains single row of pixels that span the entire width of the screen (number of pixels is equal to the x resolution). I would like the rows to combine and represent a floor plane at the player’s feet. The problem is that I am unable to correctly calculate the uv coordinates for each row and could use some help.

The approach is as follows

- For each row
- Calculate the world coordinates at the bottom left of the row
- Calculate the world coordinates at the bottom right of the row
- Use a dot product to find the uv coordinates on the plane surface

This results in the following image which does not give the effect of standing on a flat plane but instead looking up a steep surface

The underlying code is

```
const float numRays = 320; // One ray for each column of pixels denoted by X resolution
const float inverseNumRaysMinusOne = 1f / (numRays - 1f);
var numRows = 256f; // Number of rows that make up the plane
var distance = 100f; // Distance of farthest row
var dz = distance / numRows; // Delta distance between each row
// Calculate vector to far left column on the screen
var col = 0;
var offset1 = 2f * col * inverseNumRaysMinusOne - 1f;
var dir1 = forward + perpendicular * (halfWidth * offset1);
dir1 *= dz;
// Calculate vector to far right column on the screen
col = 319;
var offset2 = 2f * col * inverseNumRaysMinusOne - 1f;
var dir2 = forward + perpendicular * (halfWidth * offset2);
dir2 *= dz;
var rowPoint1 = camera.Position; // Ray starts at camera pos
var rowPoint2 = camera.Position; //
var grid = 128f; // Used to tile texture over a 128x128 grid
for (var i = 0; i < numRows; ++i) // Start from bottom of the screen (closest to camera position)
{
rowPoint1 += dir1;
rowPoint2 += dir2;
// Tile uv over grid
var texCoordinates = new Vector4
{
x = Vector2.Dot(rowPoint1, camera.right) / grid,
y = Vector2.Dot(rowPoint1, camera..up) / grid,
z = Vector2.Dot(rowPoint2, camera.right) / grid,
w = Vector2.Dot((rowPoint2 + dir2), camera.up) / grid,
};
DrawRow(i, SCREEN_X_MIN, SCREEN_X_MAX, texCoordinates, texName);
}
```

Where have my calculations gone wrong?