...
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/sdl3.sx";
|
||||
#import "modules/opengl.sx";
|
||||
#import "modules/math";
|
||||
|
||||
PI :f32: 3.14159265;
|
||||
|
||||
WIDTH :f32: 800;
|
||||
HEIGHT :f32: 600;
|
||||
|
||||
vec4 :: (x: f32, y: f32, z: f32, w: f32) -> Vector(4, f32) {
|
||||
.[x, y, z, w];
|
||||
@@ -23,6 +26,7 @@ mat4_multiply :: (a: *Matrix44, b: *Matrix44) -> Matrix44 {
|
||||
out.c3 = a.c0 * b.c3.x + a.c1 * b.c3.y + a.c2 * b.c3.z + a.c3 * b.c3.w;
|
||||
out;
|
||||
}
|
||||
multiply :: ufcs mat4_multiply;
|
||||
|
||||
mat4_perspective :: (fov: f32, aspect: f32, near: f32, far: f32) -> Matrix44 {
|
||||
half := fov / 2.0;
|
||||
@@ -117,7 +121,7 @@ main :: () {
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
|
||||
window := SDL_CreateWindow("sx GL cube", 800, 600, SDL_WINDOW_OPENGL);
|
||||
window := SDL_CreateWindow("sx GL cube", xx WIDTH, xx HEIGHT, SDL_WINDOW_OPENGL);
|
||||
gl_ctx := SDL_GL_CreateContext(window);
|
||||
SDL_GL_MakeCurrent(window, gl_ctx);
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
@@ -276,11 +280,11 @@ GLSL;
|
||||
angle := ms * 0.001;
|
||||
|
||||
// Build matrices
|
||||
proj := mat4_perspective(PI / 4.0, 800.0 / 600.0, 0.1, 100.0);
|
||||
proj := mat4_perspective(PI / 4.0, WIDTH / HEIGHT, 0.1, 100.0);
|
||||
view := mat4_translate(0.0, 0.0, -3.0);
|
||||
rot_y := mat4_rotate_y(angle);
|
||||
rot_x := mat4_rotate_x(angle * 0.7);
|
||||
model := mat4_multiply(rot_y, rot_x);
|
||||
model := (rot_y, rot_x).multiply();
|
||||
vm := mat4_multiply(view, model);
|
||||
mvp := mat4_multiply(proj, vm);
|
||||
|
||||
|
||||
5
examples/modules/math/math.sx
Normal file
5
examples/modules/math/math.sx
Normal file
@@ -0,0 +1,5 @@
|
||||
PI :f32: 3.14159265;
|
||||
|
||||
sqrt :: (x: $T) -> T #builtin;
|
||||
sin :: (x: $T) -> T #builtin;
|
||||
cos :: (x: $T) -> T #builtin;
|
||||
@@ -1,8 +1,8 @@
|
||||
Vector :: ($N: int, $T: Type) -> Type #builtin;
|
||||
out :: (str: string) -> void #builtin;
|
||||
sqrt :: (x: $T) -> T #builtin;
|
||||
sin :: (x: $T) -> T #builtin;
|
||||
cos :: (x: $T) -> T #builtin;
|
||||
// sqrt :: (x: $T) -> T #builtin;
|
||||
// sin :: (x: $T) -> T #builtin;
|
||||
// cos :: (x: $T) -> T #builtin;
|
||||
size_of :: ($T: Type) -> s64 #builtin;
|
||||
malloc :: (size: s64) -> *void #builtin;
|
||||
memcpy :: (dst: *void, src: *void, size: s64) -> *void #builtin;
|
||||
|
||||
Reference in New Issue
Block a user