farice / arshooter Goto Github PK
View Code? Open in Web Editor NEWA demo Augmented Reality shooter made with ARKit in Swift (iOS 11)
Home Page: http://farice.github.io
License: Apache License 2.0
A demo Augmented Reality shooter made with ARKit in Swift (iOS 11)
Home Page: http://farice.github.io
License: Apache License 2.0
Just forked and receiving:
Cannot invoke initializer for type 'SCNMatrix4' with an argument list of type '(matrix_float4x4)'
Played around a bit with manual init, but not keen on extracting and typing the variables.
hey, i'm just having a black screen, with the box(picture) and i can shoot but nothing else, nothing is moving either
ViewController.swift:175:23: 'SCNMatrix4FromMat4' is unavailable in Swift
i run you code on iphone6 with ios11 beta,but camera preview is not show,why?
Hi, I was looking for ways to implement projectiles in my ARKit project and stumbled across your ViewController. I saw that in the method getUserVector
, the direction property was set based on positions: m31, 32, and 33 of the camera transform matrix and I was wondering how you figured this out. I wasn't able to find it anywhere I looked in any documentation, article or video. Is there some sort of documentation on the properties of this matrix you found? Sorry to open a new issue. I hope I'm not bugging you, I was just insanely curious about that one line (which helped me a lot, thank you!).
Cheers, Harry
Is there a way to remove old bullet nodes? I have been looking around the project and can't seem to figure out how to do it. Without this functionality, there are a bunch of "bullets" flying around.
2017-06-07 18:40:19.329904+0800 ARViewer[771:115352] -[MTLTextureDescriptorInternal validateWithDevice:], line 778: error 'MTLTextureDescriptor has invalid pixelFormat (520).'
-[MTLTextureDescriptorInternal validateWithDevice:]:778: failed assertion `MTLTextureDescriptor has invalid pixelFormat (520).'
on iPhone5s , but iPhone5s simulator is ok
Possibility to shoot where the screen was tapped and add a small amount of gravity? I tried adding it but it was a dramatic drop.
A simple enhancement is adding sound effects using AVFoundation. I added 3 basic sound effects, torpedo.mp3 (bullet sound), explosion.mp3 , collison.mp3.
sound effects available:
torpedo.mp3
explosion.mp3
collision.mp3
import AVFoundation
var Player: AVAudioPlayer = AVAudioPlayer()
// added this basic code snippet in three places just change the forResource for each mp3 name.
do
{
let MusicURL = Bundle.main.path(forResource: "torpedo", ofType: "mp3")
try Player = AVAudioPlayer(contentsOf: NSURL (fileURLWithPath:MusicURL!) as URL)
Player.prepareToPlay()
Player.play()
}
catch let error as NSError {
print(error.description)
}
1st spot. after
@IBAction func didTapScreen(_ sender: UITapGestureRecognizer) { // fire bullet in direction camera is facing
2nd spot. after
func removeNodeWithAnimation(_ node: SCNNode, explosion: Bool) {
if explosion {
3rd spot after
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
//print("did begin contact", contact.nodeA.physicsBody!.categoryBitMask, contact.nodeB.physicsBody!.categoryBitMask)
if contact.nodeA.physicsBody?.categoryBitMask == CollisionCategory.ship.rawValue || contact.nodeB.physicsBody?.categoryBitMask == CollisionCategory.ship.rawValue { // this conditional is not required--we've used the bit masks to ensure only one type of collision takes place--will be necessary as soon as more collisions are created/enabled
do
{
Thats it!
Awesome Repo. Thanks! I'm looking for some more information around the "getUserVector()" method.
Firstly -- SCNMatrxi4.mat31, mat32, mat33, etc. are not available anymore. Xcode shows me that I must use SCNMatrix4.columns.1.x, which Is confusing -- I don't know how to convert to the m31 matrix syntax with the new columns approach.
My main issue is that I'm having a real hard time finding in the Apple docs what exactly all 16 elements represent in the 4x4 transform matrices, for example the ARcamera.transform matrix. How did you know that m31, m32, and m33 are the orientation of the camera, and that m41, m42, m43 are the position? Lastly, as mentioned above -- these coordinates would need to be converted to the new columns.0.y syntax, which again seem to be poorly documented in any apple doc. I feel like I'm missing some holy grail for Matrix Transforms from apple.
Thank you so much!
func getUserVector() -> (SCNVector3, SCNVector3) { // (direction, position)
if let frame = self.sceneView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space
let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33) // orientation of camera in world space
let pos = SCNVector3(mat.m41, mat.m42, mat.m43) // location of camera in world space
return (dir, pos)
}
return (SCNVector3(0, 0, -1), SCNVector3(0, 0, -0.2))
}
let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space
Error:
Cannot invoke initializer for type 'SCNMatrix4' with an argument list of type '(matrix_float4x4)'
I get this error when I try to build your project on my machine.
Open the project,
Prompt bug:Cannot invoke initializer for type 'SCNMatrix4' with an argument list of type '(matrix_float4x4)'...
Can you see?A great god
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.