Gods Bezier Table Format

From ModdingWiki
Jump to navigation Jump to search

BEZIER.DAT is a lookup table used by Gods to move objects along cubic Bezier curves. It is one of the few data files that is not compressed.

File format

The file is 1600 bytes: four tables of 200 unsigned big-endian 16-bit values.

Data type Name Description
UINT16BE[200] b0 (1 - t)³
UINT16BE[200] b1 3t(1 - t)²
UINT16BE[200] b2 3t²(1 - t)
UINT16BE[200] b3 t³

Entry i in each table is the value for t = i / 200, stored as a fixed-point number where 65536 = 1.0 (so the value 1.0 at t = 0 is stored as 65535). For example at t = 0.5 (entry 100), b0 is 8192 (0.125) and b1 is 24576 (0.375).

There is no entry for t = 1.0, so a curve never quite reaches its end point.

Use

When reading a value, the game shifts it right by one bit, turning it into a 1.15 fixed-point number, before use. A point on the curve with control points P0-P3 is then:

x = (b0[i]*P0.x + b1[i]*P1.x + b2[i]*P2.x + b3[i]*P3.x) >> 15
y = (b0[i]*P0.y + b1[i]*P1.y + b2[i]*P2.y + b3[i]*P3.y) >> 15

The shift is an arithmetic shift (rounding towards minus infinity), which gives slightly different results from a division for negative coordinates.

Source code

From re-gods, the open-source HTML5 port:

Credits

This file format was reverse engineered by VorticonCmdr. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)