-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointOfInterestComponent.swift
More file actions
59 lines (46 loc) · 1.63 KB
/
PointOfInterestComponent.swift
File metadata and controls
59 lines (46 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
A component that marks an entity as a point of interest on the diorama map.
*/
import RealityKit
import SwiftUI
public enum Region: String, Codable, CaseIterable {
case yosemite
case catalina
public func opacity(forSliderValue sliderValue: Float) -> Float {
switch self {
case .yosemite: return 1.0 - sliderValue
case .catalina: return sliderValue
}
}
public func gain(forSliderValue sliderValue: Float) -> Audio.Decibel {
let fullyOn: Audio.Decibel = 0
let fullyOff: Audio.Decibel = -100
switch self {
case .yosemite: return Audio.Decibel.lerp(a: fullyOn, b: fullyOff, t: Audio.Decibel(sliderValue))
case .catalina: return Audio.Decibel.lerp(a: fullyOff, b: fullyOn, t: Audio.Decibel(sliderValue))
}
}
}
public extension FloatingPoint {
static func lerp(a: Self, b: Self, t: Self) -> Self {
let one = Self(1)
let oneMinusT = one - t
let aTimesOneMinusT = a * oneMinusT
let bTimesT = b * t
return aTimesOneMinusT + bTimesT
}
}
public struct PointOfInterestComponent: Component, Codable {
public var region: Region = .yosemite
public var name: String = "Learn More"
public var description: String? = nil
public var mainImageName: String? = nil
public var secondImageName: String? = nil
public var thirdImageName: String? = nil
public var imageNames: [String] {
[mainImageName, secondImageName, thirdImageName].compactMap({ $0 })
}
public init() {}
}