Created
January 31, 2021 19:38
-
-
Save sturdysturge/763f147309b2e01b9d0044f10a68c303 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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