All Projects → VamshiIITBHU14 → Basketballarkit

VamshiIITBHU14 / Basketballarkit

Hello Everyone, This project talks about basics of ARKit introduced by Apple in iOS11. Please note that ARKit is only capable wih devices which use A9, A10, A11 chips .It shows how to build a basic BasketBall app using ARKit. All written in Swift4.

Programming Languages

swift
15916 projects
swift4
162 projects

Projects that are alternatives of or similar to Basketballarkit

DreamBig
☁🌝☁ 3D emoji drawing iPad app with ARKit and the Apple Pencil ☁🌝☁
Stars: ✭ 24 (-42.86%)
Mutual labels:  ios11, arkit
Simple-ARKit-Game
No description or website provided.
Stars: ✭ 13 (-69.05%)
Mutual labels:  ios11, arkit
ARKitPhysics
ARKit Demo for Physics
Stars: ✭ 21 (-50%)
Mutual labels:  ios11, arkit
ARichMan
Use ARKit to realize your dream of becoming rich.
Stars: ✭ 19 (-54.76%)
Mutual labels:  ios11, arkit
Ios 11 By Examples
👨🏻‍💻 Examples of new iOS 11 APIs
Stars: ✭ 3,327 (+7821.43%)
Mutual labels:  ios11, arkit
iOS-ARKit
Basic Concepts and Projects using ARKit on iOS.
Stars: ✭ 18 (-57.14%)
Mutual labels:  ios11, arkit
ar-resume-with-visual-recognition
An augmented reality based résumé with Face recognition. The iOS app recognizes the face and presents you with the AR view that contains 3D mock face and details of your resume.
Stars: ✭ 71 (+69.05%)
Mutual labels:  ios11, arkit
Arkit Floorislava
Basic ARKit example that detects planes and makes them lava.
Stars: ✭ 120 (+185.71%)
Mutual labels:  ios11, arkit
Arkit
ARKit Base Project. Place virtual objects based on WWDC example project
Stars: ✭ 297 (+607.14%)
Mutual labels:  ios11, arkit
Argithubcommits
Show your GitHub commit records in 3D with ARKit and SceneKit. 用 ARKit 展示你的 GitHub 提交图
Stars: ✭ 280 (+566.67%)
Mutual labels:  ios11, arkit
unity-arkit-charts-demo
iOS 11 ARKit Charts Demo
Stars: ✭ 13 (-69.05%)
Mutual labels:  ios11, arkit
Arpaint
Draw with bare fingers in the air using ARKit
Stars: ✭ 672 (+1500%)
Mutual labels:  ios11, arkit
Measurearkit
An example of measuring app with ARKit in iOS 11
Stars: ✭ 220 (+423.81%)
Mutual labels:  ios11, arkit
cARd
Flip your card with ARKit
Stars: ✭ 22 (-47.62%)
Mutual labels:  ios11, arkit
Arkit Unity3d
Access ARKit features like world-tracking, live video rendering, plane estimation and updates, hit-testing API, ambient light estimation, and raw point cloud data.
Stars: ✭ 124 (+195.24%)
Mutual labels:  ios11, arkit
titanium-arkit
Use the iOS 11 ARKit API in Axway Titanium
Stars: ✭ 28 (-33.33%)
Mutual labels:  ios11, arkit
Measurethings
ARKit framework demo for our article
Stars: ✭ 97 (+130.95%)
Mutual labels:  ios11, arkit
Arplayer
Playback videos using ARKit and AVFoundation.
Stars: ✭ 117 (+178.57%)
Mutual labels:  ios11, arkit
Arbottlejump
An ARKit version of WeChat Bottle Jump game. ARKit 版微信跳一跳游戏
Stars: ✭ 259 (+516.67%)
Mutual labels:  ios11, arkit
Measure
Using ARKit to make calculate the distance of real-world objects
Stars: ✭ 357 (+750%)
Mutual labels:  ios11, arkit

BasketBallARKit

Hello Everyone, This project talks about basics of ARKit introduced by Apple in iOS11. Please note that ARKit is only capable wih devices which use A9, A10, A11 chips and the devices that use these chips are:

a) iPhone 6s and 6s Plus b) iPhone 7 and 7 Plus c) iPhone SE d) iPad Pro (9.7, 10.5 or 12.9) – both first-gen and 2nd-gen e) iPad (2017) f) iPhone 8 and 8 Plus g) iPhone X

Now coming to the project, it shows how to build a basic BasketBall app using ARKit. Taking it step by step:

