misc/shaker
흔들림 발생기. (화면 / 노드 공용)
- 원본 misc/shaker.js 를 옮긴 것이다. 위상이 다른 두 사인파로 x / y 오프셋을 만들고 지수 감쇠로 잦아들게 한다.
- add_shake(strength) 로 세기를 더하고, 매 프레임 tick(time_delta) 뒤 get_offset() 을 카메라나 노드 위치에 더해 쓴다.
- 원본과 다른 점: 생성자의 options 객체({ decay_rate, frequency })는 ShakerOptions 구조체다. 비운 값은 ..ShakerOptions::default() 로 채운다.
let shaker = Shaker::new(ShakerOptions { decay_rate: 10.0, ..ShakerOptions::default() });Shake generator. (shared by screen / nodes)
- A port of the original misc/shaker.js. Makes x / y offsets from two sine waves with different phases and lets them die down with exponential decay.
- Add strength with add_shake(strength), and every frame after tick(time_delta), add get_offset() to a camera or node position.
- Differences from the original: The constructor's options object ({ decay_rate, frequency }) is the ShakerOptions struct. Omitted values are filled with ..ShakerOptions::default().
let shaker = Shaker::new(ShakerOptions { decay_rate: 10.0, ..ShakerOptions::default() });ShakerOptionsstruct traits Clone, Copy, Debug, PartialEq, Default
흔들림 설정. (원본 options = { decay_rate = 9, frequency = 42 })
Shake settings. (original options = { decay_rate = 9, frequency = 42 })
use vanilla::{Shaker, ShakerOptions};
let shaker_options = ShakerOptions {
decay_rate: 10.0,
..ShakerOptions::default()
};
assert_eq!(shaker_options.frequency, 42.0);
let shaker = Shaker::new(shaker_options);
assert!(!shaker.is_shaking());감쇠율. (클수록 빨리 잦아든다)
Decay rate. (the larger, the faster it dies down)
반환Returnsf64
Shakerstruct traits Clone, Debug, Default
흔들림 발생기.
- add_shake 로 세기를 넣고 매 프레임 tick 한 뒤 get_offset 을 카메라나 노드 위치에 더한다.
Shake generator.
- Put in strength with add_shake, and after tick every frame add get_offset to a camera or node position.
use vanilla::{Shaker, ShakerOptions, Vector2};
let mut shaker = Shaker::new(ShakerOptions {
decay_rate: 10.0,
..ShakerOptions::default()
});
shaker.add_shake(8.0);
shaker.tick(0.1);
let offset = shaker.get_offset();
assert!(offset.x.abs() <= 8.0);
assert!(offset.y.abs() <= 8.0);
while shaker.is_shaking() {
shaker.tick(0.1);
}
assert_eq!(shaker.get_offset(), Vector2::zero());생성.
Constructor.
- optionsShakerOptions
- 감쇠율과 주파수.Decay rate and frequency.
반환ReturnsShaker 흔들리지 않는(세기 0) 새 흔들림 발생기.A new shake generator that is not shaking (strength 0).
짝Counterpart: vanilla.js Shaker.constructor
흔들림 더하기. (최대 오프셋 픽셀. 이미 흔들리는 중이면 더 센 쪽을 따른다)
Adds a shake. (maximum offset in pixels. If already shaking, the stronger one wins)
- strengthf64
- 흔들림 세기. (최대 오프셋, 픽셀) 지금 세기보다 작으면 무시한다.Shake strength. (maximum offset, pixels) Ignored if less than the current strength.
짝Counterpart: vanilla.js Shaker.addShake
갱신. (세기가 0.05 아래로 떨어지면 멈춘다)
Update. (stops when the strength drops below 0.05)
- time_deltaf64
- 지난 시간. (초, 세기에 exp(-decay_rate * time_delta) 를 곱한다)Elapsed time. (seconds, the strength is multiplied by exp(-decay_rate * time_delta))
짝Counterpart: vanilla.js Shaker.tick
지금 오프셋 반환. (두 축의 주파수 비를 1 : 1.37 로 달리 두어 궤적이 단조롭지 않게 한다)
Returns the current offset. (the two axes use a frequency ratio of 1 : 1.37 so the path is not monotonous)
반환ReturnsVector2 더할 오프셋. (픽셀, 각 축 -세기 ~ 세기) 흔들리지 않으면 (0, 0).Offset to add. (pixels, -strength ~ strength per axis) (0, 0) if not shaking.
짝Counterpart: vanilla.js Shaker.getOffset
흔들리는 중인지.
Whether it is shaking.
반환Returnsbool 세기가 0 보다 크면 true.true if the strength is greater than 0.
짝Counterpart: vanilla.js Shaker.isShaking
감쇠율 설정. (클수록 빨리 잦아든다)
Sets the decay rate. (larger fades faster)
- decay_ratef64
- 새 감쇠율. (초당 지수 감쇠 계수)New decay rate. (exponential decay coefficient per second)
짝Counterpart: vanilla.js Shaker.setDecayRate
진동 주파수 설정.
Sets the oscillation frequency.
- frequencyf64
- 새 진동 주파수. (라디안/초, y 축은 이것의 1.37 배)New oscillation frequency. (radians/second, the y axis is 1.37 times this)
짝Counterpart: vanilla.js Shaker.setFrequency