Fix bad texture coordinates in raster-12 #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
The Cube Model defines the triangle vertexes forming its top face in a different way to its other faces. It makes no difference for the demos where the cube faces are solid colors, but it is a problem in raster-12.html, when textures are introduced. It results in one of the top face triangles displaying the wrong part of the texture.
To see the problem, change the camera position on line 859 to:
var camera = Camera(Vertex(-1.5, 2, 3.5), MakeOYRotationMatrix(0));
You may also need to increase the ambient light on line 876 to better see the problem, e.g.:
Light(LT_AMBIENT, 0.6),
It's easier to see if you add code to rotate the camera around the X axis so you can move it above the cube and point it down.
For the record, raster-06.html to raster-09.html use the same vertex code; raster-10.html reorders the lines of the code block, but the vertexes are unchanged; and raster-11.html and raster-12.html use the same order as raster-06.html to raster-09.html, but change the vertexes for both triangles of the purple (top) cube face.
Fix in this PR
This PR fixes the problem by reordering the triangle vertexes on the top cube face. Although the problem is only visible on raster-12.html, the PR makes similar changes to raster-06.html to raster-12.html so the definition of cube vertexes remains consistent. One disadvantage to this approach is that eagle-eyed readers may notice that the triangles defining cube tops are drawn from different corners than shown in the figures in chapters 10 and 11.
Alternative Fix
If you prefer a smaller workaround rather than this fix, reject this PR and correct what I believe was an attempt at a workaround for just raster-12.html. It reorders the texture coordinates (not the vertexes), on line 844, but it unfortunately modifies the wrong triangle. Undo the bad workaround and implement it correctly by changing lines 843 and 844 to:
In case you are wondering how I found the problem, it was because I was puzzled why the texture coordinates on line 844 of raster-12.html didn't follow the pattern of the other triangles.