Improvements my frien

This commit is contained in:
2024-10-30 23:45:16 +01:00
parent acd9f42286
commit cb55590e03
6 changed files with 33 additions and 13 deletions

View File

@@ -133,7 +133,7 @@ world_to_screen :: (camera: Camera, world_position: Vector3) -> Vector3 {
return screen_position;
}
screen_to_world :: (camera: Camera, screen_position: Vector2) -> Vector3 {
screen_to_world :: (camera: Camera, screen_position: Vector2, distance: float) -> Vector3 {
pos : Vector4;
pos.x = (screen_position.x / cast(float)engine.renderer.render_target_width) * 2.0 - 1.0;
pos.y = (screen_position.y / cast(float)engine.renderer.render_target_height) * 2.0 - 1.0;
@@ -145,10 +145,18 @@ screen_to_world :: (camera: Camera, screen_position: Vector2) -> Vector3 {
result.y /= result.w;
result.z /= result.w;
// Calculate world direction by subtracting camera position and normalizing
direction : Vector3;
direction.x = result.x - camera.position.x;
direction.y = result.y - camera.position.y;
direction.z = result.z - camera.position.z;
direction = normalize(direction);
// Scale the direction to the specified distance
world_position : Vector3;
world_position.x = result.x;
world_position.y = result.y;
world_position.z = result.z;
world_position.x = camera.position.x + direction.x * distance;
world_position.y = camera.position.y + direction.y * distance;
world_position.z = camera.position.z + direction.z * distance;
return world_position;
}

View File

@@ -128,8 +128,6 @@ Gamepad :: struct {
MAX_GAMEPADS :: 4;
MAX_MAPPINGS :: 4;
Action :: enum {}
Action_Mapping :: struct {
gamepad_buttons: [MAX_MAPPINGS] Gamepad_Button;
keys: [MAX_MAPPINGS] Key_Code;

View File

@@ -1,5 +1,5 @@
key_mappings : Table(SDL_Keycode, Key_Code);
sdl_button_map : [SDL_CONTROLLER_BUTTON_MAX] Gamepad_Button;
sdl_button_map : Table(SDL_GameControllerButton, Gamepad_Button);
init_sdl_input :: () {
table_add(*key_mappings, SDLK_a, .A);//[SDLK_a] = .A;
@@ -70,6 +70,13 @@ init_sdl_input :: () {
table_add(*key_mappings, SDLK_UP, .UP);
table_add(*key_mappings, SDLK_DOWN, .DOWN);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_A, .SPECIAL_BOTTOM);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_B, .SPECIAL_RIGHT);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_X, .SPECIAL_LEFT);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_Y, .SPECIAL_TOP);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_LEFTSHOULDER, .LEFT_BUMPER);
table_add(*sdl_button_map, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, .RIGHT_BUMPER);
//glfw_key_map[GLFW_MOUSE_BUTTON_LEFT] = .MOUSE_LEFT;
//glfw_key_map[GLFW_MOUSE_BUTTON_RIGHT] = .MOUSE_RIGHT;
@@ -237,11 +244,14 @@ sdl_gamepad_button_update :: (using event : SDL_ControllerButtonEvent) {
return;
}
down := state == SDL_PRESSED;
gamepad_button := sdl_button_map[button];
gamepad_button, success := table_find(*sdl_button_map, cast(SDL_GameControllerButton)button);
if success {
gamepad := *engine.input.gamepads[which];
gamepad := *engine.input.gamepads[which];
update_gamepad_state(gamepad, gamepad_button, down);
update_gamepad_state(gamepad, gamepad_button, down);
}
}
sdl_gamepad_device_event :: (using event : SDL_ControllerDeviceEvent) {

View File

@@ -1,5 +1,6 @@
#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false);
#module_parameters(WITH_EDITOR := true, WITH_NETWORKING := false, action_type : Type);
Action :: action_type;
EDITOR :: WITH_EDITOR;
DEBUG :: true;
NETWORKING :: WITH_NETWORKING;

View File

@@ -1,6 +1,7 @@
Textured_Vert :: struct {
position: Vector2;
texcoord: Vector2;
color: Vector4;
}
Textured_Vert_3D :: struct {

View File

@@ -344,9 +344,10 @@ ui_init :: () {
vs := create_vertex_shader(engine.renderer, "../assets/shaders/ui_rect.hlsl", "VS", string.["USE_TEXTURE"]);
ps := create_pixel_shader(engine.renderer, "../assets/shaders/ui_rect.hlsl", "PS", string.["USE_TEXTURE"]);
layout : [2] Vertex_Data_Info;
layout : [3] Vertex_Data_Info;
layout[0] = .{0,.POSITION2D, 0};
layout[1] = .{0,.TEXCOORD0, 0};
layout[2] = .{0,.COLOR, 0};
params : [2] Shader_Parameter;
params[0].shader = .PIXEL;
@@ -741,6 +742,7 @@ make_vert_textured :: (x: float, y: float, uv_x: float, uv_y: float) -> Textured
vert.position.y = y;
vert.texcoord.x = uv_x;
vert.texcoord.y = uv_y;
vert.color = .{1,1,1,1};
return vert;
}