vanilladocs
vanillapunch.com
API / graphics3d/camerashake

graphics3d/camerashake

3D 카메라 흔들림. (유니티 Cinemachine Impulse, 언리얼 Camera Shake 꼴의 엔진 흔들림)

3D camera shake. (an engine shake in the form of Unity Cinemachine Impulse and Unreal Camera Shake)

CameraShake

짝Counterpart: vanilla-engine CameraShake

3D 카메라 흔들림. (유니티 Cinemachine Impulse, 언리얼 Camera Shake 꼴의 엔진 흔들림)

  • add(options) 로 흔들림 하나를 더한다. 흔들림마다 자리 3 축과 돌림 3 축(pitch, yaw, roll)의 결, 세기, 주파수, 길이, 오름, 잦아듦을 따로 쥔다.
  • 결: 축마다 주파수가 조금씩 다른 사인파 둘을 겹친다. 위상과 주파수 몫은 흔들림의 씨앗에서 뽑는다. (같은 씨앗, 같은 나이면 같은 값)
  • 크기 곡선: 나이가 음수면 아직 0(그만큼 늦게 시작), attack 초 동안 0 에서 1 로 오르고, (1 - 나이 / 길이) 의 decayExponent 제곱으로 잦아들어 길이에서 0.
  • 겹침: 사는 흔들림을 모두 더한다. (센 쪽을 따르는 2D Shaker 와 다르다)
  • 나이: options.age 는 이미 지난 초다. 결도 나이로 셈해 늦게 보인 사건을 그 나이로 넣으면 처음부터 넣은 것과 같은 값이 이어진다.
  • update(초) 로 나이를 먹이고 다 된 흔들림을 지운다. read() 가 지금의 덧붙임 { position, rotation } 을 준다. (카메라 지역 축)
  • 거는 곳: Camera3D.setViewOffset(position, rotation) 에 넣거나, 게임이 셈한 보기 행렬이면 createOffsetViewMatrix 로 건다.
  • 씨앗: options.seed 를 주지 않은 흔들림은 이 바탕의 씨앗(생성의 seed)에서 차례로 씨앗을 뽑는다.

3D camera shake. (an engine shake in the form of Unity Cinemachine Impulse and Unreal Camera Shake)

  • add(options) adds one shake. Each shake holds its own signal for 3 position axes and 3 rotation axes (pitch, yaw, roll), strength, frequency, duration, attack and decay.
  • Signal: each axis layers two sine waves with slightly different frequencies. Phases and frequency ratios are drawn from the shake's seed. (same seed and same age give the same value)
  • Envelope: 0 while age is negative (starts that much later), rises from 0 to 1 over attack seconds, decays as (1 - age / duration) to the power decayExponent and reaches 0 at duration.
  • Stacking: all live shakes are summed. (unlike the 2D Shaker, which follows the stronger one)
  • Age: options.age is the seconds already elapsed. The signal is also computed from age, so an event seen late and added with that age continues with the same values as if it had been added from the start.
  • update(seconds) advances ages and removes finished shakes. read() gives the current offset { position, rotation }. (camera local axes)
  • Where to apply: pass it to Camera3D.setViewOffset(position, rotation), or apply it with createOffsetViewMatrix to a view matrix the game computed.
  • Seed: a shake added without options.seed draws its seed in turn from this object's seed (the seed given at construction).
예제Example폭발 흔들림을 Camera3D 에 걸기Applying an explosion shake to Camera3D
import { CameraShake, Camera3D, Vector3 } from "./vanilla.js";
const camera = new Camera3D();
camera.setPerspective(Math.PI / 3, 0.1, 500);
camera.lookAt(Vector3.create(0, 4, 10), Vector3.create(0, 0, 0));
const cameraShake = new CameraShake({ seed: 7 });
cameraShake.add({ amplitude: 0.09, rotationAmplitude: 0.01, duration: 0.25, positionAxes: [1, 0.5, 1] });
cameraShake.add({ amplitude: 0.04, duration: 0.6, age: 0.1 });
cameraShake.update(1 / 60);
const shake = cameraShake.read();
camera.setViewOffset(shake.position, shake.rotation);
const viewProjectionMatrix = camera.getViewProjectionMatrix();
console.log(cameraShake.isShaking(), viewProjectionMatrix.getElements().length);
생성자constructorconstructor(options = {})#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

optionsobject
{ seed = 1 } 씨앗을 주지 않은 흔들림의 씨앗을 뽑을 바탕 씨앗.{ seed = 1 } base seed from which shakes without a seed draw theirs.

짝Counterpart: vanilla-engine CameraShake.new

메서드methodadd(options = {})#0.4.0 부터since 0.4.0소스source

흔들림 더하기. (사는 흔들림에 겹쳐 더함)

