Win32 Demo - Minor math tests

This commit is contained in:
gingerBill
2016-08-18 09:24:52 +01:00
parent 6f9d11b381
commit 6b2cd1b33f
5 changed files with 955 additions and 95 deletions
+933 -69
View File
File diff suppressed because it is too large Load Diff
-23
View File
@@ -1,20 +1,4 @@
#load "basic.odin"
main :: proc() {
a := {4}f32{1}; // {1, 1, 1, 1} broadcasts to all
a = swizzle({4}f32{1, 2, 3, 4}, 1, 3, 2, 0);
for i := 0; i < len(a); i++ {
if i > 0 {
print_string(", ");
}
print_int(a[i] as int);
}
print_string("\n");
}
/*
#load "win32.odin"
#load "opengl.odin"
#load "stb_image.odin"
@@ -173,12 +157,6 @@ main :: proc() {
}
defer destroy_window(^window);
{
v := Vec2{1, 2};
c := v * 2;
}
prev_time := time_now();
running := true;
for running {
@@ -215,4 +193,3 @@ main :: proc() {
display_window(^window);
}
}
*/
+18
View File
@@ -0,0 +1,18 @@
type Vec2: {2}f32
type Vec3: {3}f32
type Vec4: {4}f32
type Mat2: {4}f32
sqrt_f32 :: proc(x: f32) -> f32 #foreign "llvm.sqrt.f32"
sqrt_f64 :: proc(x: f64) -> f64 #foreign "llvm.sqrt.f64"
vec2_dot :: proc(a, b: Vec2) -> f32 { c := a*b; return c[0] + c[1]; }
vec3_dot :: proc(a, b: Vec3) -> f32 { c := a*b; return c[0] + c[1] + c[2]; }
lerp :: proc(a, b, t: f32) -> f32 { return a*(1-t) + b*t; }
vec2_mag :: proc(a: Vec2) -> f32 { return sqrt_f32(vec2_dot(a, a)); }
vec3_mag :: proc(a: Vec3) -> f32 { return sqrt_f32(vec3_dot(a, a)); }