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

@ -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
}

@ -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 anchor = arView.defineAnchors()
vm.setup(anchor)
arView.addGesture(vm.pieces)
vmArkit.setup(anchor)
arView.addGesture(vmArkit.pieces)
return arView
}

@ -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)
}
}
}

@ -123,11 +123,11 @@ struct VMArkit {
}
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 {
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)
}

Loading…
Cancel
Save