Plug in an MDLCamera in place of hard coded transforms
This commit is contained in:
parent
44b5f46c9a
commit
552864eb09
1 changed files with 8 additions and 2 deletions
|
|
@ -48,6 +48,7 @@ class Renderer: NSObject, MTKViewDelegate {
|
||||||
var projectionMatrix: matrix_float4x4 = matrix_float4x4()
|
var projectionMatrix: matrix_float4x4 = matrix_float4x4()
|
||||||
var rotation: Float = 0
|
var rotation: Float = 0
|
||||||
|
|
||||||
|
var camera = MDLCamera()
|
||||||
var terrain: Terrain
|
var terrain: Terrain
|
||||||
|
|
||||||
var drawLines = true {
|
var drawLines = true {
|
||||||
|
|
@ -110,6 +111,11 @@ class Renderer: NSObject, MTKViewDelegate {
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
camera.nearVisibilityDistance = 0.1
|
||||||
|
camera.farVisibilityDistance = 100
|
||||||
|
camera.focalLength = 50
|
||||||
|
camera.look(at: float3(0), from: float3(0, 2, 8))
|
||||||
|
|
||||||
populateLights()
|
populateLights()
|
||||||
populateMaterials()
|
populateMaterials()
|
||||||
}
|
}
|
||||||
|
|
@ -211,11 +217,11 @@ class Renderer: NSObject, MTKViewDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
geometryUniforms.pointer[0].projectionMatrix = projectionMatrix
|
geometryUniforms.pointer[0].projectionMatrix = camera.projectionMatrix
|
||||||
|
|
||||||
let rotationAxis = float3(0, 1, 0)
|
let rotationAxis = float3(0, 1, 0)
|
||||||
let modelMatrix = matrix4x4_rotation(radians: rotation, axis: rotationAxis)
|
let modelMatrix = matrix4x4_rotation(radians: rotation, axis: rotationAxis)
|
||||||
let viewMatrix = matrix4x4_translation(0.0, -2.0, -8.0)
|
let viewMatrix = camera.transform!.matrix.inverse
|
||||||
let modelViewMatrix = simd_mul(viewMatrix, modelMatrix)
|
let modelViewMatrix = simd_mul(viewMatrix, modelMatrix)
|
||||||
geometryUniforms.pointer[0].modelViewMatrix = modelViewMatrix
|
geometryUniforms.pointer[0].modelViewMatrix = modelViewMatrix
|
||||||
rotation += 0.003
|
rotation += 0.003
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue