Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/developeracademy-postech/2024-nc2-m23-corehaptics


https://github.com/developeracademy-postech/2024-nc2-m23-corehaptics

Last synced: about 13 hours ago
JSON representation

Awesome Lists containing this project

README

        

# 2024-NC2-M0-AugmentedReality
## πŸ‘« Pair

| 이름 | 이지(μž„μ΄μ§€) | 뉴쀀성(κΉ€μ€€μ„±) |
| ---- | ---- | ---- |
| **ν”„λ‘œν•„ 사진** | | |
| **μ—­ν• ** | λ””μžμΈ | ν…Œν¬ |
| **GitHub** | [@ez](https://github.com/izzy0426) | [@newJunsung](https://github.com/newJunsung) |
## πŸŽ₯ Youtube Link
(μΆ”ν›„ λ§Œλ“€μ–΄μ§„ 유튜브 링크 μΆ”κ°€)

## πŸ’‘ About Core Haptics
(ν•΄λ‹Ή κΈ°μˆ μ— λŒ€ν•œ 쑰사 λ‚΄μš© 정리)

- 이벀트λ₯Ό 기반으둜 ν•œ μ˜€λ””μ˜€ / ν–…ν‹± λžœλ”λ§ API
- κΈ°λ³Έ 햅틱이 μ—¬λŸ¬ μΈν„°νŽ˜μ΄μŠ€ μš”μ†Œμ— μžλ™μœΌλ‘œ λ“€μ–΄κ°€ μžˆμ§€λ§Œ, Core Haptics λ₯Ό μ‚¬μš©ν•˜λ©΄ 기본적인 νŒ¨ν„΄μ„ λ„˜μ–΄μ„œ 촉각(진동)κ³Ό μ†Œλ¦¬ ν”Όλ“œλ°±κ³Ό 같은 **햅틱을 μ»€μŠ€ν…€**ν•΄μ„œ κΈ°λŠ₯을 ν™•μž₯ν•  수 μžˆλ‹€.
- 햅틱을 일관성 있게 μ‚¬μš©ν•΄μ•Όν•˜λ©°, κ³Όλ„ν•œ μ‚¬μš©μ€ μ§€μ–‘ν•œλ‹€.
- μ‚¬μš©μžμ˜ λͺ°μž…도λ₯Ό λ†’μ—¬μ€€λ‹€.
- μ§€μ›ν•˜λŠ” ν•˜λ“œμ›¨μ–΄ 인지 확인이 ν•„μš”ν•˜λ‹€.

- **CoreHaptics**μ—λŠ” μ†Œλ¦¬μ™€ 진동을 μ‹€ν–‰μ‹œν‚¬ 수 μžˆλŠ” 것을 μ•Œκ²Œ 됨.
- `CHHapticEngine을` μ΄μš©ν•΄μ„œ μ†Œλ¦¬ 및 진동을 κ΄€λ¦¬ν•˜λŠ” ν•˜λ“œμ›¨μ–΄λ₯Ό μ œμ–΄ν•  수 μžˆλ‹€λŠ” 것을 μ•Œκ²Œ 됨.
- `CHHapticPattern` μ†Œλ¦¬ 및 진동에 λŒ€ν•œ νŒ¨ν„΄μ„ λ§Œλ“€ 수 μžˆλ‹€λŠ” 것을 μ•Œκ²Œ 됨.
- `CHHapticPatternPlayer`을 μ΄μš©ν•˜μ—¬ 햅틱에 λŒ€ν•œ νŒ¨ν„΄μ„ μž¬μƒν•  수 μžˆλ‹€λŠ” 것을 μ•Œκ²Œ 됨.

## 🎯 What we focus on?

보쑰적인 μˆ˜λ‹¨μ΄ μ•„λ‹Œ ν–…ν‹± μžμ²΄μ—μ„œ 재미λ₯Ό 찾고자 ν–ˆμŒ. **CoreHaptics**에 진동과 μ†Œλ¦¬ 쀑, 진동에 쀑점을 λ‘κΈ°λ‘œ 함.
`CHHapticEventParameter`을 μ΄μš©ν•˜μ—¬ νŠΉμ • intensity, sharpness, duration을 가진 진동 이벀트λ₯Ό λ§Œλ“€κ³ , 이λ₯Ό `CHHapticPatternPlayer둜` λ§Œλ“€κ³  μ‹€ν–‰μ‹œν‚€κ³ μž 함.
μ‚¬μš©μžκ°€ λžœλ€ν•œ(λ˜λŠ” μƒλŒ€λ°©μ΄ λ§Œλ“€μ–΄λ‚Έ) 진동을 λ§žμΆ”λ©° 재미λ₯Ό 느끼게 ν•˜κ³ μž 함.

## πŸ’Ό Use Case
- CoreHaptics κΈ°μˆ μ„ μ΄μš©ν•˜μ—¬ 심심할 λ•Œ 진동을 λ§ˆμŒλŒ€λ‘œ μ‘°μ ˆν•˜λ©° 가지고 놀 수 있게 ν•˜λŠ” μ•±

> πŸ’‘ **μ ˆλŒ€μ§„κ°**

- μž„μ˜λ‘œ μ£Όμ–΄μ§€λŠ” 진동을 intensity와 sharpness, duration의 쑰정을 톡해 λ§žμΆ˜λ‹€.
- intensity와 sharpness, duration의 μ‘°μ •μœΌλ‘œ μƒˆλ‘œμš΄ 진동을 λ§Œλ“€κ³  κ³΅μœ ν•œλ‹€.
- μΉœκ΅¬κ°€ κ³΅μœ ν•œ 진동을 intensity와 sharpness, duration의 μ‘°μ •μœΌλ‘œ λ§žμΆ˜λ‹€.

## πŸ–ΌοΈ Prototype
(ν”„λ‘œν† νƒ€μž…κ³Ό μ„€λͺ… μΆ”κ°€)
![nc2 프로토ᄐᅑ압](https://github.com/DeveloperAcademy-POSTECH/2024-NC2-M23-CoreHaptics/assets/107932188/f58471cf-4bb3-4130-a233-c8aae348eb00)
1. **1인 λͺ¨λ“œ**
1. 컴퓨터가 λžœλ€ν•˜κ²Œ μ œκ³΅ν•˜λŠ” 진동 λ“£κΈ°
2. μ‚¬μš©μžκ°€ μ»€μŠ€ν…€ν•œ 진동 λ“£κΈ°
3. Intensity, Sharpeness, Duration μ„€μ •ν•˜κΈ°
4. μ»€μŠ€ν…€ν•œ 진동을 μ œμΆœν•œ ν›„ κ²°κ³Ό ν™•μΈν•˜κΈ°
5. μ‹€νŒ¨ν•œ 경우 μž¬μ‹œλ„ν•˜κΈ°
2. **2인 λͺ¨λ“œ**
1. νŽ˜μ΄μŠ€νƒ€μž„μ„ 톡해 SharePlay μ—°κ²°ν•˜κΈ°
2. Intensity, Sharpeness, Duration을 μ‘°μ •ν•˜μ—¬ λ‚˜μ˜ 진동 μ»€μŠ€ν…€ν•˜κΈ°
3. λ‚˜μ˜ μ§„λ™μ˜ 이름을 λ°”κΎΈκ³  μƒλŒ€μ—κ²Œ κ³΅μœ ν•˜κΈ°
4. μƒλŒ€κ°€ κ³΅μœ ν•œ 진동을 λ°›κ³  λ“£κΈ°
5. Intensity, Sharpeness, Duration을 μ‘°μ •ν•˜μ—¬ μƒλŒ€μ˜ 진동 λ§žμΆ”κΈ°
6. μ»€μŠ€ν…€ν•œ 진동을 μ œμΆœν•œ ν›„ κ²°κ³Ό ν™•μΈν•˜κΈ°
7. μ‹€νŒ¨ν•œ 경우 μž¬μ‹œλ„ν•˜κΈ°

## πŸ“±μ•± μ‹œν˜„

https://github.com/DeveloperAcademy-POSTECH/2024-NC2-M23-CoreHaptics/assets/107932188/0c2064a8-386a-40fa-b7be-92af2222b512

## πŸ› οΈ About Code
- 햅틱을 μ§€μ›ν•˜μ§€ μ•ŠλŠ” κΈ°μ’… λ“±μ˜ 이유둜 `HapticManager`λ₯Ό λ§Œλ“€ 수 μ—†λŠ” 상황이 되면, `nil`을 λ°˜ν™˜ν•˜κ²Œλ” 함.
```swift
// HapticManager.swift

init?() {
do {
let capablitity = CHHapticEngine.capabilitiesForHardware()

if capablitity.supportsHaptics {
let engine = try CHHapticEngine()
self.engine = engine
try engine.start()
print("haptic manager return.")
} else {
print("haptic manager nil.")
return nil
}
} catch {
print(error)
return nil
}
}
```

- ν”„λ‘œν† μ½œμ„ λ§€κ°œλ³€μˆ˜λ‘œ λ°›μ•„μ„œ λ‹€μ–‘ν•œ νƒ€μž…μ„ 받을 수 있게 함. (λ¬Όλ‘ , ν•΄λ‹Ή ν”„λ‘œν† μ½œμ„ 채택해야 함.)
```swift
// HapticManager.swift

func haptic(
type: CHHapticEvent.EventType,
intensity: Float,
sharpness: Float,
duration: Float
) throws {
stop()

let eventParams = [
CHHapticEventParameter(parameterID: .hapticIntensity, value: intensity),
CHHapticEventParameter(parameterID: .hapticSharpness, value: sharpness)
]
let event = CHHapticEvent(eventType: .hapticContinuous, parameters: eventParams, relativeTime: 0, duration: TimeInterval(duration))
let pattern = try CHHapticPattern(events: [event], parameters: [])

player = try engine.makePlayer(with: pattern)
start()
}

func haptic(for param: HapticEventParameterable) throws {
try haptic(
type: .hapticContinuous,
intensity: param.intensity, sharpness: param.sharpness,
duration: param.duration
)
}
```

### 클래슀 λ‹€μ΄μ–΄κ·Έλž¨
```mermaid
classDiagram

class ContentViewModel {
+ hapticsPublisher: AnyPublisher
- bind()
+ onAppear()
+ playHaptic()
+ resetHaptic()
+ send()
+ startSharing()
+ checkSubmit()
+ changeMode()
}

class HapticManager {
- engine: CHHapticEngine
- player: CHHapticPatternPlayer?
+ haptic()
+ start()
+ stop()
}

class GameTogetherManager {
+ session: GroupSession?
- messenger: GroupSessionMessenger?
+ hapticPublisher: AnyPublisher

+ startSharing()
+ setSessions()
+ send()
- configureSession
- handle()
}

ContentView --|> ContentViewModel
ContentViewModel --|> HapticManager
ContentViewModel --|> GameTogetherManager
```