Skip to content

Commit

Permalink
Add SphereNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilot-Marc committed Nov 28, 2019
1 parent 6142e7a commit daefdad
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
34 changes: 31 additions & 3 deletions ARKit+CoreLocation/POIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class POIViewController: UIViewController {
@IBOutlet weak var nodePositionLabel: UILabel!

@IBOutlet var contentView: UIView!
let sceneLocationView = SceneLocationView()
let sceneLocationView = SceneLocationView(trackingType: .orientationTracking)

var userAnnotation: MKPointAnnotation?
var locationEstimateAnnotation: MKPointAnnotation?
Expand All @@ -46,7 +46,7 @@ class POIViewController: UIViewController {
let displayDebugging = false

let adjustNorthByTappingSidesOfScreen = false
let addNodeByTappingScreen = true
let addNodeByTappingScreen = false

class func loadFromStoryboard() -> POIViewController {
return UIStoryboard(name: "Main", bundle: nil)
Expand Down Expand Up @@ -230,10 +230,13 @@ extension POIViewController {
return box
}
} else {
// 3. If not, then show the
// 3. If not, then show the fixed demo objects
buildDemoData().forEach {
sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: $0)
}
buildNewDemoData().forEach {
sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: $0)
}
}

// There are many different ways to add lighting to a scene, but even this mechanism (the absolute simplest)
Expand Down Expand Up @@ -266,6 +269,27 @@ extension POIViewController {
return nodes
}

/// Builds the location annotations for a few random objects, scattered across the country
///
/// - Returns: an array of location nodes.
func buildNewDemoData() -> [LocationNode] {
var nodes: [LocationNode] = []

let currentCoordinates = sceneLocationView.sceneLocationManager.currentLocation!.coordinate

let greenCircle2D = currentCoordinates.coordinateWithBearing(bearing: 20, distanceMeters: (6.0).nauticalMilesToMeters)
let greenCircle3D = CLLocation(coordinate: greenCircle2D, altitude: 300)
let greenCircleNode = buildSphereNode(location: greenCircle3D, radius: (1.0).nauticalMilesToMeters, color: .green)
nodes.append(greenCircleNode)

let yellowCircle2D = currentCoordinates.coordinateWithBearing(bearing: 350, distanceMeters: (6.0).nauticalMilesToMeters)
let yellowCircle3D = CLLocation(coordinate: yellowCircle2D, altitude: 300)
let yellowCircleNode = buildSphereNode(location: yellowCircle3D, radius: (1.0).nauticalMilesToMeters, color: .yellow)
nodes.append(yellowCircleNode)

return nodes
} // buildNewDemoData() -? [LocationNode]

@objc
func updateUserLocation() {
guard let currentLocation = sceneLocationView.sceneLocationManager.currentLocation else {
Expand Down Expand Up @@ -344,6 +368,10 @@ extension POIViewController {
return LocationAnnotationNode(location: location, image: image)
}

func buildSphereNode(location: CLLocation, radius: CLLocationDistance, color: UIColor) -> SphereNode {
return SphereNode(location: location, radius: radius, color: color)
}

func buildViewNode(latitude: CLLocationDegrees, longitude: CLLocationDegrees,
altitude: CLLocationDistance, text: String) -> LocationAnnotationNode {
let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
Expand Down
4 changes: 4 additions & 0 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Foundation

public extension Double {
var short: String { return String(format: "%.02f", self) }
var feetToMeters: Double { return self * 0.3048 }
var metersToFeet: Double { return self * 3.28084 }
var nauticalMilesToMeters: Double { return self * 1852.0 }
var metersToNauticalMiles: Double { return self / 1852.0 }
}

public extension Float {
Expand Down
38 changes: 38 additions & 0 deletions Sources/ARKit-CoreLocation/Nodes/SphereNode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SphereNode.swift
// ARCL
//
// Created by Marc Alexander on 11/27/19.
//

import Foundation
import CoreLocation
import ARKit

public class SphereNode: LocationNode {

public init(location: CLLocation, radius: CLLocationDistance, color: UIColor) {
print(#function)
super.init(location: location)

let geometry = SCNSphere(radius: CGFloat(radius)) // The node's geometry
geometry.firstMaterial?.diffuse.contents = color

let shapeNode = SCNNode(geometry: geometry) // Attach geometry to shape node
shapeNode.name = ""
shapeNode.removeFlicker()

addChildNode(shapeNode) // Attach shape node to ourself

} // init(location:radius:color:)

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

deinit {
print(#function)

} // deinit

} // SphereNode class

0 comments on commit daefdad

Please sign in to comment.