In trying to create a little floor perspective thingy using a Mesh, I've encountered an issue; seems that it's rendering it a bit odd, showing the seam between the mesh's triangles and also skewing the UV mapping?
Here's the source for the bit that generates the quad; note that in the first function, "frame" is a number that just refers to which tile in the sheet we want to grab the UVs for (starting at 1, top left, and going left to right, top to bottom, till the very bottom right tile):
Code: Select all
function ExploreState:getUVsByFrame(texture, frame, tileHeight, tileWidth)
local textureWidth = texture:getWidth()
local textureHeight = texture:getHeight()
local tilesPerRow = textureWidth / 32
local tilesPerColumn = textureHeight / 32
local numTiles = tilesPerRow * tilesPerColumn
local x = frame % tilesPerRow + 1
local y = math.floor(frame / tilesPerRow)
local xIncrement = 1 / tilesPerRow
local yIncrement = 1 / tilesPerColumn
local topLeft = {
xIncrement * x, yIncrement * y
}
print_r(topLeft)
local topRight = {
xIncrement * x + xIncrement, yIncrement * y
}
print_r(topRight)
local bottomRight = {
xIncrement * x + xIncrement, yIncrement * y + yIncrement
}
print_r(bottomRight)
local bottomLeft = {
xIncrement * x, yIncrement * y + yIncrement
}
print_r(bottomLeft)
return topLeft, topRight, bottomRight, bottomLeft;
end
function ExploreState:createFloorVertices()
local topLeft, topRight, bottomRight, bottomLeft =
self:getUVsByFrame(gTextures['tiles'], 1179, 32, 32)
return {
{
-- top-left corner
0, 0,
topLeft[1], topLeft[2],
255, 255, 255
},
{
-- top-right corner
128, 0,
topRight[1], topRight[2],
255, 255, 255
},
{
-- bottom-right corner
256, 128,
bottomRight[1], bottomRight[2],
255, 255, 255
},
{
-- bottom-left corner
-128, 128,
bottomLeft[1], bottomLeft[2],
255, 255, 255
}
}
end
function ExploreState:renderMap()
-- render the ground and the ceiling
love.graphics.clear()
love.graphics.draw(self.meshes['floor1'], virtualWidth / 2 - 64, virtualHeight / 2 + 16)
end