PS: Please note that we have to choose Augmented Reality App as template when you create the project.

  1. Camera Permission:

This step involves asking for permission from user for his Camera access. This can be done by adding 'Privacy - Camera Usage Description : This application will use the camera for Augmented Reality' as key-value in pair in info.plist

  1. Adding the hoop:

After you launch the app, you just see the world infront of you through phone's camera. Now you can augment a Basketball hoop by just adding the code below:

func addBackboard(){
        guard  let backboardScene = SCNScene(named:"art.scnassets/hoop.scn") else{return}
        guard let backboardNode = backboardScene.rootNode.childNode(withName: "backboard", recursively: false) else{return}
        backboardNode.position = SCNVector3(x:0.0, y:0.5, z:-3)
        
        let physicsShape = SCNPhysicsShape(node: backboardNode, options: [SCNPhysicsShape.Option.type : SCNPhysicsShape.ShapeType.concavePolyhedron])
        let physicsBody = SCNPhysicsBody(type: .static, shape: physicsShape)
        backboardNode.physicsBody = physicsBody
        
        sceneView.scene.rootNode.addChildNode(backboardNode)
        currentNode = backboardNode
    }
screen shot 2017-12-11 at 1 55 52 pm

Then we add a Tap Gesture onto the SceneView to aim the ball at the basket.

func registerTapGestureRecogniser(){
        let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(gesture:)))
        sceneView.addGestureRecognizer(tap)
    }
    
    @objc func handleTap(gesture:UIRotationGestureRecognizer){
        //scene view to be accessed
        //access the center point of the sceneview
        guard let sceneView = gesture.view as? ARSCNView else{return}
        guard let centerPoint = sceneView.pointOfView else{return}
        
        let cameraTransform = centerPoint.transform
        let cameraLocation = SCNVector3(x:cameraTransform.m41, y: cameraTransform.m42, z:cameraTransform.m43)
        let cameraOrientation = SCNVector3(x: -cameraTransform.m31, y: -cameraTransform.m32, z: -cameraTransform.m33)
        let cameraPosition = SCNVector3Make(cameraLocation.x + cameraOrientation.x, cameraLocation.y + cameraOrientation.y , cameraLocation.z + cameraOrientation.z)
        
        let ball = SCNSphere()
        let material = SCNMaterial()
        material.diffuse.contents = UIImage(named:"basketballSkin.png")
        ball.materials = [material]
        
        let ballNode = SCNNode(geometry:ball)
        ballNode.position = cameraPosition
        
        let physcisShape = SCNPhysicsShape(geometry: ball, options: nil)
        let physicsBody = SCNPhysicsBody(type: .dynamic, shape: physcisShape)
        
        ballNode.physicsBody = physicsBody
        let forceVector:Float = 6
        ballNode.physicsBody?.applyForce(SCNVector3(x:cameraOrientation.x * forceVector, y:cameraOrientation.y * forceVector, z: cameraOrientation.z * forceVector), asImpulse:true)
        
        sceneView.scene.rootNode.addChildNode(ballNode)
        
    }

diffuse property of SCNMaterial deals with how light is rendered on the material and contents property deals with the actual parents of the material

screen shot 2017-12-11 at 3 23 44 pm

Optional:

Moving objects in AR Space is really straight forward. Here I am posting two methods to move the hoop in XY plane in a horizontal and circuit manner:

func horizontalAction (node:SCNNode){
        let leftAction = SCNAction.move(by: SCNVector3(x:-1, y:0, z:0), duration: 2)
        let rightAction = SCNAction.move(to: SCNVector3(x:1, y:0, z:0), duration: 2)
        let actionSequence = SCNAction.sequence([leftAction , rightAction])
        node.runAction(SCNAction.repeat(actionSequence, count: 2))
    }
func roundAction(node:SCNNode){
       let upright = SCNAction.move(by: SCNVector3(x:1, y:1, z:0), duration: 2)
       let downright = SCNAction.move(to: SCNVector3(x:1, y:-1, z:0), duration: 2)
       let downLeft = SCNAction.move(by: SCNVector3(x:-1, y:-1, z:0), duration: 2)
       let upLeft = SCNAction.move(to: SCNVector3(x:-1, y:1, z:0), duration: 2)
       let actionSequence = SCNAction.sequence([upright , downright , downLeft , upLeft])
       node.runAction(SCNAction.repeat(actionSequence, count: 2))
   }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].