2011-06-26 13:46:16 -04:00
[[Category Packet]]
[[Category Packet 317]]
2012-07-28 09:44:56 -04:00
{{packet|name=Camera Oscillate|description=Makes the camera shake.|opcode=35|type=Fixed|length=4|revision=317}}
2012-01-05 12:42:58 -05:00
== Load Map Region ==
2011-06-26 13:46:16 -04:00
=== Description ===
2012-07-28 09:44:56 -04:00
description=Begins camera oscillation, which is implemented using a configurable sinusoidal oscillator that advances once per render.
2011-06-26 13:46:16 -04:00
2012-01-05 12:42:58 -05:00
=== Packet Structure ===
{| border=2
! Data type
! Description
|-
| [[Data Types#Standard data types|Byte]]
2012-07-28 09:44:56 -04:00
| Parameter (camera X, Z, Y, yaw, pitch)
2012-01-05 12:42:58 -05:00
|-
| [[Data Types#Standard data types|Byte]]
2012-07-28 09:44:56 -04:00
| Jitter - for randomization
2012-01-05 12:42:58 -05:00
|-
| [[Data Types#Standard data types|Byte]]
2012-07-28 09:44:56 -04:00
| Amplitude
2012-01-05 12:42:58 -05:00
|-
| [[Data Types#Standard data types|Byte]]
2012-07-28 09:44:56 -04:00
| Frequency (scaled by 100)
2012-01-05 12:42:58 -05:00
|-
|}
=== Other Information ===
2012-07-28 09:44:56 -04:00
The oscillate event enables the client to oscillate one of 5 of it's position parameters, i.e. corresponding to the camera's degrees of freedom; parameters 0, 1, and 2 refer to the location of the camera, while 3 and 4 deal with the camera's orientation. Together, these enable complex effects involving manipulation of the camera position to give rise to simulated earth-quakes and camera shock.
2012-01-05 12:42:58 -05:00
{| border=2
2012-07-28 09:44:56 -04:00
! Parameter
2012-01-05 12:42:58 -05:00
! Description
|-
| 0
2012-07-28 09:44:56 -04:00
| Camera location along world X axis (a horizontal axis, aligned with map grid X)
2012-01-05 12:42:58 -05:00
|-
| 1
2012-07-28 09:44:56 -04:00
| Camera location along world Z axis (vertical axis)
2012-01-05 12:42:58 -05:00
|-
| 2
2012-07-28 09:44:56 -04:00
| Camera location along world Y axis (a horizontal axis, aligned with map grid Y)
2012-01-05 12:42:58 -05:00
|-
| 3
2012-07-28 09:44:56 -04:00
| Camera orientation in world X plane w.r.t. world Z axis, i.e. yaw
2012-01-05 12:42:58 -05:00
|-
| 4
2012-07-28 09:44:56 -04:00
| Camera orientation in world Z plane w.r.t. world X axis, i.e. pitch
2012-01-05 12:42:58 -05:00
|-
|}
2012-07-28 09:44:56 -04:00
Note there is no built-in way to manipulate camera roll, as this is not one of the camera's degrees of freedom.
2012-01-05 12:42:58 -05:00
=== What it's doing ===
2012-07-28 09:44:56 -04:00
Every time the world is rendered, each camera parameter that is enabled for oscillation is offset by a value computed as follows:
2012-01-05 12:42:58 -05:00
{| border=2
! Calculation
! Formula
|-
2012-07-28 09:44:56 -04:00
| Delta
| (int) ((Math.random() * (double) (jitter * 2 + 1) - (double) jitter) + Math.sin((double) phase * ((double) frequency / 100D)) * (double) amplitude);
2012-01-05 12:42:58 -05:00
|-
|}
2012-07-28 09:44:56 -04:00
Each parameter's phase accumulator (phase) is incremented by 1 each logic update.
2012-01-05 12:42:58 -05:00
2012-07-28 09:44:56 -04:00
=== Parameter ===
The offset itself is detailed as follows for each parameter:
2012-01-05 12:42:58 -05:00
{| border=2
2012-07-28 09:44:56 -04:00
! Parameter
2012-01-05 12:42:58 -05:00
! Action
|-
| 0
2012-07-28 09:44:56 -04:00
| camera_x += delta
2012-01-05 12:42:58 -05:00
|-
| 1
2012-07-28 09:44:56 -04:00
| camera_z += delta
2012-01-05 12:42:58 -05:00
|-
| 2
2012-07-28 09:44:56 -04:00
| camera_y += delta
2012-01-05 12:42:58 -05:00
|-
| 3
2012-07-28 09:44:56 -04:00
| camera_yaw = camera_yaw + delta & 0x7ff;
2012-01-05 12:42:58 -05:00
|-
| 4
2012-07-28 09:44:56 -04:00
| camera_pitch += delta
2012-01-05 12:42:58 -05:00
|-
|}
2012-07-28 09:44:56 -04:00
Note that the camera's yaw is corrected modulo 0x7ff, or 2048, which is equivalent to 2{{{pi}}} radians in Jagex's binary angle system.
This is not done to the camera pitch, which is instead clamped (see below).
2012-01-05 12:42:58 -05:00
=== Note ===
2012-07-28 09:44:56 -04:00
For oscillating the camera pitch, clamping is done to ensure the angle not out of bounds:
2012-01-05 12:42:58 -05:00
{| border=2
|-
2012-07-28 09:44:56 -04:00
|if (camera_pitch < 128) then camera_pitch = 128
2012-01-05 12:42:58 -05:00
|-
2012-07-28 09:44:56 -04:00
|if (camera_pitch > 383) then camera_pitch = 383
2012-01-05 12:42:58 -05:00
|-
2012-07-28 09:44:56 -04:00
|}
This is do to Jagex restricting the possible range of orientations the camera may take.