Karl Zylinski 6 mesi fa
parent
commit
b59933ec68
3 ha cambiato i file con 22 aggiunte e 5 eliminazioni
  1. 8 5
      karl2d.odin
  2. 5 0
      window_interface.odin
  3. 9 0
      window_win32.odin

+ 8 - 5
karl2d.odin

@@ -101,6 +101,7 @@ process_events :: proc() {
 	s.keys_went_up = {}
 	s.keys_went_down = {}
 	s.mouse_delta = {}
+	s.mouse_wheel_delta = 0
 
 	win.process_events()
 
@@ -123,6 +124,9 @@ process_events :: proc() {
 			prev_pos := s.mouse_position
 			s.mouse_position = e.position
 			s.mouse_delta = prev_pos - s.mouse_position
+
+		case Window_Event_Mouse_Wheel:
+			s.mouse_wheel_delta = e.delta
 		}
 	}
 
@@ -196,12 +200,10 @@ set_camera :: proc(camera: Maybe(Camera)) {
 	if c, c_ok := camera.?; c_ok {
 		origin_trans := linalg.matrix4_translate(vec3_from_vec2(-c.origin))
 		translate := linalg.matrix4_translate(vec3_from_vec2(c.target))
+		scale := linalg.matrix4_scale(Vec3{c.zoom, c.zoom, 1})
 		rot := linalg.matrix4_rotate_f32(c.rotation * math.RAD_PER_DEG, {0, 0, 1})
-		camera_matrix := translate * rot * origin_trans
+		camera_matrix := translate * rot *scale* origin_trans
 		s.view_matrix = linalg.inverse(camera_matrix)
-		
-		s.proj_matrix[0, 0] *= c.zoom
-		s.proj_matrix[1, 1] *= c.zoom
 	} else {
 		s.view_matrix = 1
 	}
@@ -546,7 +548,7 @@ mouse_button_is_held :: proc(button: Mouse_Button) -> bool {
 }
 
 get_mouse_wheel_delta :: proc() -> f32 {
-	return 0
+	return s.mouse_wheel_delta
 }
 
 get_mouse_position :: proc() -> Vec2 {
@@ -609,6 +611,7 @@ State :: struct {
 
 	mouse_position: Vec2,
 	mouse_delta: Vec2,
+	mouse_wheel_delta: f32,
 
 	keys_went_down: #sparse [Keyboard_Key]bool,
 	keys_went_up: #sparse [Keyboard_Key]bool,

+ 5 - 0
window_interface.odin

@@ -18,6 +18,7 @@ Window_Event :: union  {
 	Window_Event_Key_Went_Down,
 	Window_Event_Key_Went_Up,
 	Window_Event_Mouse_Move,
+	Window_Event_Mouse_Wheel,
 }
 
 Window_Event_Key_Went_Down :: struct {
@@ -32,4 +33,8 @@ Window_Event_Close_Wanted :: struct {}
 
 Window_Event_Mouse_Move :: struct {
 	position: Vec2,
+}
+
+Window_Event_Mouse_Wheel :: struct {
+	delta: f32,
 }

+ 9 - 0
window_win32.odin

@@ -4,6 +4,8 @@ package karl2d
 
 import win32 "core:sys/windows"
 import "base:runtime"
+import "core:log"
+_ :: log
 
 WINDOW_INTERFACE_WIN32 :: Window_Interface {
 	state_size = win32_state_size,
@@ -143,6 +145,13 @@ _win32_window_proc :: proc "stdcall" (hwnd: win32.HWND, msg: win32.UINT, wparam:
 		})
 
 		return 0
+
+	case win32.WM_MOUSEWHEEL:
+		delta := -f32(win32.GET_WHEEL_DELTA_WPARAM(wparam))/win32.WHEEL_DELTA
+
+		append(&s.events, Window_Event_Mouse_Wheel {
+			delta = delta,
+		})
 	}
 
 	return win32.DefWindowProcW(hwnd, msg, wparam, lparam)