diff --git a/bind/lua b/bind/lua index 6718e0d..92587d5 100644 Binary files a/bind/lua and b/bind/lua differ diff --git a/depot b/depot index 06f2dd9..ff92bac 160000 --- a/depot +++ b/depot @@ -1 +1 @@ -Subproject commit 06f2dd98dfeee885b9935486f055e58cc3ce1b5d +Subproject commit ff92bac168d3fb16e4c5be89343ac7fc4dc42858 diff --git a/engine/joint/v4k.h b/engine/joint/v4k.h index 6b91d24..b80c662 100644 --- a/engine/joint/v4k.h +++ b/engine/joint/v4k.h @@ -591966,7 +591966,7 @@ void printi_( int *m, int ii, int jj ) { } void print_( float *m, int ii, int jj ) { for( int j = 0; j < jj; ++j ) { - for( int i = 0; i < ii; ++i ) printf("%8.3f", *m++); + for( int i = 0; i < ii; ++i ) printf("%8.3f ", *m++); puts(""); } // puts("---"); @@ -606798,10 +606798,17 @@ char *editor_path(const char *path) { vec3 editor_pick(float mouse_x, float mouse_y) { // unproject 2d coord as 3d coord camera_t *camera = camera_get_active(); - vec3 out, xyd = vec3(mouse_x,window_height()-mouse_y,1); // usually x:mouse_x,y:window_height()-mouse_y,d:0=znear/1=zfar - mat44 mvp, model; identity44(model); multiply44x3(mvp, camera->proj, camera->view, model); - bool ok = unproject44(&out, xyd, vec4(0,0,window_width(),window_height()), mvp); - return out; + float x = (2.0f * mouse_x) / window_width() - 1.0f; + float y = 1.0f - (2.0f * mouse_y) / window_height(); + float z = 1.0f; + vec3 ray_nds = vec3(x, y, z); + vec4 ray_clip = vec4(ray_nds.x, ray_nds.y, -1.0, 1.0); + mat44 inv_proj; invert44(inv_proj, camera->proj); + mat44 inv_view; invert44(inv_view, camera->view); + vec4 p = transform444(inv_proj, ray_clip); + vec4 eye = vec4(p.x, p.y, -1.0, 0.0); + vec4 wld = norm4(transform444(inv_view, eye)); + return vec3(wld.x, wld.y, wld.z); } int editor_ui_bits8(const char *label, uint8_t *enabled) { // @to deprecate diff --git a/engine/split/v4k_editor.c b/engine/split/v4k_editor.c index 4149c2e..300b202 100644 --- a/engine/split/v4k_editor.c +++ b/engine/split/v4k_editor.c @@ -8,10 +8,17 @@ char *editor_path(const char *path) { vec3 editor_pick(float mouse_x, float mouse_y) { // unproject 2d coord as 3d coord camera_t *camera = camera_get_active(); - vec3 out, xyd = vec3(mouse_x,window_height()-mouse_y,1); // usually x:mouse_x,y:window_height()-mouse_y,d:0=znear/1=zfar - mat44 mvp, model; identity44(model); multiply44x3(mvp, camera->proj, camera->view, model); - bool ok = unproject44(&out, xyd, vec4(0,0,window_width(),window_height()), mvp); - return out; + float x = (2.0f * mouse_x) / window_width() - 1.0f; + float y = 1.0f - (2.0f * mouse_y) / window_height(); + float z = 1.0f; + vec3 ray_nds = vec3(x, y, z); + vec4 ray_clip = vec4(ray_nds.x, ray_nds.y, -1.0, 1.0); + mat44 inv_proj; invert44(inv_proj, camera->proj); + mat44 inv_view; invert44(inv_view, camera->view); + vec4 p = transform444(inv_proj, ray_clip); + vec4 eye = vec4(p.x, p.y, -1.0, 0.0); + vec4 wld = norm4(transform444(inv_view, eye)); + return vec3(wld.x, wld.y, wld.z); } int editor_ui_bits8(const char *label, uint8_t *enabled) { // @to deprecate diff --git a/engine/split/v4k_math.c b/engine/split/v4k_math.c index 4370c2d..85ecbc1 100644 --- a/engine/split/v4k_math.c +++ b/engine/split/v4k_math.c @@ -987,7 +987,7 @@ void printi_( int *m, int ii, int jj ) { } void print_( float *m, int ii, int jj ) { for( int j = 0; j < jj; ++j ) { - for( int i = 0; i < ii; ++i ) printf("%8.3f", *m++); + for( int i = 0; i < ii; ++i ) printf("%8.3f ", *m++); puts(""); } // puts("---"); diff --git a/engine/v4k.c b/engine/v4k.c index 8cef6e2..ad08190 100644 --- a/engine/v4k.c +++ b/engine/v4k.c @@ -10135,7 +10135,7 @@ void printi_( int *m, int ii, int jj ) { } void print_( float *m, int ii, int jj ) { for( int j = 0; j < jj; ++j ) { - for( int i = 0; i < ii; ++i ) printf("%8.3f", *m++); + for( int i = 0; i < ii; ++i ) printf("%8.3f ", *m++); puts(""); } // puts("---"); @@ -24967,10 +24967,17 @@ char *editor_path(const char *path) { vec3 editor_pick(float mouse_x, float mouse_y) { // unproject 2d coord as 3d coord camera_t *camera = camera_get_active(); - vec3 out, xyd = vec3(mouse_x,window_height()-mouse_y,1); // usually x:mouse_x,y:window_height()-mouse_y,d:0=znear/1=zfar - mat44 mvp, model; identity44(model); multiply44x3(mvp, camera->proj, camera->view, model); - bool ok = unproject44(&out, xyd, vec4(0,0,window_width(),window_height()), mvp); - return out; + float x = (2.0f * mouse_x) / window_width() - 1.0f; + float y = 1.0f - (2.0f * mouse_y) / window_height(); + float z = 1.0f; + vec3 ray_nds = vec3(x, y, z); + vec4 ray_clip = vec4(ray_nds.x, ray_nds.y, -1.0, 1.0); + mat44 inv_proj; invert44(inv_proj, camera->proj); + mat44 inv_view; invert44(inv_view, camera->view); + vec4 p = transform444(inv_proj, ray_clip); + vec4 eye = vec4(p.x, p.y, -1.0, 0.0); + vec4 wld = norm4(transform444(inv_view, eye)); + return vec3(wld.x, wld.y, wld.z); } int editor_ui_bits8(const char *label, uint8_t *enabled) { // @to deprecate