diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift index 56d0d25..21d5495 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitView.swift @@ -13,6 +13,7 @@ import UIKit class ArKitView : ARView { + var vmArkit:VMArkit? required init(frame frameRect: CGRect) { super.init(frame: frameRect) @@ -22,8 +23,9 @@ class ArKitView : ARView { fatalError("init(coder:) not implemented") } - convenience init() { + convenience init(_ vmArkit:VMArkit){ self.init(frame: UIScreen.main.bounds) + self.vmArkit = vmArkit } func applyConfiguration() { @@ -57,8 +59,22 @@ class ArKitView : ARView { switch translationGesture.state { case .began: self.initialTransform = entity.transform + case .ended: 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: break } diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift index b11817f..9d3da78 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ArKitViewRepresentable.swift @@ -8,20 +8,23 @@ import Foundation import SwiftUI import DouShouQiModel +import ARKit +import RealityKit +import UIKit struct ArKitViewRepresentable : UIViewRepresentable { - var vm:VMArkit + let vmArkit:VMArkit - init(_ game:Game){ - vm = VMArkit(game) + init(_ vmArkit:VMArkit){ + self.vmArkit = vmArkit } func makeUIView(context: Context) -> ArKitView { - let arView = ArKitView() + let arView = ArKitView(vmArkit) let anchor = arView.defineAnchors() - vm.setup(anchor) - arView.addGesture(vm.pieces) + vmArkit.setup(anchor) + arView.addGesture(vmArkit.pieces) return arView } diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift index d0e9f97..aaf6e94 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/ContentArkit.swift @@ -10,12 +10,12 @@ import DouShouQiModel 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 { VStack { Text("toto") - ArKitViewRepresentable(try! Game(withRules: ClassicRules(), andPlayer1: RandomPlayer(withName: "Bot1", andId: .player1)!, andPlayer2: RandomPlayer(withName: "Bot2", andId: .player2)!)) + ArKitViewRepresentable(vm) } } } diff --git a/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift b/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift index c5cc548..a93ed64 100644 --- a/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift +++ b/ArkitDoushiQi/ArkitDoushiQi/ArKit/VMArkit.swift @@ -123,11 +123,11 @@ struct VMArkit { } func convertPosModeleIntoWorldPos(pos:CGPoint) -> SIMD3 { - return SIMD3(Float(VMArkit.offset.x + VMArkit.direction.dx * pos.x),Float(VMArkit.offset.y + VMArkit.direction.dy * pos.y),10) + return SIMD3(Float(VMArkit.offset.x + VMArkit.direction.dx * pos.x),0.02,Float(VMArkit.offset.y + VMArkit.direction.dy * pos.y)) } func converWorldPosIntoPosModele(pos:SIMD3) -> CGPoint { 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) }