From 7d17df39b3673d7838eb1289892639d06386198a Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Mon, 5 Jun 2023 11:15:47 +0200 Subject: [PATCH] some old changes --- .vscode/settings.json | 3 +- CMakeLists.txt | 2 +- src/core/include/pw/core/matrix_transform.hpp | 52 ++++++++++++++++--- src/deps/CMakeLists.txt | 3 +- src/scripts/demos/simple_004.lua | 17 +++--- 5 files changed, 59 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index b4d8c35..4d69525 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + "cmake.configureOnOpen": true } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d1842d..3cfa15f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(pixwerx) # # pixwerx ist C++17 # -set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_STANDARD 23) # internal cmake modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH}) diff --git a/src/core/include/pw/core/matrix_transform.hpp b/src/core/include/pw/core/matrix_transform.hpp index bf60b91..7131fe3 100644 --- a/src/core/include/pw/core/matrix_transform.hpp +++ b/src/core/include/pw/core/matrix_transform.hpp @@ -39,7 +39,7 @@ struct matrix_transform { } inline static - matrix_<4,4,T> perspective_frustum(const T &left,const T &right, + matrix_<4,4,T> perspective_frustum_rh(const T &left,const T &right, const T &bottom,const T &top, const T &z_near,const T &z_far) { @@ -48,16 +48,56 @@ struct matrix_transform { frustum(0,0) = T(2) * z_near / (right - left); frustum(1,1) = T(2) * z_near / (top - bottom); - frustum(0,2) = (right+left)/(right-left); //A - frustum(1,2) = (top+bottom)/(top-bottom); //B - frustum(2,2) = -(z_far+z_near)/(z_far-z_near); //C - frustum(2,3) = -T(2) * z_far*z_near/(z_far-z_near); //D + frustum(0,2) = (right+left)/(right-left); //A + frustum(1,2) = (top+bottom)/(top-bottom); //B + frustum(2,2) = -(z_far+z_near)/(z_far-z_near); //C + frustum(2,3) = -T(2) * z_far*z_near/(z_far-z_near); //D frustum(3,2) = -T(1); return frustum; } + +// /// creates a projection from a frustum planes with a reversed depth mapped to [0..1] +// pub fn make_projection_rh_from_frustum_reversed( +// left: f32, +// right: f32, +// bottom: f32, +// top: f32, +// z_near: f32, +// z_far: f32, +// ) -> Mat4 { +// assert!(z_near > 0.0 && z_far > 0.0); + +// // info!("near {:?}", z_near); + +// // +// // reversed z 0..1 projection +// // +// let a = (right + left) / (right - left); // position in frame horizontal +// let b = (top + bottom) / (top - bottom); // position in frame vertical + +// let c = z_near / (z_far - z_near); // lower bound +// let d = z_far * z_near / (z_far - z_near); // upper bound + +// let sx = 2.0 * z_near / (right - left); // scale x +// let sy = 2.0 * z_near / (top - bottom); // scale y + +// // reverse z 0..1 +// // -------------- +// // sx 0 a 0 +// // 0 sy b 0 +// // 0 0 c d +// // 0 0 -1 0 + +// Mat4::from_cols( +// Vec4::new(sx, 0.0, 0.0, 0.0), +// Vec4::new(0.0, sy, 0.0, 0.0), +// Vec4::new(a, b, c, -1.0), +// Vec4::new(0.0, 0.0, d, 0.0), +// ) +// } inline static matrix_<4,4,T> perspective_projection(const T &field_of_view, const T &aspect_ratio, @@ -69,7 +109,7 @@ struct matrix_transform { const auto top = right / aspect_ratio; const auto bottom = -top; - return perspective_frustum(left,right, + return perspective_frustum_rh(left,right, bottom,top, z_near,z_far); } diff --git a/src/deps/CMakeLists.txt b/src/deps/CMakeLists.txt index 6871c28..dd84fd6 100644 --- a/src/deps/CMakeLists.txt +++ b/src/deps/CMakeLists.txt @@ -1,10 +1,9 @@ -set(GLFW_BUILD_EXAMPLES TRUE CACHE BOOL "Build the GLFW example programs" FORCE) +set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" FORCE) set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" FORCE) set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target" FORCE) -#add_subdirectory(glfw-3.2.1) add_subdirectory(glfw-3.3.5) add_subdirectory(lua-5.4.2) diff --git a/src/scripts/demos/simple_004.lua b/src/scripts/demos/simple_004.lua index f2264f2..44ec6bb 100644 --- a/src/scripts/demos/simple_004.lua +++ b/src/scripts/demos/simple_004.lua @@ -54,9 +54,14 @@ g.texture_coordinates = { { { 0.0, 1.0 } } } -z = -5.0 +z = 0 s = 1 + +-- 0 --- 3 +-- | \ | +-- 1 --- 2 + -- indices g.indices = { 0, 1, 2, -- triangle #1 @@ -74,10 +79,6 @@ g.vertices = { { -s, s, z } } --- 0 --- 3 --- | \ | --- 1 --- 2 - g:compute_normals() @@ -131,7 +132,7 @@ end local renderer = pw.renderer() -- camera position -local cam_pos = pw.vector3(0,0,0) +local cam_pos = pw.vector3(0,0,5) -- model position local model_pos = pw.vector3(0,0,0) @@ -197,7 +198,7 @@ w.on_update = function(self) s:set_uniform_vec4("color",cl) -- specific to our shader - s:set_uniform_int("tex_color",0) + s:set_uniform_int("tex_color",0) -- unit 0 -- bind the texture tx:bind() @@ -228,7 +229,7 @@ while w:update() do if pw.input.get().has_input then - -- somehow works + -- somehow (depending on X11/Wayland) works if pw.input.get().input_string == 'f' then w.fullscreen = not w.fullscreen end