Refactors, lots and lots of it... plus coodinate space
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package sectr
|
||||
|
||||
import "base:runtime"
|
||||
import "core:fmt"
|
||||
|
||||
import rl "vendor:raylib"
|
||||
@ -19,6 +20,7 @@ DebugActions :: struct {
|
||||
cam_move_left : b32,
|
||||
cam_move_down : b32,
|
||||
cam_move_right : b32,
|
||||
cam_mouse_pan : b32,
|
||||
}
|
||||
|
||||
poll_debug_actions :: proc( actions : ^ DebugActions, input : ^ InputState )
|
||||
@ -26,6 +28,13 @@ poll_debug_actions :: proc( actions : ^ DebugActions, input : ^ InputState )
|
||||
using actions
|
||||
using input
|
||||
|
||||
modifier_active := keyboard.right_alt.ended_down ||
|
||||
keyboard.right_control.ended_down ||
|
||||
keyboard.right_shift.ended_down ||
|
||||
keyboard.left_alt.ended_down ||
|
||||
keyboard.left_control.ended_down ||
|
||||
keyboard.left_shift.ended_down
|
||||
|
||||
load_project = keyboard.left_control.ended_down && pressed( keyboard.O )
|
||||
save_project = keyboard.left_control.ended_down && pressed( keyboard.S )
|
||||
|
||||
@ -35,10 +44,12 @@ poll_debug_actions :: proc( actions : ^ DebugActions, input : ^ InputState )
|
||||
|
||||
show_mouse_pos = keyboard.right_alt.ended_down && pressed(keyboard.M)
|
||||
|
||||
cam_move_up = keyboard.W.ended_down
|
||||
cam_move_left = keyboard.A.ended_down
|
||||
cam_move_down = keyboard.S.ended_down
|
||||
cam_move_right = keyboard.D.ended_down
|
||||
cam_move_up = keyboard.W.ended_down && ( ! modifier_active || keyboard.left_shift.ended_down )
|
||||
cam_move_left = keyboard.A.ended_down && ( ! modifier_active || keyboard.left_shift.ended_down )
|
||||
cam_move_down = keyboard.S.ended_down && ( ! modifier_active || keyboard.left_shift.ended_down )
|
||||
cam_move_right = keyboard.D.ended_down && ( ! modifier_active || keyboard.left_shift.ended_down )
|
||||
|
||||
cam_mouse_pan = mouse.right.ended_down && ! pressed(mouse.right)
|
||||
}
|
||||
|
||||
update :: proc( delta_time : f64 ) -> b32
|
||||
@ -46,6 +57,14 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
state := get_state(); using state
|
||||
replay := & memory.replay
|
||||
|
||||
if rl.IsWindowResized() {
|
||||
window := & state.app_window
|
||||
window.extent.x = f32(rl.GetScreenWidth()) * 0.5
|
||||
window.extent.y = f32(rl.GetScreenHeight()) * 0.5
|
||||
|
||||
project.workspace.cam.offset = transmute(Vec2) window.extent
|
||||
}
|
||||
|
||||
state.input, state.input_prev = swap( state.input, state.input_prev )
|
||||
poll_input( state.input_prev, state.input )
|
||||
|
||||
@ -110,14 +129,12 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
debug.mouse_vis = !debug.mouse_vis
|
||||
}
|
||||
|
||||
debug.mouse_pos = { input.mouse.X, input.mouse.Y }
|
||||
|
||||
// Camera Manual Nav
|
||||
{
|
||||
move_speed : f32 = 200.0
|
||||
zoom_sensitiviity : f32 = 3.5
|
||||
digital_move_speed : f32 = 200.0
|
||||
zoom_sensitiviity : f32 = 3.5
|
||||
|
||||
cam := & project.workspace.cam
|
||||
cam := & project.workspace.cam
|
||||
cam.zoom *= 1 + input.mouse.vertical_wheel * zoom_sensitiviity * f32(delta_time)
|
||||
cam.zoom = clamp( cam.zoom, 0.05, 10.0 )
|
||||
|
||||
@ -125,10 +142,20 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
- cast(f32) i32(debug_actions.cam_move_left) + cast(f32) i32(debug_actions.cam_move_right),
|
||||
- cast(f32) i32(debug_actions.cam_move_up) + cast(f32) i32(debug_actions.cam_move_down),
|
||||
}
|
||||
move_velocity *= move_speed * f32(delta_time)
|
||||
move_velocity *= digital_move_speed * f32(delta_time)
|
||||
cam.target += move_velocity
|
||||
|
||||
if debug_actions.cam_mouse_pan
|
||||
{
|
||||
if is_within_screenspace(input.mouse.pos) {
|
||||
pan_velocity := input.mouse.delta * (1/cam.zoom)
|
||||
cam.target -= pan_velocity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug.last_mouse_pos = input.mouse.pos
|
||||
|
||||
should_shutdown : b32 = ! cast(b32) rl.WindowShouldClose()
|
||||
return should_shutdown
|
||||
}
|
||||
|
Reference in New Issue
Block a user