get the flycam going already
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "scenes/scene.h"
|
||||
#include "scenes/title.h"
|
||||
|
||||
#include <SDL_scancode.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
@ -22,16 +23,28 @@ void game_tick(void) {
|
||||
input_bind_action_scancode(&ctx.input, "debug_toggle", SDL_SCANCODE_BACKSPACE);
|
||||
|
||||
input_add_action(&ctx.input, "player_left");
|
||||
input_bind_action_scancode(&ctx.input, "player_left", SDL_SCANCODE_LEFT);
|
||||
input_bind_action_scancode(&ctx.input, "player_left", SDL_SCANCODE_A);
|
||||
|
||||
input_add_action(&ctx.input, "player_right");
|
||||
input_bind_action_scancode(&ctx.input, "player_right", SDL_SCANCODE_RIGHT);
|
||||
input_bind_action_scancode(&ctx.input, "player_right", SDL_SCANCODE_D);
|
||||
|
||||
input_add_action(&ctx.input, "player_forward");
|
||||
input_bind_action_scancode(&ctx.input, "player_forward", SDL_SCANCODE_W);
|
||||
|
||||
input_add_action(&ctx.input, "player_backward");
|
||||
input_bind_action_scancode(&ctx.input, "player_backward", SDL_SCANCODE_S);
|
||||
|
||||
input_add_action(&ctx.input, "player_jump");
|
||||
input_bind_action_scancode(&ctx.input, "player_jump", SDL_SCANCODE_X);
|
||||
input_bind_action_scancode(&ctx.input, "player_jump", SDL_SCANCODE_SPACE);
|
||||
|
||||
input_add_action(&ctx.input, "player_run");
|
||||
input_bind_action_scancode(&ctx.input, "player_run", SDL_SCANCODE_LSHIFT);
|
||||
|
||||
input_add_action(&ctx.input, "ui_accept");
|
||||
input_bind_action_scancode(&ctx.input, "ui_accept", SDL_SCANCODE_RETURN);
|
||||
|
||||
input_add_action(&ctx.input, "mouse_capture_toggle");
|
||||
input_bind_action_scancode(&ctx.input, "mouse_capture_toggle", SDL_SCANCODE_END);
|
||||
}
|
||||
|
||||
struct state *state = ctx.udata;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "ingame.h"
|
||||
#include "src/input.h"
|
||||
#include "title.h"
|
||||
#include "scene.h"
|
||||
|
||||
@ -12,14 +13,45 @@ static void ingame_tick(struct state *state) {
|
||||
player_calc(scn->player);
|
||||
|
||||
static t_camera cam = { .pos = { 32, 0, 1 }, .up = { 0, 1, 0 }, .fov = (float)M_PI_2 };
|
||||
cam.target = m_vec_norm(((t_fvec3){ -1, 0, 1 }));
|
||||
|
||||
const float sensitivity = 0.6f; /* TODO: put this in a better place */
|
||||
scn->yaw += (float)ctx.input.mouse_relative_position.x * sensitivity;
|
||||
scn->pitch -= (float)ctx.input.mouse_relative_position.y * sensitivity;
|
||||
scn->pitch = clampf(scn->pitch, -89.0f, 89.0f);
|
||||
|
||||
const float yaw_rad = scn->yaw * (float)DEG2RAD;
|
||||
const float pitch_rad = scn->pitch * (float)DEG2RAD;
|
||||
|
||||
cam.target = m_vec_norm(((t_fvec3){
|
||||
cosf(yaw_rad) * cosf(pitch_rad),
|
||||
sinf(pitch_rad),
|
||||
sinf(yaw_rad) * cosf(pitch_rad)
|
||||
}));
|
||||
|
||||
const t_fvec3 right = m_vec_norm(m_vec_cross(cam.target, cam.up));
|
||||
const float speed = 0.04f; /* TODO: put this in a better place */
|
||||
if (input_is_action_pressed(&ctx.input, "player_left"))
|
||||
cam.pos.x -= 0.01f;
|
||||
cam.pos = fvec3_sub(cam.pos, m_vec_scale(right, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_right"))
|
||||
cam.pos.x += 0.01f;
|
||||
cam.pos = fvec3_add(cam.pos, m_vec_scale(right, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_forward"))
|
||||
cam.pos = fvec3_add(cam.pos, m_vec_scale(cam.target, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_backward"))
|
||||
cam.pos = fvec3_sub(cam.pos, m_vec_scale(cam.target, speed));
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_jump"))
|
||||
cam.pos.z += 0.01f;
|
||||
cam.pos.y += speed;
|
||||
|
||||
if (input_is_action_pressed(&ctx.input, "player_run"))
|
||||
cam.pos.y -= speed;
|
||||
|
||||
/* toggle mouse capture with end key */
|
||||
if (input_is_action_just_pressed(&ctx.input, "mouse_capture_toggle")) {
|
||||
input_set_mouse_captured(&ctx.input, !input_is_mouse_captured(&ctx.input));
|
||||
}
|
||||
|
||||
m_sprite(m_set(path, "/assets/light.png"),
|
||||
m_set(rect, ((t_frect){ 48, 64, 64, 64 })),
|
||||
@ -93,5 +125,7 @@ struct scene *ingame_scene(struct state *state) {
|
||||
.repeat = true,
|
||||
});
|
||||
|
||||
input_set_mouse_captured(&ctx.input, true);
|
||||
|
||||
return (struct scene *)new_scene;
|
||||
}
|
||||
|
@ -14,6 +14,11 @@ struct scene_ingame {
|
||||
|
||||
struct world *world;
|
||||
struct player *player;
|
||||
|
||||
/* TODO: put this in a better place */
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user