Adds a shake. (summed with the live shakes)

optionsobject
{ amplitude, rotationAmplitude, positionAxes, rotationAxes, frequency, duration, attack, decayExponent, age, seed } - amplitude: 자리 흔들림의 최대 길이. (장면 길이, 기본 0.1) - rotationAmplitude: 돌림 흔들림의 최대 각. (라디안, 기본 0) - positionAxes: [x, y, z] 자리 축마다의 몫. (카메라 지역 축 오른쪽, 위, 뒤, 기본 [1, 1, 1]) - rotationAxes: [pitch, yaw, roll] 돌림 축마다의 몫. (기본 [1, 1, 1]) - frequency: 주파수. (초당 번, 기본 10) - duration: 길이. (초, 기본 0.25) - attack: 0 에서 다 센 데까지 오르는 초. (기본 0) - decayExponent: 잦아듦 지수. (기본 2, (1 - 나이 / 길이) 의 이 제곱) - age: 이미 지난 초. (기본 0, 음수면 그만큼 늦게 시작) - seed: 이 흔들림의 씨앗. (없으면 바탕 씨앗에서 차례로 뽑음){ amplitude, rotationAmplitude, positionAxes, rotationAxes, frequency, duration, attack, decayExponent, age, seed } - amplitude: largest position offset. (scene length, default 0.1) - rotationAmplitude: largest rotation angle. (radians, default 0) - positionAxes: [x, y, z] share per position axis. (camera local axes right, up, back, default [1, 1, 1]) - rotationAxes: [pitch, yaw, roll] share per rotation axis. (default [1, 1, 1]) - frequency: frequency. (times per second, default 10) - duration: duration. (seconds, default 0.25) - attack: seconds to rise from 0 to full strength. (default 0) - decayExponent: decay exponent. (default 2, (1 - age / duration) to this power) - age: seconds already elapsed. (default 0, negative starts that much later) - seed: this shake's seed. (drawn in turn from the base seed when absent)

짝Counterpart: vanilla-engine CameraShake.add

메서드methodupdate(deltaTime)#0.4.0 부터since 0.4.0소스source

나이 먹이기. (다 된 흔들림을 지움)

Advances age. (removes finished shakes)

deltaTimenumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)

짝Counterpart: vanilla-engine CameraShake.update

메서드methodread()#0.4.0 부터since 0.4.0소스source

지금의 덧붙임. (사는 흔들림을 모두 더함, 카메라 지역 축)

The current offset. (sum of all live shakes, camera local axes)

반환Returnsobject { position: Vector3, rotation: Vector3 } 자리(장면 길이, x 오른쪽, y 위, z 뒤)와 돌림(라디안, x pitch, y yaw, z roll). (흔들림이 없으면 둘 다 영 벡터){ position: Vector3, rotation: Vector3 } 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-engine CameraShake.read

메서드methodisShaking()#0.4.0 부터since 0.4.0소스source

흔들림이 남았는지. (늦게 시작할 흔들림도 셈)

Whether any shake remains. (shakes that start later also count)

반환Returnsboolean 사는 흔들림이 하나라도 있으면 true.true if at least one shake is live.

짝Counterpart: vanilla-engine CameraShake.is_shaking

메서드methodclear()#0.4.0 부터since 0.4.0소스source

모든 흔들림을 곧바로 멈추기.

Stops all shakes at once.

짝Counterpart: vanilla-engine CameraShake.clear

함수Functions

함수functioncreateOffsetViewMatrix(viewMatrix, position, rotation)#0.4.0 부터since 0.4.0소스source

보기 행렬에 카메라 지역 덧붙임 걸기. (카메라를 그 자리에서 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) 의 역을 앞에 곱한다.

Applies an offset in camera local axes to a view matrix. (the view of the camera moved by position and turned by rotation in place, 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.
viewMatrixMatrix4
덧붙이기 앞의 보기 행렬. (월드 → 카메라, 고치지 않는다)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 덧붙인 보기 행렬. (새 행렬)The offset view matrix. (new matrix)

짝Counterpart: vanilla-engine create_offset_view_matrix

예제Example보기 행렬을 오른쪽으로 0.1, 고개를 0.02 라디안 들어 덧붙이기Offsetting a view matrix 0.1 to the right and tilting the head up by 0.02 radians
import { createOffsetViewMatrix, Matrix4, Vector3 } from "./vanilla.js";
const viewMatrix = Matrix4.createLookAt(Vector3.create(0, 2, 6), Vector3.create(0, 1, 0), Vector3.create(0, 1, 0));
const shakenViewMatrix = createOffsetViewMatrix(viewMatrix, Vector3.create(0.1, 0, 0), Vector3.create(0.02, 0, 0));
console.log(shakenViewMatrix.getElements().length);