func (c *Camera) Tick() { moveSpeed := float32(0.1) movement := [4]float32{} if input.IsKeyDown(glfw.KeyUp) || input.IsKeyDown('W') { movement[2] += moveSpeed } if input.IsKeyDown(glfw.KeyDown) || input.IsKeyDown('S') { movement[2] -= moveSpeed } if input.IsKeyDown(glfw.KeyLeft) || input.IsKeyDown('A') { movement[0] -= moveSpeed } if input.IsKeyDown(glfw.KeyRight) || input.IsKeyDown('D') { movement[0] += moveSpeed } c.UpdateRotation() m := matrix.MakeRotationMatrix(c.pitch, 1, 0, 0) m = m.Multiply(matrix.MakeRotationMatrix(c.yaw, 0, 1, 0)) movement = m.MultiplyPoint(movement) c.eyePosition[0] += movement[0] c.eyePosition[1] += movement[1] c.eyePosition[2] += movement[2] c.UpdateModelViewMatrix() }
func (c *Camera) UpdateModelViewMatrix() { c.modelViewMatrix = matrix.MakeRotationMatrix(c.pitch, 1, 0, 0) c.modelViewMatrix = c.modelViewMatrix.Multiply(matrix.MakeRotationMatrix(c.yaw, 0, 1, 0)) c.modelViewMatrix = c.modelViewMatrix.Multiply(matrix.MakeTranslationMatrix(-c.eyePosition[0], -c.eyePosition[1], -c.eyePosition[2])) c.modelViewMatrix.Transpose() }