pull/28/head^2
Your Name 10 months ago
parent 61961bbd5f
commit cc17fd1f4b

@ -13,6 +13,7 @@ import UIKit
class ArKitView : ARView { class ArKitView : ARView {
var vmArkit:VMArkit?
required init(frame frameRect: CGRect) { required init(frame frameRect: CGRect) {
super.init(frame: frameRect) super.init(frame: frameRect)
@ -22,8 +23,9 @@ class ArKitView : ARView {
fatalError("init(coder:) not implemented") fatalError("init(coder:) not implemented")
} }
convenience init() { convenience init(_ vmArkit:VMArkit){
self.init(frame: UIScreen.main.bounds) self.init(frame: UIScreen.main.bounds)
self.vmArkit = vmArkit
} }
func applyConfiguration() { func applyConfiguration() {
@ -57,8 +59,22 @@ class ArKitView : ARView {
switch translationGesture.state { switch translationGesture.state {
case .began: case .began:
self.initialTransform = entity.transform self.initialTransform = entity.transform
case .ended: case .ended:
entity.move(to: initialTransform, relativeTo: entity.parent, duration: 1) entity.move(to: initialTransform, relativeTo: entity.parent, duration: 1)
let pos = entity.position
if ( pos.x > )
if (localisation.x > 450 || localisation.x < -450 || localisation.y < -350 || localisation.y > 350){
print("Hors limite !")
self.position = returnPositionByCellPos(cellX:Int(self.cellPosition.x),cellY:Int(self.cellPosition.y))
return
}
default: default:
break break
} }

@ -8,20 +8,23 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
import DouShouQiModel import DouShouQiModel
import ARKit
import RealityKit
import UIKit
struct ArKitViewRepresentable : UIViewRepresentable { struct ArKitViewRepresentable : UIViewRepresentable {
var vm:VMArkit let vmArkit:VMArkit
init(_ game:Game){ init(_ vmArkit:VMArkit){
vm = VMArkit(game) self.vmArkit = vmArkit
} }
func makeUIView(context: Context) -> ArKitView { func makeUIView(context: Context) -> ArKitView {
let arView = ArKitView() let arView = ArKitView()
let anchor = arView.defineAnchors() let anchor = arView.defineAnchors()
vm.setup(anchor) vmArkit.setup(anchor)
arView.addGesture(vm.pieces) arView.addGesture(vmArkit.pieces)
return arView return arView
} }

@ -10,12 +10,12 @@ import DouShouQiModel
struct ContentArkit: View { struct ContentArkit: View {
//var vm:VMArkit = VMArkit(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!)) var vm:VMArkit = VMArkit(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!))
var body: some View { var body: some View {
VStack { VStack {
Text("toto") Text("toto")
ArKitViewRepresentable(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!)) ArKitViewRepresentable(vm)
} }
} }
} }

@ -123,11 +123,11 @@ struct VMArkit {
} }
func convertPosModeleIntoWorldPos(pos:CGPoint) -> SIMD3<Float> { func convertPosModeleIntoWorldPos(pos:CGPoint) -> SIMD3<Float> {
return SIMD3<Float>(Float(VMArkit.offset.x + VMArkit.direction.dx * pos.x),Float(VMArkit.offset.y + VMArkit.direction.dy * pos.y),10) return SIMD3<Float>(Float(VMArkit.offset.x + VMArkit.direction.dx * pos.x),0.02,Float(VMArkit.offset.y + VMArkit.direction.dy * pos.y))
} }
func converWorldPosIntoPosModele(pos:SIMD3<Float>) -> CGPoint { func converWorldPosIntoPosModele(pos:SIMD3<Float>) -> CGPoint {
let posX = Int(round((CGFloat(pos.x) - (VMArkit.offset.x)) / VMArkit.direction.dx)) let posX = Int(round((CGFloat(pos.x) - (VMArkit.offset.x)) / VMArkit.direction.dx))
let posY = Int(round((CGFloat(pos.y) - (VMArkit.offset.y)) / VMArkit.direction.dy)) let posY = Int(round((CGFloat(pos.z) - (VMArkit.offset.y)) / VMArkit.direction.dy))
return CGPoint(x: posX, y: posY) return CGPoint(x: posX, y: posY)
} }

Loading…
Cancel
Save