odin-raylib-game/game/math.odin

27 lines
494 B
Odin

package game
Vec2i :: struct {
x: int,
y: int,
}
vec2i_to_vec2 :: proc(v2i:Vec2i) -> [2]f32 {
return {f32(v2i.x), f32(v2i.y)}
}
vec2_to_vec2i :: proc(v2:[2]f32) -> Vec2i {
return {int(v2.x), int(v2.y)}
}
to_bytes :: proc(v: $T) -> [size_of(T)]u8 {
val := v
encoded_bytes := (^[size_of(T)]u8)(&val)
return encoded_bytes^
}
from_bytes :: proc($T:typeid, data: [size_of(T)]u8) -> T {
bytes := data
decoded_value := (^T)(&bytes)^
return decoded_value
}