-
Notifications
You must be signed in to change notification settings - Fork 5
th.um
Module with useful variables and types.
Variables: time, delta, platform
Constants: black, white, red, green, blue, yellow, magenta, cyan.
type fu* = real32
standard type for real values
type iu* = int32
standard type for integer values
type uu* = uint32
standard type for unsigned values
type Vf2* = struct {
x, y: fu
}
vector 2
fn mkVf2*(x: fu = 0, y: fu = 0): Vf2 {
Vf2 constructor
fn (p: ^th.Vf2) rotated*(origin: th.Vf2, rot: th.fu): th.Vf2 {
rotates p
around origin
with rot
in degrees
fn (p1: ^th.Vf2) distanceTo*(p2: th.Vf2): th.fu {
distance between p1 and p2
fn (p1: ^th.Vf2) angleTo*(p2: th.Vf2): real {
Angle between p1 and p2
fn (p: ^th.Vf2) abs*(): th.Vf2 {
Absolute value of a vector.
fn (p: ^th.Vf2) round*(): th.Vf2 {
Rounds a vector.
fn (p: ^th.Vf2) trunc*(): th.Vf2 {
Truncates a vector.
fn (p: ^th.Vf2) floor*(): th.Vf2 {
Floors a vector.
fn (p: ^th.Vf2) ceil*(): th.Vf2 {
Ceils a vector.
fn vf2f*(f: th.fu): th.Vf2 {
Creates a vector with both x and y set to f
fn (p: ^th.Vf2) sub*(p2: th.Vf2): th.Vf2 {
Subtracts a vector from another one.
fn (p: ^th.Vf2) subf*(f: th.fu): th.Vf2 {
Subtracts a fu from a vector.
fn (p: ^th.Vf2) add*(p2: th.Vf2): th.Vf2 {
Adds a vector to another one.
fn (p: ^th.Vf2) addf*(f: th.fu): th.Vf2 {
Adds a fu to a vector.
fn (p: ^th.Vf2) div*(p2: th.Vf2): th.Vf2 {
Divides a vector by another one.
fn (p: ^th.Vf2) divf*(f: th.fu): th.Vf2 {
Divides a vector by a fu.
fn (p: ^th.Vf2) mul*(p2: th.Vf2): th.Vf2 {
Multiplies a vector by another one.
fn (p: ^th.Vf2) mulf*(f: th.fu): th.Vf2 {
Multiplies a vector by a fu.
fn (p: ^th.Vf2) mag*(): th.fu {
Returns the magnitude of a vector p.
fn (p: ^th.Vf2) norm*(): th.Vf2 {
Normalizes a vector.
fn (p: ^th.Vf2) dot*(q: th.Vf2): fu {
Calculates dot product between 2 vectors.
type Transform* = struct {
p: Vf2 // position
s: Vf2 // scale
o: Vf2 // origin
r: fu // rotation
}
Struct defining transformation. Used for example by entities.
fn mkTransform*(p: Vf2, s: Vf2 = Vf2{1, 1}, o: Vf2 = Vf2{0, 0}, r: fu = 0.0): Transform {
Transform constructor
fn (v: ^Vf2) transformed*(t: Transform): Vf2 {
Transforms a vf2 to another vf2. Order: 1. scale 2. rotation 3. position
This allows conversion from a relative to an absolute vf2.
type Quad* = [4]th.Vf2
fn (q: ^Quad) transformed*(t: Transform): Quad {
Transforms a quad into another quad. Order: 1. scale 2. rotation 3. position
fn getGlobal*(): ^struct{} {
returns a pointer to the th_global. Set this as your extensions thg.
fn getFuncs*(): ^struct{} {
returns pointer to tophat functions. Pass this to th_ext_set.