Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 31, 2021 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/763f147309b2e01b9d0044f10a68c303 to your computer and use it in GitHub Desktop.
Save sturdysturge/763f147309b2e01b9d0044f10a68c303 to your computer and use it in GitHub Desktop.
import SwiftUI
import RealityKit
struct AnyViewRepresentable<T: UIView>: UIViewRepresentable {
let makeUIView: () -> T
func makeUIView(context: Context) -> T { makeUIView() }
func updateUIView(_ uiView: T, context: Context) { }
}
extension ContentView {
var newOrientation: simd_quatf {
simd_quatf(angle: rotation.degreesToRadians, axis: SIMD3<Float>(0,1,0))
}
func rotationChanged() {
DispatchQueue.main.async {
if rotation < 1 { rotation = 358 }
else if rotation > 358 { rotation = 1 }
}
let newOrientation = simd_quatf(angle: rotation.degreesToRadians, axis: SIMD3<Float>(0,1,0))
boxAnchor.taxi?.setOrientation(newOrientation, relativeTo: nil)
}
func onTimer() {
if moving {
boxAnchor.taxi?.move(to: boxAnchor.taxi?.transformMatrix(relativeTo: nil) ?? simd_float4x4()
.movedForwardPosition(speed: speed), relativeTo: nil)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment