diff --git a/Data/resources/shaders/.kp3d/map_grid_f.glsl b/Data/resources/shaders/.kp3d/map_grid_f.glsl index 1b355e4..4aa04fa 100644 --- a/Data/resources/shaders/.kp3d/map_grid_f.glsl +++ b/Data/resources/shaders/.kp3d/map_grid_f.glsl @@ -56,7 +56,7 @@ void main() vec3 res = light.diffuse * lambert(norm, light.position); - float a = dist(v_position.xy, vec2(0.0, 0.0)) * 2.0f; + float a = dist(v_position.xz, vec2(0.0, 0.0)) * 2.0f; v_output = vec4(tex.rgb, tex.a - a); } diff --git a/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl b/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl new file mode 100644 index 0000000..f7a0776 --- /dev/null +++ b/Data/resources/shaders/.kp3d/r3d_legacy_f.glsl @@ -0,0 +1,17 @@ +#version 330 core + +in vec3 v_position; +in vec4 v_color; +in vec2 v_texcoord; + +out vec4 v_output; + +uniform sampler2D u_texture; + +uniform float u_time; + +void main() +{ + vec4 tex = texture(u_texture, v_texcoord) * v_color; + v_output = vec4(1.0, 0.0, 0.0, 0.5 + (sin(u_time * 0.3f) + 1.0) * 0.25); +} diff --git a/Data/resources/shaders/.kp3d/r3d_legacy_v.glsl b/Data/resources/shaders/.kp3d/r3d_legacy_v.glsl new file mode 100644 index 0000000..731613c --- /dev/null +++ b/Data/resources/shaders/.kp3d/r3d_legacy_v.glsl @@ -0,0 +1,24 @@ +#version 330 core + +uniform mat4 u_mvp; + +layout (location = 0) in vec3 position; +layout (location = 1) in vec4 color; +layout (location = 2) in vec2 texcoord; + +out vec3 v_position; +out vec4 v_color; +out vec2 v_texcoord; + +out float v_id; + +void main() +{ + v_position = position; + v_color = color; + v_texcoord = texcoord; + + v_id = gl_VertexID; + + gl_Position = u_mvp * vec4(v_position, 1.0); +} diff --git a/Data/sandbox-log.txt b/Data/sandbox-log.txt index 340912c..7e33877 100644 --- a/Data/sandbox-log.txt +++ b/Data/sandbox-log.txt @@ -1,16 +1,356 @@ -[03:52:19 AM] Info: Starting... +[01:28:26 PM] Info: Starting... KP3D version 2 =============================== Copyright (C) kpworld.xyz 2018-2024 Contact me! @kp_cftsz -[03:52:19 AM] Info: Initializing SDL -[03:52:19 AM] Info: Initializing OpenGL -[03:52:19 AM] Info: OpenGL version: 4.6.0 NVIDIA 536.23 -[03:52:19 AM] Info: Initializing GLEW -[03:52:19 AM] Info: Initializing SDL_mixer -[03:52:19 AM] Info: Reticulating splines... -[03:52:20 AM] Info: Ready! -[03:53:11 AM] Info: $ set-mode edit -[03:53:11 AM] Info: $ +[01:28:26 PM] Info: Initializing SDL +[01:28:27 PM] Info: Initializing OpenGL +[01:28:27 PM] Info: OpenGL version: 4.6.0 NVIDIA 517.70 +[01:28:27 PM] Info: Initializing GLEW +[01:28:27 PM] Info: Initializing SDL_mixer +[01:28:27 PM] Info: Reticulating splines... +[01:28:27 PM] Info: Ready! +[01:28:27 PM] Info: SECTOR HIERARCHY +[01:28:27 PM] Info: Sector 3 (area: 1) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - 1 +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - [NO CHILDREN] +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: Sector 4 (area: 1) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - 2 +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - [NO CHILDREN] +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: Sector 6 (area: 6) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - 1 +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - [NO CHILDREN] +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: Sector 2 (area: 19) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - 1 +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - 4 +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: Sector 5 (area: 34) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - [NO PARENT] +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - [NO CHILDREN] +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: Sector 1 (area: 105.5) +[01:28:27 PM] Info: Parent: +[01:28:27 PM] Info: - [NO PARENT] +[01:28:27 PM] Info: Children: +[01:28:27 PM] Info: - 3 +[01:28:27 PM] Info: - 6 +[01:28:27 PM] Info: - 2 +[01:28:27 PM] Info: ----- +[01:28:27 PM] Info: 3 IS CONNECTED TO 2 +[01:28:27 PM] Info: 3 IS CONNECTED TO 2 +[01:28:27 PM] Info: 2 IS CONNECTED TO 3 +[01:28:27 PM] Info: 2 IS CONNECTED TO 3 +[01:28:27 PM] Info: 1 IS CONNECTED TO 5 +[01:28:40 PM] Info: SECTOR HIERARCHY +[01:28:40 PM] Info: Sector 3 (area: 1) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - 1 +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - [NO CHILDREN] +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 4 (area: 1) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - 2 +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - [NO CHILDREN] +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 6 (area: 6) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - 1 +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - [NO CHILDREN] +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 2 (area: 19) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - 1 +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - 4 +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 5 (area: 34) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - [NO PARENT] +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - [NO CHILDREN] +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 1 (area: 105.5) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - [NO PARENT] +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - 3 +[01:28:40 PM] Info: - 6 +[01:28:40 PM] Info: - 2 +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: Sector 7 (area: 311) +[01:28:40 PM] Info: Parent: +[01:28:40 PM] Info: - [NO PARENT] +[01:28:40 PM] Info: Children: +[01:28:40 PM] Info: - [NO CHILDREN] +[01:28:40 PM] Info: ----- +[01:28:40 PM] Info: 3 IS CONNECTED TO 2 +[01:28:40 PM] Info: 3 IS CONNECTED TO 2 +[01:28:40 PM] Info: 2 IS CONNECTED TO 3 +[01:28:40 PM] Info: 2 IS CONNECTED TO 3 +[01:28:40 PM] Info: 1 IS CONNECTED TO 7 +[01:28:40 PM] Info: 1 IS CONNECTED TO 5 +[01:28:40 PM] Info: 7 IS CONNECTED TO 1 +[01:28:40 PM] Info: 7 IS CONNECTED TO 1 +[01:28:50 PM] Info: SECTOR HIERARCHY +[01:28:50 PM] Info: Sector 3 (area: 1) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - 1 +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 4 (area: 1) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - 2 +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 6 (area: 6) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - 1 +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 2 (area: 19) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - 1 +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - 4 +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 5 (area: 34) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - [NO PARENT] +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 1 (area: 105.5) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - [NO PARENT] +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - 3 +[01:28:50 PM] Info: - 6 +[01:28:50 PM] Info: - 2 +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 7 (area: 311) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - [NO PARENT] +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: Sector 8 (area: 585) +[01:28:50 PM] Info: Parent: +[01:28:50 PM] Info: - [NO PARENT] +[01:28:50 PM] Info: Children: +[01:28:50 PM] Info: - [NO CHILDREN] +[01:28:50 PM] Info: ----- +[01:28:50 PM] Info: 3 IS CONNECTED TO 2 +[01:28:50 PM] Info: 3 IS CONNECTED TO 2 +[01:28:50 PM] Info: 2 IS CONNECTED TO 3 +[01:28:50 PM] Info: 2 IS CONNECTED TO 3 +[01:28:50 PM] Info: 1 IS CONNECTED TO 7 +[01:28:50 PM] Info: 1 IS CONNECTED TO 5 +[01:28:50 PM] Info: 7 IS CONNECTED TO 1 +[01:28:50 PM] Info: 7 IS CONNECTED TO 8 +[01:28:50 PM] Info: 7 IS CONNECTED TO 1 +[01:28:50 PM] Info: 8 IS CONNECTED TO 7 +[01:28:50 PM] Info: 8 IS CONNECTED TO 7 +[01:29:01 PM] Info: SECTOR HIERARCHY +[01:29:01 PM] Info: Sector 3 (area: 1) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - 1 +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 4 (area: 1) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - 2 +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 6 (area: 6) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - 1 +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 2 (area: 19) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - 1 +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - 4 +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 5 (area: 34) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - [NO PARENT] +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 9 (area: 48.5) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - [NO PARENT] +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 1 (area: 105.5) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - [NO PARENT] +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - 3 +[01:29:01 PM] Info: - 6 +[01:29:01 PM] Info: - 2 +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 7 (area: 311) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - [NO PARENT] +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: Sector 8 (area: 585) +[01:29:01 PM] Info: Parent: +[01:29:01 PM] Info: - [NO PARENT] +[01:29:01 PM] Info: Children: +[01:29:01 PM] Info: - [NO CHILDREN] +[01:29:01 PM] Info: ----- +[01:29:01 PM] Info: 3 IS CONNECTED TO 2 +[01:29:01 PM] Info: 3 IS CONNECTED TO 2 +[01:29:01 PM] Info: 2 IS CONNECTED TO 3 +[01:29:01 PM] Info: 2 IS CONNECTED TO 3 +[01:29:01 PM] Info: 1 IS CONNECTED TO 7 +[01:29:01 PM] Info: 1 IS CONNECTED TO 5 +[01:29:01 PM] Info: 7 IS CONNECTED TO 1 +[01:29:01 PM] Info: 7 IS CONNECTED TO 8 +[01:29:01 PM] Info: 7 IS CONNECTED TO 1 +[01:29:01 PM] Info: 8 IS CONNECTED TO 7 +[01:29:01 PM] Info: 8 IS CONNECTED TO 7 +[01:29:11 PM] Info: SECTOR HIERARCHY +[01:29:11 PM] Info: Sector 3 (area: 1) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - 1 +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 4 (area: 1) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - 2 +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 6 (area: 6) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - 1 +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 2 (area: 19) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - 1 +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - 4 +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 5 (area: 34) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 10 (area: 36) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 9 (area: 48.5) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 1 (area: 105.5) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - 3 +[01:29:11 PM] Info: - 6 +[01:29:11 PM] Info: - 2 +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 7 (area: 311) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: Sector 8 (area: 585) +[01:29:11 PM] Info: Parent: +[01:29:11 PM] Info: - [NO PARENT] +[01:29:11 PM] Info: Children: +[01:29:11 PM] Info: - [NO CHILDREN] +[01:29:11 PM] Info: ----- +[01:29:11 PM] Info: 3 IS CONNECTED TO 2 +[01:29:11 PM] Info: 3 IS CONNECTED TO 2 +[01:29:11 PM] Info: 2 IS CONNECTED TO 3 +[01:29:11 PM] Info: 2 IS CONNECTED TO 3 +[01:29:11 PM] Info: 5 IS CONNECTED TO 10 +[01:29:11 PM] Info: 10 IS CONNECTED TO 5 +[01:29:11 PM] Info: 10 IS CONNECTED TO 9 +[01:29:11 PM] Info: 10 IS CONNECTED TO 5 +[01:29:11 PM] Info: 9 IS CONNECTED TO 10 +[01:29:11 PM] Info: 9 IS CONNECTED TO 10 +[01:29:11 PM] Info: 1 IS CONNECTED TO 7 +[01:29:11 PM] Info: 1 IS CONNECTED TO 5 +[01:29:11 PM] Info: 7 IS CONNECTED TO 1 +[01:29:11 PM] Info: 7 IS CONNECTED TO 8 +[01:29:11 PM] Info: 7 IS CONNECTED TO 1 +[01:29:11 PM] Info: 8 IS CONNECTED TO 7 +[01:29:11 PM] Info: 8 IS CONNECTED TO 7 +[01:29:38 PM] Info: SECTOR HIERARCHY +[01:29:38 PM] Info: Sector 3 (area: 1) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - 1 +[01:29:38 PM] Info: Children: +[01:29:38 PM] Info: - [NO CHILDREN] +[01:29:38 PM] Info: ----- +[01:29:38 PM] Info: Sector 4 (area: 1) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - 2 +[01:29:38 PM] Info: Children: +[01:29:38 PM] Info: - [NO CHILDREN] +[01:29:38 PM] Info: ----- +[01:29:38 PM] Info: Sector 6 (area: 6) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - 1 +[01:29:38 PM] Info: Children: +[01:29:38 PM] Info: - [NO CHILDREN] +[01:29:38 PM] Info: ----- +[01:29:38 PM] Info: Sector 2 (area: 19) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - 1 +[01:29:38 PM] Info: Children: +[01:29:38 PM] Info: - 4 +[01:29:38 PM] Info: ----- +[01:29:38 PM] Info: Sector 5 (area: 34) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - [NO PARENT] +[01:29:38 PM] Info: Children: +[01:29:38 PM] Info: - [NO CHILDREN] +[01:29:38 PM] Info: ----- +[01:29:38 PM] Info: Sector 10 (area: 36) +[01:29:38 PM] Info: Parent: +[01:29:38 PM] Info: - [NO PARENT] +[01:29:38 PM] In \ No newline at end of file diff --git a/KP3Dii/src/KP3D_Map.cpp b/KP3Dii/src/KP3D_Map.cpp index 8250e87..d688ec0 100644 --- a/KP3Dii/src/KP3D_Map.cpp +++ b/KP3Dii/src/KP3D_Map.cpp @@ -265,18 +265,24 @@ void Map::BuildWall(Sector& sector, Wall& wall) if (wall.flags & Wall::FLAG_OPENING) { // Build upper and lower walls for sectors connected to other sectors + // Kinda inefficient the way I'm doing this but whatever YOLO etc. BuildQuad(sector, sector.floor, wall.portal->floor, wall.textures[TEX_LOWER], a, b, false, false, false, wall.uv_offset[TEX_LOWER]); + BuildQuad(sector, sector.floor, wall.portal->floor, wall.textures[TEX_LOWER], a, b, true, false, false, wall.uv_offset[TEX_LOWER]); BuildQuad(sector, sector.ceiling, wall.portal->ceiling, wall.textures[TEX_UPPER], a, b, true, false, false, wall.uv_offset[TEX_UPPER]); + BuildQuad(sector, sector.ceiling, wall.portal->ceiling, wall.textures[TEX_UPPER], a, b, false, false, false, wall.uv_offset[TEX_UPPER]); } } void Map::JoinSectors(Sector& sector) { // "Connect" sectors by splitting up their walls where other sectors intersect + //for (int i = 0; i < sector.walls.size(); i++) for (int i = 0; i < sector.walls.size(); i++) { Wall& ld = sector.walls[i]; - for (Sector& s : sectors) + // Clipper2Lib::PathD p; + // p.push_back({ld.start.x, ld.start.y}); + for (Sector& s: sectors) { if (s.id == sector.id) continue; @@ -288,18 +294,29 @@ void Map::JoinSectors(Sector& sector) float yt = s.ceiling.base_height; bool not_child = s.parent_id != sector.id; + float e = 1.0f / 128.0f; + for (Wall& l : s.walls) { - if (PointInLine(l.start, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}) && - PointInLine(l.end, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}) && - !PosCmp({l.start.x, 0.0f, l.start.y}, {pos_a.x, 0.0f, pos_a.z}) && - !PosCmp({l.start.x, 0.0f, l.start.y}, {pos_b.x, 0.0f, pos_b.z}) && - !PosCmp({l.end.x, 0.0f, l.end.y}, {pos_b.x, 0.0f, pos_b.z}) && - !PosCmp({l.end.x, 0.0f, l.end.y}, {pos_a.x, 0.0f, pos_a.z}) && not_child) + // Clipper2Lib::PointD pi = { l.start.x, l.start.y }; + + bool good = false; + bool same_points = PosCmp({l.start.x, 0.0f, l.start.y}, {pos_a.x, 0.0f, pos_a.z}, e) || + PosCmp({l.start.x, 0.0f, l.start.y}, {pos_b.x, 0.0f, pos_b.z}, e) || + PosCmp({l.end.x, 0.0f, l.end.y}, {pos_b.x, 0.0f, pos_b.z}, e) || + PosCmp({l.end.x, 0.0f, l.end.y}, {pos_a.x, 0.0f, pos_a.z}, e); + + bool on_segment = PointInLine(l.start, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}) && + PointInLine(l.end, {pos_a.x, pos_a.z}, {pos_b.x, pos_b.z}); + + if (on_segment && not_child) + good = true; + if (good && !l.portal && !ld.portal) { XYf old_end = ld.end; ld.end.x = l.end.x; ld.end.y = l.end.y; + ld.flags = Wall::FLAG_TOUCHED; Wall w1 = ld; w1.start.x = ld.end.x; w1.start.y = ld.end.y; @@ -308,19 +325,23 @@ void Map::JoinSectors(Sector& sector) w1.textures[TEX_FRONT] = nullptr; w1.flags = Wall::FLAG_OPENING; w1.portal = &s; + w1.flags = Wall::FLAG_TOUCHED; Wall w2 = ld; w2.start.x = w1.end.x; w2.start.y = w1.end.y; w2.end.x = old_end.x; w2.end.y = old_end.y; + w2.flags = Wall::FLAG_TOUCHED; InsertLine(sector.walls, i + 1, w1); InsertLine(sector.walls, i + 2, w2); + KP3D_LOG_INFO("{} IS CONNECTED TO {}", sector.id, s.id); + // Mark the other one as an opening // This really shouldn't be necessary I think, but whatever l.textures[TEX_FRONT] = nullptr; - l.flags = Wall::FLAG_OPENING; + l.flags = Wall::FLAG_OPENING | Wall::FLAG_TOUCHED; l.portal = §or; } } @@ -337,10 +358,10 @@ void Map::Init() BuildGrid(); static Texture tex, tex2, tex3, tex4; - tex.Load("GRASS2.png"); - tex2.Load("floor0.png"); - tex3.Load("FLAT5_7.png"); - tex4.Load("block.png"); + tex.Load("GRASS2.png", true); + tex2.Load("floor0.png", true); + tex3.Load("FLAT5_7.png", true); + tex4.Load("block.png", true); m_dot.Load("dot.png"); // Build a stupid little test map @@ -371,7 +392,7 @@ void Map::Init() float scl = 1.0f; for (size_t i = 0; i < num_points; i++) s.walls.push_back(Wall{ {wall,wall,wall}, {{0, 0}}, points[i], points[(i + 1) % num_points], Wall::NO_FLAGS, (uint)i }); - sectors.push_back(s); + original_sectors.push_back(s); }; build_sector(&tex3, &tex, &tex2, -1.0f, 5.0f, 1, points, std::size(points)); build_sector(&tex4, &tex2, &tex2, -1.5f, 4.0f, 2, points2, std::size(points2)); @@ -380,6 +401,19 @@ void Map::Init() build_sector(&tex3, &tex, &tex2, test_u, test_l, 5, points5, std::size(points5), false); build_sector(&tex4, &tex4, &tex4, 1.0f, 1.4f, 6, points6, std::size(points6), true); + Rebuild(GEN_NORMALS); +} + +void Map::Rebuild(NormalGenType gen_normals) +{ + m_mesh.Reset(); + + sectors.clear(); + for (Sector& s : original_sectors) + { + sectors.push_back(s); + } + // Correct sectors with counter-clockwise linedef order using the shoelace formula, // also while we're at it grab the sector areas (will be useful later) and reset old data. int i = 0; @@ -387,6 +421,7 @@ void Map::Init() { // Since we're regenerating the map, we don't want to re-use this data, it may be old. s.children.clear(); + s.area = 0.0f; s.flags = Sector::NO_FLAGS; s.parent_id = 0; s.id = ++i; @@ -402,6 +437,7 @@ void Map::Init() l.flags |= Wall::FLAG_TOUCHED; if (no_collisions) l.flags |= Wall::FLAG_NO_COLLISION; + l.portal = nullptr; area += l.start.x * l.end.y; area -= l.end.x * l.start.y; @@ -433,7 +469,7 @@ void Map::Init() } } -#if 0 +#if 1 // Debug: Print out the sector hierachy KP3D_LOG_INFO("SECTOR HIERARCHY"); for (Sector& s: sectors) @@ -482,8 +518,8 @@ void Map::Init() { float yv0 = PerlinNoise2D(steiner_point.x, steiner_point.y, 1.0, 10.0); float yv1 = -PerlinNoise2D(steiner_point.x, steiner_point.y, 0.5, 9.0); - s.floor.steiner_points.push_back({ steiner_point.x, yv0, steiner_point.y }); - s.ceiling.steiner_points.push_back({ steiner_point.x, yv1, steiner_point.y }); + //s.floor.steiner_points.push_back({ steiner_point.x, yv0, steiner_point.y }); + //s.ceiling.steiner_points.push_back({ steiner_point.x, yv1, steiner_point.y }); } } } @@ -514,12 +550,6 @@ void Map::Init() } // Finalize the mesh - m_mesh.Finalize(); -} - -void Map::Rebuild(NormalGenType gen_normals) -{ - // This routine is really just here for me to test smooth normal generation; in the future, everything in Init() should go here m_mesh.Finalize(gen_normals); } @@ -622,16 +652,19 @@ void Map::RenderSkybox() void Map::BuildGrid() { m_grid_shader.Load(".kp3d/map_grid_v.glsl", ".kp3d/map_grid_f.glsl"); - m_grid_texture.Load(".kp3d/map_grid.png", false, kp3d::Texture::FILTER_LINEAR); + m_grid_texture.Load(".kp3d/map_grid.png", true, kp3d::Texture::FILTER_LINEAR); m_grid_mesh.AddBatch(&m_grid_texture, { - Vertex3D(Vec3(-0.5f, -0.5f, 0.0f), Vec2(0.0f, 1.0f)), - Vertex3D(Vec3(-0.5f, 0.5f, 0.0f), Vec2(0.0f, 0.0f)), - Vertex3D(Vec3( 0.5f, -0.5f, 0.0f), Vec2(1.0f, 1.0f)), - Vertex3D(Vec3(-0.5f, 0.5f, 0.0f), Vec2(0.0f, 0.0f)), - Vertex3D(Vec3( 0.5f, 0.5f, 0.0f), Vec2(1.0f, 0.0f)), - Vertex3D(Vec3( 0.5f, -0.5f, 0.0f), Vec2(1.0f, 1.0f)) - }, true); + Vertex3D(Vec3(-0.5f, 0.0f, 0.5f), Vec2(0.0f, 1.0f)), + Vertex3D(Vec3(-0.5f, 0.0f, -0.5f), Vec2(0.0f, 0.0f)), + Vertex3D(Vec3( 0.5f, 0.0f, 0.5f), Vec2(1.0f, 1.0f)), + Vertex3D(Vec3(-0.5f, 0.0f, -0.5f), Vec2(0.0f, 0.0f)), + Vertex3D(Vec3( 0.5f, 0.0f, -0.5f), Vec2(1.0f, 0.0f)), + Vertex3D(Vec3( 0.5f, 0.0f, 0.5f), Vec2(1.0f, 1.0f)) + }, false); m_grid_mesh.Finalize(); + for (const RenderBatch3D& batch: m_grid_mesh.GetBatchesRef()) + for (int i = 0; i < batch.vertex_data.size(); i++) + grid_box[i] = batch.vertex_data[i].position * 1000.0f; } void Map::RenderGrid() @@ -639,7 +672,7 @@ void Map::RenderGrid() Renderer3D::PushShader(m_grid_shader); Vec3 camera_pos = Renderer3D::GetPrimaryCamera()->position; camera_pos.y = 0.0f; - Transform grid_transform(camera_pos, {ToRadians(90.0f), 0.0, 0.0}, {1000.0, 1000.0, 0.0}); + Transform grid_transform(camera_pos, {0.0, 0.0, 0.0}, {1000.0, 0.0, 1000.0}); glDisable(GL_CULL_FACE); Renderer3D::DrawMesh(m_grid_mesh, grid_transform); glEnable(GL_CULL_FACE); diff --git a/KP3Dii/src/KP3D_Map.h b/KP3Dii/src/KP3D_Map.h index 29bdc23..6f500be 100644 --- a/KP3Dii/src/KP3D_Map.h +++ b/KP3Dii/src/KP3D_Map.h @@ -122,9 +122,11 @@ public: void RenderGrid(); public: + std::vector original_sectors; std::vector sectors; bool render_wireframe = true; float texture_scale = 128.0f; + Vec3 grid_box[6]; float test_u = -1.5f, test_l = 3.0f; diff --git a/KP3Dii/src/KP3D_Raycast.cpp b/KP3Dii/src/KP3D_Raycast.cpp index 17f06a6..4a65d1f 100644 --- a/KP3Dii/src/KP3D_Raycast.cpp +++ b/KP3Dii/src/KP3D_Raycast.cpp @@ -55,6 +55,9 @@ bool RayIntersectsTriangle(const Vec3& ray_origin, const Vec3& ray_vector, Trian Vec3 vertex0 = in_triangle->vertices[0]; Vec3 vertex1 = in_triangle->vertices[1]; Vec3 vertex2 = in_triangle->vertices[2]; + // vertex0 *= Vec3(1, 1, -1); + // vertex1 *= Vec3(1, 1, -1); + // vertex2 *= Vec3(1, 1, -1); Vec3 edge1, edge2, h, s, q; float a, f, u, v; edge1 = vertex1 - vertex0; diff --git a/KP3Dii/src/KP3D_Renderer2D.cpp b/KP3Dii/src/KP3D_Renderer2D.cpp index 6dcf998..ca695d1 100644 --- a/KP3Dii/src/KP3D_Renderer2D.cpp +++ b/KP3Dii/src/KP3D_Renderer2D.cpp @@ -147,6 +147,11 @@ void Renderer2D::ResetShader() r2d_state->shader = &r2d_state->default_shader; } +const Texture& Renderer2D::GetDefaultTexture() +{ + return r2d_state->default_texture; +} + void Renderer2D::PushVertex(float x, float y, float r, float g, float b, float a, float u, float v) { assert(r2d_state->num_vertices + V_BUFFER_SIZE < sizeof(r2d_state->vdata)); diff --git a/KP3Dii/src/KP3D_Renderer2D.h b/KP3Dii/src/KP3D_Renderer2D.h index 3015adc..a56d0a9 100644 --- a/KP3Dii/src/KP3D_Renderer2D.h +++ b/KP3Dii/src/KP3D_Renderer2D.h @@ -30,6 +30,8 @@ public: static void SetShader(const Shader& shader); static void ResetShader(); + static const Texture& GetDefaultTexture(); + static void PushVertex(float x, float y, float r, float g, float b, float a, float u, float v); static void DrawRect(float x, float y, float w, float h, uint rgba = COLOR_WHITE); diff --git a/KP3Dii/src/KP3D_Renderer3D.cpp b/KP3Dii/src/KP3D_Renderer3D.cpp index c518e29..3e90a02 100644 --- a/KP3Dii/src/KP3D_Renderer3D.cpp +++ b/KP3Dii/src/KP3D_Renderer3D.cpp @@ -11,9 +11,16 @@ #include "KP3D_Texture.h" #include "KP3D_Time.h" #include "KP3D_Transform.h" +#include "KP3D_Color.h" +#include "KP3D_Renderer2D.h" namespace { +constexpr kp3d::uint V_POSITION_SIZE = 3; +constexpr kp3d::uint V_COLOR_SIZE = 4, V_COLOR_OFFSET = 3 * sizeof(float); +constexpr kp3d::uint V_TEXCOORD_SIZE = 2, V_TEXCOORD_OFFSET = 7 * sizeof(float); +constexpr kp3d::uint V_BUFFER_SIZE = 9, V_MAX = 4096; + struct RenderState3D { const kp3d::Camera* v; @@ -32,10 +39,100 @@ struct RenderState3D const kp3d::Shader* shader; bool active; + + // "Legacy rendering" stuff; immediate mode GL emulation (similar to Renderer2D) + kp3d::uint lr_num_vertices; + kp3d::uint lr_num_vertices_last_flushed; + GLuint lr_gl_vao_id; + GLuint lr_gl_vbo_id; + const kp3d::Texture* lr_texture; + float lr_vdata[V_MAX * V_BUFFER_SIZE]; + kp3d::Shader lr_shader; }; std::unique_ptr r3d_state; +void LR_Flush() +{ + if (!r3d_state->lr_num_vertices) + return; + + r3d_state->lr_texture->Bind(); + + kp3d::Mat4 m = kp3d::Transform().GetProjectedTransformationMatrix(*r3d_state->v, *r3d_state->p); + // kp3d::Renderer3D::PushShader(r3d_state->lr_shader); + r3d_state->shader = &r3d_state->lr_shader; + r3d_state->shader->Bind(); + r3d_state->shader->SetUniform("u_mvp", m); + r3d_state->shader->SetUniform("u_campos", r3d_state->v->position); + r3d_state->shader->SetUniform("u_time", r3d_state->time); + + glBindVertexArray(r3d_state->lr_gl_vao_id); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + glBindBuffer(GL_ARRAY_BUFFER, r3d_state->lr_gl_vbo_id); + glBufferData(GL_ARRAY_BUFFER, sizeof(r3d_state->lr_vdata), r3d_state->lr_vdata, GL_DYNAMIC_DRAW); + + glVertexAttribPointer(0, V_POSITION_SIZE, GL_FLOAT, false, V_BUFFER_SIZE * sizeof(float), nullptr); + glVertexAttribPointer( + 1, V_COLOR_SIZE, GL_FLOAT, false, V_BUFFER_SIZE * sizeof(float), reinterpret_cast(V_COLOR_OFFSET) + ); + glVertexAttribPointer( + 2, V_TEXCOORD_SIZE, GL_FLOAT, false, V_BUFFER_SIZE * sizeof(float), reinterpret_cast(V_TEXCOORD_OFFSET) + ); + + glDrawArrays(GL_TRIANGLES, 0, r3d_state->lr_num_vertices); + + glDisableVertexAttribArray(2); + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(0); + glBindVertexArray(0); + + std::fill_n(r3d_state->lr_vdata, std::size(r3d_state->lr_vdata), 0.0f); + + r3d_state->lr_num_vertices_last_flushed += r3d_state->lr_num_vertices; + r3d_state->lr_num_vertices = 0; + + //kp3d::Renderer3D::PopShader(); +} + +void LR_FlushOnOverflow(kp3d::uint batch_size) +{ + if (r3d_state->lr_num_vertices + batch_size > V_MAX) + LR_Flush(); +} + + +void LR_PushVertex(float x, float y, float z, float r, float g, float b, float a, float u, float v) +{ + assert(r3d_state->lr_num_vertices + V_BUFFER_SIZE < sizeof(r3d_state->lr_vdata)); + + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 0] = x; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 1] = y; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 2] = z; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 3] = r; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 4] = g; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 5] = b; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 6] = a; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 7] = u; + r3d_state->lr_vdata[r3d_state->lr_num_vertices + 8] = v; + + r3d_state->lr_num_vertices += V_BUFFER_SIZE; +} + +void LR_SetTexture(const kp3d::Texture& texture) +{ + if (r3d_state->lr_texture->GetGLID() == texture.GetGLID()) + return; + + LR_Flush(); + + r3d_state->lr_texture = &texture; + r3d_state->lr_texture->Bind(); +} + } // namespace namespace kp3d { @@ -62,6 +159,9 @@ void Renderer3D::End() return; } + r3d_state->lr_num_vertices_last_flushed = 0; + LR_Flush(); + r3d_state->active = false; } @@ -292,6 +392,31 @@ void Renderer3D::DrawModel(Model& model, Transform& m) DrawModel(model, m.GetProjectedTransformationMatrix(*r3d_state->v, *r3d_state->p)); } +void Renderer3D::DrawLine(const Vec3& start, const Vec3& end, float thickness, uint rgba) +{ + using namespace util_color_index; + + std::array in_floats = ColorToFloats(rgba); + + LR_SetTexture(Renderer2D::GetDefaultTexture()); + LR_FlushOnOverflow(6); + + float angle = atan2(start.z - end.z, start.x - end.x) - ToRadians(90.0f); + + Vec3 v0 = { start.x - cosf(angle) * thickness, start.y, start.z - sinf(angle) * thickness }; + Vec3 v1 = { start.x + cosf(angle) * thickness, start.y, start.z + sinf(angle) * thickness }; + Vec3 v2 = { end.x + cosf(angle) * thickness, end.y, end.z + sinf(angle) * thickness }; + Vec3 v3 = { end.x - cosf(angle) * thickness, end.y, end.z - sinf(angle) * thickness }; + + LR_PushVertex(v0.x, v0.y, v0.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 0.0f, 0.0f); + LR_PushVertex(v1.x, v1.y, v1.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 1.0f, 0.0f); + LR_PushVertex(v3.x, v3.y, v3.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 0.0f, 1.0f); + LR_PushVertex(v2.x, v2.y, v2.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 1.0f, 1.0f); + LR_PushVertex(v3.x, v3.y, v3.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 0.0f, 1.0f); + LR_PushVertex(v1.x, v1.y, v1.z, in_floats[R], in_floats[G], in_floats[B], in_floats[A], 1.0f, 0.0f); + +} + void Renderer3D::PushShader(const Shader& shader) { if (r3d_state->shader->GetGLID() == shader.GetGLID()) @@ -387,11 +512,20 @@ void Renderer3D::Init() r3d_state->default_shader.Load(".kp3d/r3d_v.glsl", ".kp3d/r3d_f.glsl"); r3d_state->shader = &r3d_state->default_shader; + + glGenVertexArrays(1, &r3d_state->lr_gl_vao_id); + glBindVertexArray(r3d_state->lr_gl_vao_id); + + glGenBuffers(1, &r3d_state->lr_gl_vbo_id); + + r3d_state->lr_shader.Load(".kp3d/r3d_legacy_v.glsl", ".kp3d/r3d_legacy_f.glsl"); + r3d_state->lr_texture = &Renderer2D::GetDefaultTexture(); } void Renderer3D::Destroy() { - // ... + glDeleteBuffers(1, &r3d_state->lr_gl_vbo_id); + glDeleteVertexArrays(1, &r3d_state->lr_gl_vao_id); } } // namespace kp3d diff --git a/KP3Dii/src/KP3D_Renderer3D.h b/KP3Dii/src/KP3D_Renderer3D.h index 5a8063b..68dc2b3 100644 --- a/KP3Dii/src/KP3D_Renderer3D.h +++ b/KP3Dii/src/KP3D_Renderer3D.h @@ -39,6 +39,8 @@ public: static void DrawModel(Model& model, const Mat4& m); static void DrawModel(Model& model, Transform& m); + static void DrawLine(const Vec3& start, const Vec3& end, float thickness = 1.0f, uint rgba = 0xFFFFFFFF); + static void PushShader(const Shader& shader); static void PopShader(); static void ReloadShaders(); diff --git a/KP3Dii/src/KP3D_Texture.cpp b/KP3Dii/src/KP3D_Texture.cpp index cfe0c42..6245ed7 100644 --- a/KP3Dii/src/KP3D_Texture.cpp +++ b/KP3Dii/src/KP3D_Texture.cpp @@ -79,8 +79,8 @@ Texture::Load(const byte* data, int width, int height, bool mipmap, FilterMode f if (mipmap) { - glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR); + glGenerateMipmap(GL_TEXTURE_2D); } glBindTexture(GL_TEXTURE_2D, 0); diff --git a/Sandbox/src/Editor.cpp b/Sandbox/src/Editor.cpp index 95705d1..328a5f8 100644 --- a/Sandbox/src/Editor.cpp +++ b/Sandbox/src/Editor.cpp @@ -3,17 +3,34 @@ #include #include "KP3D_Renderer3D.h" +#include "KP3D_Raycast.h" +#include "KP3D_Math.h" +#include "KP3D_Geometry.h" #include "Sandbox.h" namespace { constexpr float MIN_DISTANCE_FROM_PLAYER = 0.1f; constexpr float MAX_DISTANCE_FROM_PLAYER = 100.0f; + +std::vector points; + +inline float Align(float value, float size) +{ + return value - (std::fmod(value, size)); +} + +inline float Distance(kp3d::Vec3 a, kp3d::Vec3 b) +{ + return sqrtf((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y) + (b.z - a.z) * (b.z - a.z)); +} + } Editor::Editor() { m_stem.Load("editor/stem.png"); + m_block.Load("block.png", true); } Editor::~Editor() @@ -24,34 +41,105 @@ void Editor::Init() { } +void Editor::Update() +{ + if (sandbox->IsMouseButtonDown(kp3d::MOUSE_BUTTON_LEFT)) + { + points.push_back(m_stem_pos); + + if (points.size() >= 3 && kp3d::PosCmp(points.back(), points.front(), 1.0f / 128.0f))// points.back() == points.front()) + { + kp3d::Sector s; + s.ceiling.texture = &m_block; + s.floor.texture = &m_block; + s.floor.floor = true; + s.floor.base_height = 0.0f; + s.ceiling.base_height = 2.0f; + s.id = sandbox->map.sectors.size() + 1; + s.parent_id = 0; + s.inverted = false; + for (int i = 0; i < points.size() - 1; i++) + { + kp3d::Wall wall; + wall.start = {points[i].x, -points[i].z}; + wall.end = {points[i+1].x, -points[i+1].z}; + wall.uid = i; + for (int j = 0; j < 3; j++) + wall.textures[j] = &m_block; + + s.walls.push_back(wall); + } + + sandbox->map.original_sectors.push_back(s); + sandbox->map.Rebuild(kp3d::GEN_NORMALS); + + points.clear(); + } + + sandbox->MouseButtonReset(kp3d::MOUSE_BUTTON_LEFT); + } +} + void Editor::RenderMap() { + // Render the map grid sandbox->map.RenderGrid(); - RenderStem({5.0f, 0.0f, 0.0f}); + + // Render the points we're drawing + if (points.size() > 1) + { + for (int i = 0; i < points.size() - 1; i++) + { + kp3d::Vec3 p0 = points[i]; + kp3d::Vec3 p1 = points[i + 1]; + + float target_thickness = 1.0f / 128.0f; + float thickness = target_thickness; + kp3d::Vec3 player_distance = ((p0 + p1) * 0.5f) - sandbox->camera.position; + float d = sqrtf( + player_distance.x * player_distance.x + player_distance.y * player_distance.y + player_distance.z * player_distance.z + ); + if (d < 0.01f) + d = 0.01f; + thickness *= d; + if (thickness > target_thickness) + thickness = target_thickness; + p0.y += 0.01f; + p1.y += 0.01f; + + kp3d::Renderer3D::DrawLine(p0, p1, thickness * d, 0xFF0000FF); + } + } + + // Render the "stem" + auto ray = kp3d::GetRayFromCamera(sandbox->camera); + kp3d::Vec3 pos{5,0,0}; + float dist = 0.0f; + kp3d::Triangle tri0 = {{sandbox->map.grid_box[0], sandbox->map.grid_box[1], sandbox->map.grid_box[2]}, 0, 0}; + kp3d::Triangle tri1 = {{sandbox->map.grid_box[3], sandbox->map.grid_box[4], sandbox->map.grid_box[5]}, 0, 0}; + bool on_grid = kp3d::RayIntersectsTriangle(ray[0], ray[1], &tri0, pos) || kp3d::RayIntersectsTriangle(ray[0], ray[1], &tri1, pos); + pos.x = Align(pos.x, 1.0f); + pos.z = Align(pos.z, 1.0f); + RenderStem(pos); + m_stem_pos = pos; + } void Editor::RenderStem(kp3d::Vec3 position) { using namespace kp3d; - Vec2 size = { - 1.0f, - (float)m_stem.GetHeight() / (float)m_stem.GetWidth() - }; + Vec2 size = {1.0f, (float) m_stem.GetHeight() / (float) m_stem.GetWidth()}; const Camera* camera = Renderer3D::GetPrimaryCamera(); kp3d::Vec3 player_distance = position - camera->position; float vec_distance = sqrtf( - player_distance.x * player_distance.x + - player_distance.y * player_distance.y + - player_distance.z * player_distance.z + player_distance.x * player_distance.x + player_distance.y * player_distance.y + player_distance.z * player_distance.z ); - float scale = vec_distance; - scale *= 0.1f; - - if (scale < MIN_DISTANCE_FROM_PLAYER) - scale = MIN_DISTANCE_FROM_PLAYER; - if (scale > MAX_DISTANCE_FROM_PLAYER) - scale = MAX_DISTANCE_FROM_PLAYER; + float scale = 1.0f; + if (vec_distance > scale) + scale = vec_distance * 0.1f; + if (scale > 1.0f) + scale = 1.0f; size.x *= scale; size.y *= scale; diff --git a/Sandbox/src/Editor.h b/Sandbox/src/Editor.h index 7f9f553..8074814 100644 --- a/Sandbox/src/Editor.h +++ b/Sandbox/src/Editor.h @@ -10,11 +10,14 @@ public: ~Editor(); void Init(); + void Update(); void RenderMap(); void RenderStem(kp3d::Vec3 position); void RenderUI(); private: kp3d::Texture m_stem; + kp3d::Texture m_block; + kp3d::Vec3 m_stem_pos; }; diff --git a/Sandbox/src/Sandbox.cpp b/Sandbox/src/Sandbox.cpp index f15f42b..c929aa3 100644 --- a/Sandbox/src/Sandbox.cpp +++ b/Sandbox/src/Sandbox.cpp @@ -59,6 +59,9 @@ void Sandbox::Update() if (kp3d::console::open || m_mode == MODE_MENU) return; + if (m_mode == MODE_EDIT) + editor.Update(); + if (IsKeyDown(kp3d::KEY_F1)) { map.render_wireframe ^= 1; @@ -76,7 +79,7 @@ void Sandbox::Update() } if (IsKeyDown(kp3d::KEY_B)) { - map.Init(); + //map.Init(); //map.Rebuild(kp3d::GEN_NORMALS); //KeyReset(kp3d::KEY_B); } @@ -98,18 +101,18 @@ void Sandbox::Update() } float qerf_speed = 1.0f; float move_speed = 0.2f; - if (IsKeyDown(kp3d::KEY_W)) m_camera.Move(m_camera.forward, move_speed); - if (IsKeyDown(kp3d::KEY_S)) m_camera.Move(m_camera.forward, -move_speed); - if (IsKeyDown(kp3d::KEY_A)) m_camera.Move(m_camera.right, move_speed); - if (IsKeyDown(kp3d::KEY_D)) m_camera.Move(m_camera.right, -move_speed); - if (IsKeyDown(kp3d::KEY_SPACE)) m_camera.position.y += move_speed; - if (IsKeyDown(kp3d::KEY_LSHIFT)) m_camera.position.y -= move_speed; - if (IsKeyDown(kp3d::KEY_Q)) m_camera.Rotate(kp3d::Camera::AXIS_X, qerf_speed); - if (IsKeyDown(kp3d::KEY_E)) m_camera.Rotate(kp3d::Camera::AXIS_X, -qerf_speed); - if (IsKeyDown(kp3d::KEY_R)) m_camera.Rotate(kp3d::Camera::AXIS_Y, qerf_speed); - if (IsKeyDown(kp3d::KEY_F)) m_camera.Rotate(kp3d::Camera::AXIS_Y, -qerf_speed); - ResetMouseCursor([&](float x, float y) { m_camera.UpdateMouseLook({x, y}); }); - m_camera.UpdateMatrix(); + if (IsKeyDown(kp3d::KEY_W)) camera.Move(camera.forward, move_speed); + if (IsKeyDown(kp3d::KEY_S)) camera.Move(camera.forward, -move_speed); + if (IsKeyDown(kp3d::KEY_A)) camera.Move(camera.right, move_speed); + if (IsKeyDown(kp3d::KEY_D)) camera.Move(camera.right, -move_speed); + if (IsKeyDown(kp3d::KEY_SPACE)) camera.position.y += move_speed; + if (IsKeyDown(kp3d::KEY_LSHIFT)) camera.position.y -= move_speed; + if (IsKeyDown(kp3d::KEY_Q)) camera.Rotate(kp3d::Camera::AXIS_X, qerf_speed); + if (IsKeyDown(kp3d::KEY_E)) camera.Rotate(kp3d::Camera::AXIS_X, -qerf_speed); + if (IsKeyDown(kp3d::KEY_R)) camera.Rotate(kp3d::Camera::AXIS_Y, qerf_speed); + if (IsKeyDown(kp3d::KEY_F)) camera.Rotate(kp3d::Camera::AXIS_Y, -qerf_speed); + ResetMouseCursor([&](float x, float y) { camera.UpdateMouseLook({x, y}); }); + camera.UpdateMatrix(); } void Sandbox::Render() @@ -120,7 +123,7 @@ void Sandbox::Render() if (m_mode == MODE_GAME || m_mode == MODE_EDIT) { // 3D scene - kp3d::Renderer3D::Begin(m_camera, m_projection); + kp3d::Renderer3D::Begin(camera, m_projection); map.Render(); if (m_mode == MODE_EDIT) editor.RenderMap(); diff --git a/Sandbox/src/Sandbox.h b/Sandbox/src/Sandbox.h index 1739458..9e06939 100644 --- a/Sandbox/src/Sandbox.h +++ b/Sandbox/src/Sandbox.h @@ -31,11 +31,11 @@ public: // Temp kp3d::Map map; Editor editor; + kp3d::Camera camera; private: // KP3D essentials kp3d::Mat4 m_projection; - kp3d::Camera m_camera; int m_mode; }; diff --git a/x64/Debug/assimp-vc143-mt.dll b/x64/Debug/assimp-vc143-mt.dll new file mode 100644 index 0000000..8ee29bb Binary files /dev/null and b/x64/Debug/assimp-vc143-mt.dll differ diff --git a/x64/Debug/zlib1.dll b/x64/Debug/zlib1.dll new file mode 100644 index 0000000..5b14bbf Binary files /dev/null and b/x64/Debug/zlib1.dll differ