frame-tick
Fixed-point representation of time where each second is divided into
3,603,600 Tick
s (or 25,200, if the cargo
feature low_res
is set).
This crate was inspired by this article from Inigo Quilez. Please refer to this for a more detailed explanation.
Note that the default for
TICKS_PER_SECOND
, 3,603,600, is the Least Common Multiple of all numbers in the list given in the article as well as 11 and 13, which are needed for NTSC.
This makes it 'compatible' with lots of frame- and refresh rates without ever mapping outside of or repeating a frame. That is: without strobing.
In particular, a Tick
can represent exactly:
-
24hz and 48hz, great for movie playback.
-
6hz, 8hz and 12hz, great for animating on 4s, 3s and 2s.
-
29.97hz, 59.94hz NTSC found in Japan, South Korea and the USA.
-
30hz, 60hz, for internet video and TV in the USA.
-
25hz and 50hz, for TV in the EU.
-
72hz, for Oculus Quest 1.
-
90hz for Quest 2, Rift and other headsets.
-
120hz, 144hz and 240hz, for newer VR headesets and high frequency monitors.
-
And many more.
Examples
use ;
let tick = from_secs;
/// A round trip is lossless.
assert_eq!;
/// One second at 120hz == frame № 120.
assert_eq!;
Cargo features
-
float_frame_rate
— Add support for non-integer frame rates. This pulls in thetyped_floats
crate. -
low_res
—TICKS_PER_SECOND
will be25_600
. Which is just fine if you do not need to work with NTSC frame rates. -
serde
— Add support for serialization viaserde
. -
std
— Use std; this implements Display as well asFrom<Tick>
/Into<Tick>
forstd::time::Duration
.
License
Apache-2.0 or BSD-3-Clause or MIT or Zlib at your discretion.