Terrain grid goes between -1 and 1

This commit is contained in:
Eryn Wells 2018-11-03 15:07:21 -04:00
parent 49783610e7
commit dff9e5d3bf

View file

@ -45,15 +45,28 @@ class Terrain: NSObject {
let (cellWidth, cellHeight) = (Float(2.0) / Float(size.width), Float(2.0) / Float(size.height)) let (cellWidth, cellHeight) = (Float(2.0) / Float(size.width), Float(2.0) / Float(size.height))
for y in 0..<Int(size.height) { for y in 0..<Int(size.height) {
for x in 0..<Int(size.width) { for x in 0..<Int(size.width) {
vertexes.append(Float3(x: Float(x) * cellWidth, y: Float(y) * cellHeight, z: 0.0)) vertexes.append(Float3(x: -1 + Float(x) * cellWidth,
vertexes.append(Float3(x: Float(x) * cellWidth, y: Float(y) * cellHeight + cellHeight, z: 0.0)) y: -1 + Float(y) * cellHeight,
vertexes.append(Float3(x: Float(x) * cellWidth + cellWidth, y: Float(y) * cellHeight, z: 0.0)) z: 0.0))
vertexes.append(Float3(x: Float(x) * cellWidth + cellWidth, y: Float(y) * cellHeight, z: 0.0)) vertexes.append(Float3(x: -1 + Float(x) * cellWidth,
vertexes.append(Float3(x: Float(x) * cellWidth, y: Float(y) * cellHeight + cellHeight, z: 0.0)) y: -1 + Float(y) * cellHeight + cellHeight,
vertexes.append(Float3(x: Float(x) * cellWidth + cellWidth, y: Float(y) * cellHeight + cellHeight, z: 0.0)) z: 0.0))
vertexes.append(Float3(x: -1 + Float(x) * cellWidth + cellWidth,
y: -1 + Float(y) * cellHeight,
z: 0.0))
vertexes.append(Float3(x: -1 + Float(x) * cellWidth + cellWidth,
y: -1 + Float(y) * cellHeight,
z: 0.0))
vertexes.append(Float3(x: -1 + Float(x) * cellWidth,
y: -1 + Float(y) * cellHeight + cellHeight,
z: 0.0))
vertexes.append(Float3(x: -1 + Float(x) * cellWidth + cellWidth,
y: -1 + Float(y) * cellHeight + cellHeight,
z: 0.0))
} }
} }
buffer.label = "Terrain Vertex Data"
self.buffer = buffer self.buffer = buffer
memcpy(buffer.contents(), vertexes, expectedLength) memcpy(buffer.contents(), vertexes, expectedLength)
} }