graphics3d/camerashake
3D 카메라 흔들림. (vanilla.js graphics3d/camerashake.js 의 CameraShake 와 createOffsetViewMatrix)
- 유니티 Cinemachine Impulse, 언리얼 Camera Shake 꼴의 엔진 흔들림이다. 흔들림마다 자리 3 축과 돌림 3 축(pitch, yaw, roll)의 결, 세기, 주파수, 길이, 오름, 잦아듦을 따로 쥔다.
- 결: 축마다 주파수가 조금씩 다른 사인파 둘을 겹친다. 위상과 주파수 몫은 흔들림의 씨앗에서 뽑는다. (같은 씨앗, 같은 나이면 같은 값)
- 크기 곡선: 나이가 음수면 아직 0(그만큼 늦게 시작), attack 초 동안 0 에서 1 로 오르고, (1 - 나이 / 길이) 의 decay_exponent 제곱으로 잦아들어 길이에서 0.
- 겹침: 사는 흔들림을 모두 더한다. (센 쪽을 따르는 2D Shaker 와 다르다)
- 나이: CameraShakeOptions 의 age 는 이미 지난 초다. 결도 나이로 셈해 늦게 보인 사건을 그 나이로 넣으면 처음부터 넣은 것과 같은 값이 이어진다.
- 거는 곳: Camera3D::set_view_offset(자리, 돌림) 에 넣거나, 게임이 셈한 보기 행렬이면 create_offset_view_matrix 로 건다.
- 원본과 같은 씨앗이면 같은 값이 나온다. 씨앗을 주지 않은 흔들림은 바탕 SeededRandom 의 다음 값 x 2^32 을 내린 수를 씨앗으로 쓰고, 파 값 12 개(축 여섯마다 파 둘, 파마다 주파수 몫 다음 위상)를 그 씨앗의 SeededRandom 에서 원본과 같은 차례로 뽑는다. 사인은 크롬 Math.sin 과 같은 비트의 엔진 사인(base 의 바르게 반올림한 sin)이다.
- 원본과 다른 것: 원본 생성자의 { seed } 는 CameraShake::new(seed) 이고, add 의 칸 객체는 CameraShakeOptions(Default 가 원본 기본 값)다. 원본 read 의 { position, rotation } 은 CameraShakeOffset 이다. 씨앗은 원본 SeededRandom 처럼 u32 다.
3D camera shake. (CameraShake and createOffsetViewMatrix of vanilla.js graphics3d/camerashake.js)
- An engine shake in the shape of Unity Cinemachine Impulse and Unreal Camera Shake. Each shake holds its own signal, strength, frequency, duration, attack and decay for 3 position axes and 3 rotation axes (pitch, yaw, roll).
- Signal: two sine waves with slightly different frequencies are layered per axis. Phases and frequency ratios are drawn from the shake's seed. (same seed and same age give the same values)
- Envelope: 0 while the age is negative (starts that much later), rises from 0 to 1 over attack seconds, and decays as (1 - age / duration) to the power decay_exponent, reaching 0 at the duration.
- Overlap: all live shakes are summed. (unlike the 2D Shaker, which follows the stronger one)
- Age: age in CameraShakeOptions is the seconds already passed. The signal is also computed from the age, so an event seen late added with that age continues with the same values as if added from the start.
- Where to apply: pass it to Camera3D::set_view_offset(position, rotation), or apply it with create_offset_view_matrix to a view matrix the game computed.
- The same seed as the original gives the same values. A shake without a seed uses the floor of the base SeededRandom's next value x 2^32 as its seed, and draws 12 wave values (two waves per each of six axes, frequency ratio then phase per wave) from that seed's SeededRandom in the same order as the original. The sine is the engine sine with the same bits as Chrome Math.sin (the correctly rounded sin in base).
- Differences from the original: the original constructor's { seed } is CameraShake::new(seed), and the options object of add is CameraShakeOptions (Default is the original defaults). The original read's { position, rotation } is CameraShakeOffset. The seed is u32 like the original SeededRandom.
CameraShakeOptionsstruct traits Clone, Copy, PartialEq, Debug, Default
흔들림 하나의 칸. (CameraShake::add 에 준다, 원본 add 의 options, Default 가 원본 기본 값)
Fields of one shake. (passed to CameraShake::add, the options of the original add, Default is the original defaults)
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(1);
camera_shake.add(CameraShakeOptions { amplitude: 0.05, position_axes: [1.0, 0.3, 1.0], duration: 0.4, age: -0.1, ..Default::default() });
assert!(camera_shake.is_shaking());
assert_eq!(camera_shake.read().position.x, 0.0);자리 흔들림의 최대 길이. (장면 길이, 기본 0.1)
Maximum length of the position shake. (scene length, default 0.1)
반환Returnsf64
돌림 흔들림의 최대 각. (라디안, 기본 0)
Maximum angle of the rotation shake. (radians, default 0)
반환Returnsf64
자리 축마다의 몫. ([x, y, z] 카메라 지역 축 오른쪽, 위, 뒤, 기본 [1, 1, 1])
Share per position axis. ([x, y, z] camera local axes right, up, back, default [1, 1, 1])
반환Returns[f64; 3]
돌림 축마다의 몫. ([pitch, yaw, roll], 기본 [1, 1, 1])
Share per rotation axis. ([pitch, yaw, roll], default [1, 1, 1])
반환Returns[f64; 3]
0 에서 다 센 데까지 오르는 초. (기본 0)
Seconds to rise from 0 to full strength. (default 0)
반환Returnsf64
잦아듦 지수. ((1 - 나이 / 길이) 의 이 제곱, 1 이면 곧게, 0 이면 끝까지 그대로, 기본 2)
Decay exponent. ((1 - age / duration) to this power, 1 is linear, 0 stays the same until the end, default 2)
반환Returnsf64
이미 지난 초. (기본 0, 음수면 그만큼 늦게 시작)
Seconds already passed. (default 0, negative starts that much later)
반환Returnsf64
이 흔들림의 씨앗. (None 이면 바탕 씨앗에서 차례로 뽑음)
Seed of this shake. (None draws one in turn from the base seed)
반환ReturnsOption<u32>
CameraShakeOffsetstruct traits Clone, Copy, PartialEq, Debug, Default
지금의 흔들림 덧붙임. (CameraShake::read, 카메라 지역 축, 흔들림이 없으면 둘 다 영 벡터)
Current shake offset. (CameraShake::read, camera local axes, both zero vectors when there is no shake)
use vanilla::{CameraShake, CameraShakeOffset, Vector3};
let camera_shake = CameraShake::new(1);
let offset: CameraShakeOffset = camera_shake.read();
assert_eq!(offset.position, Vector3::zero());
assert_eq!(offset.rotation, Vector3::zero());자리. (장면 길이, x 오른쪽, y 위, z 뒤)
Position. (scene length, x right, y up, z back)
반환ReturnsVector3
돌림. (라디안, x pitch, y yaw, z roll)
Rotation. (radians, x pitch, y yaw, z roll)
반환ReturnsVector3
CameraShakestruct traits Clone, Debug, Default
3D 카메라 흔들림. (원본 CameraShake, 흔들림을 더하고 나이를 먹여 지금의 카메라 지역 덧붙임을 읽는다)
- add 로 흔들림 하나를 더하고, update(초) 로 나이를 먹이고 다 된 흔들림을 지운다. read() 가 지금의 덧붙임을 준다.
- 기본(Default)은 바탕 씨앗 1 이다. (원본 생성자 기본)
3D camera shake. (original CameraShake, adds shakes, ages them and reads the current offset in camera local axes)
- add adds one shake, update(seconds) ages them and removes finished shakes. read() gives the current offset.
- The default (Default) is base seed 1. (the original constructor default)
use vanilla::{Camera3D, CameraShake, CameraShakeOptions, Vector3};
let mut camera = Camera3D::new();
camera.set_perspective(std::f64::consts::PI / 3.0, 0.1, 500.0);
camera.look_at(Vector3::create(0.0, 4.0, 10.0), Vector3::zero(), Vector3::up());
let mut camera_shake = CameraShake::new(7);
camera_shake.add(CameraShakeOptions { amplitude: 0.09, rotation_amplitude: 0.01, duration: 0.25, position_axes: [1.0, 0.5, 1.0], ..Default::default() });
camera_shake.add(CameraShakeOptions { amplitude: 0.04, duration: 0.6, age: 0.1, ..Default::default() });
camera_shake.update(1.0 / 60.0);
let shake = camera_shake.read();
camera.set_view_offset(shake.position, shake.rotation);
let view_projection_matrix = camera.get_view_projection_matrix();
assert!(camera_shake.is_shaking());
assert_eq!(view_projection_matrix.get_elements().len(), 16);생성.
Constructor.
- seedu32
- 씨앗을 주지 않은 흔들림의 씨앗을 뽑을 바탕 씨앗. (원본 { seed } 기본 1, 0 이면 SeededRandom 처럼 1)Base seed for drawing the seeds of shakes given without one. (original { seed } default 1, 0 becomes 1 like SeededRandom)
반환ReturnsCameraShake 흔들림이 없는 새 흔들림 바탕.A new shake base with no shakes.
짝Counterpart: vanilla.js CameraShake.constructor
use vanilla::{CameraShake, CameraShakeOptions};
let mut first = CameraShake::new(42);
let mut second = CameraShake::new(42);
first.add(CameraShakeOptions::default());
second.add(CameraShakeOptions::default());
first.update(0.05);
second.update(0.05);
assert_eq!(first.read(), second.read());흔들림 더하기. (사는 흔들림에 겹쳐 더함)
Add a shake. (summed on top of the live shakes)
- optionsCameraShakeOptions
- 흔들림 칸. (세기, 돌림 세기, 축 몫, 주파수, 길이, 오름, 잦아듦 지수, 나이, 씨앗)Shake fields. (strength, rotation strength, axis shares, frequency, duration, attack, decay exponent, age, seed)
짝Counterpart: vanilla.js CameraShake.add
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(3);
camera_shake.add(CameraShakeOptions { amplitude: 0.0, rotation_amplitude: 0.05, rotation_axes: [1.0, 1.0, 0.0], seed: Some(9), ..Default::default() });
camera_shake.update(0.02);
let offset = camera_shake.read();
assert_eq!(offset.position.x, 0.0);
assert_eq!(offset.rotation.z, 0.0);
assert!(offset.rotation.x != 0.0);나이 먹이기. (다 된 흔들림을 지움)
Age the shakes. (removes finished shakes)
- secondsf64
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
짝Counterpart: vanilla.js CameraShake.update
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(1);
camera_shake.add(CameraShakeOptions { duration: 0.2, ..Default::default() });
camera_shake.update(0.1);
assert!(camera_shake.is_shaking());
camera_shake.update(0.1);
assert!(!camera_shake.is_shaking());지금의 덧붙임. (사는 흔들림을 모두 더함, 카메라 지역 축)
Current offset. (sum of all live shakes, camera local axes)
반환ReturnsCameraShakeOffset 자리(장면 길이, x 오른쪽, y 위, z 뒤)와 돌림(라디안, x pitch, y yaw, z roll). (흔들림이 없으면 둘 다 영 벡터)Position (scene length, x right, y up, z back) and rotation (radians, x pitch, y yaw, z roll). (both zero vectors when there is no shake)
짝Counterpart: vanilla.js CameraShake.read
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(5);
camera_shake.add(CameraShakeOptions { amplitude: 0.2, duration: 1.0, ..Default::default() });
camera_shake.update(0.1);
let offset = camera_shake.read();
assert!(offset.position.x.abs() <= 0.2 && offset.position.y.abs() <= 0.2 && offset.position.z.abs() <= 0.2);흔들림이 남았는지. (늦게 시작할 흔들림도 셈)
Whether any shake remains. (shakes that start later count too)
반환Returnsbool 사는 흔들림이 하나라도 있으면 true.true if there is at least one live shake.
짝Counterpart: vanilla.js CameraShake.isShaking
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(1);
assert!(!camera_shake.is_shaking());
camera_shake.add(CameraShakeOptions { age: -0.5, ..Default::default() });
assert!(camera_shake.is_shaking());모든 흔들림을 곧바로 멈추기.
Stop all shakes at once.
짝Counterpart: vanilla.js CameraShake.clear
use vanilla::{CameraShake, CameraShakeOptions};
let mut camera_shake = CameraShake::new(1);
camera_shake.add(CameraShakeOptions::default());
camera_shake.clear();
assert!(!camera_shake.is_shaking());함수Functions
pub fn create_offset_view_matrix(view_matrix: &Matrix4, position: Vector3, rotation: Vector3) -> Matrix4#보기 행렬에 카메라 지역 덧붙임 걸기. (카메라를 그 자리에서 position 만큼 옮기고 rotation 만큼 돌린 보기, 새 행렬)
- position 은 카메라 지역 축이다. (x 오른쪽, y 위, z 뒤, 카메라는 -Z 를 봄)
- rotation 은 카메라 지역 축의 각(라디안)이다. (x 는 pitch, y 는 yaw, z 는 roll, roll 다음 pitch 다음 yaw 로 건다)
- 덧붙인 카메라는 (카메라) x 옮김 x yaw x pitch x roll 이고, 보기 행렬은 그 역이라 (옮김 x yaw x pitch x roll) 의 역을 앞에 곱한다.
Apply an offset in camera local axes to a view matrix. (the view of the camera moved by position and rotated by rotation from where it is, a new matrix)
- position is in camera local axes. (x right, y up, z back, the camera looks down -Z)
- rotation is angles (radians) in camera local axes. (x is pitch, y is yaw, z is roll, applied roll then pitch then yaw)
- The offset camera is (camera) x translation x yaw x pitch x roll, and the view matrix is its inverse, so the inverse of (translation x yaw x pitch x roll) is multiplied in front.
- view_matrix&Matrix4
- 덧붙이기 앞의 보기 행렬. (월드 → 카메라, 고치지 않는다)View matrix before the offset. (world → camera, not modified)
- positionVector3
- 카메라 지역 자리 덧붙임. (장면 길이)Position offset in camera local axes. (scene length)
- rotationVector3
- 카메라 지역 돌림 덧붙임. (라디안, x pitch, y yaw, z roll)Rotation offset in camera local axes. (radians, x pitch, y yaw, z roll)
반환ReturnsMatrix4 덧붙인 보기 행렬. (새 행렬)Offset view matrix. (a new matrix)
짝Counterpart: vanilla.js createOffsetViewMatrix
use vanilla::{create_offset_view_matrix, Matrix4, Vector3};
let view_matrix = Matrix4::create_look_at(Vector3::create(0.0, 2.0, 6.0), Vector3::create(0.0, 1.0, 0.0), Vector3::create(0.0, 1.0, 0.0));
let shaken_view_matrix = create_offset_view_matrix(&view_matrix, Vector3::create(0.1, 0.0, 0.0), Vector3::create(0.02, 0.0, 0.0));
assert_eq!(shaken_view_matrix.get_elements().len(), 16);
assert_eq!(create_offset_view_matrix(&view_matrix, Vector3::zero(), Vector3::zero()).get_elements(), view_matrix.get_elements());