voir le parsing

This commit is contained in:
H3XploR
2025-02-17 23:12:16 +01:00
parent e36cfb5fde
commit 490c585c48
7 changed files with 67 additions and 72 deletions
+24 -24
View File
@@ -6,7 +6,7 @@
/* By: yantoine <yantoine@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/17 19:27:23 by yantoine #+# #+# */
/* Updated: 2025/02/17 19:30:13 by yantoine ### ########.fr */
/* Updated: 2025/02/17 23:07:57 by yantoine ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,40 +15,40 @@
static void update_camera_rotation(t_app *app)
{
if (app->key_left)
app->yaw -= app->rot_speed;
app->scene.camera.yaw -= app->scene.camera.rot_speed;
if (app->key_right)
app->yaw += app->rot_speed;
app->scene.camera.yaw += app->scene.camera.rot_speed;
if (app->key_up)
app->pitch += app->rot_speed;
app->scene.camera.pitch += app->scene.camera.rot_speed;
if (app->key_down)
app->pitch -= app->rot_speed;
if (app->pitch > 1.57f - 0.01f)
app->pitch = 1.57f - 0.01f;
if (app->pitch < -1.57f + 0.01f)
app->pitch = -1.57f + 0.01f;
app->cam_dir.x = cosf(app->pitch) * sinf(app->yaw);
app->cam_dir.y = sinf(app->pitch);
app->cam_dir.z = -cosf(app->pitch) * cosf(app->yaw);
app->cam_dir = vec3_normalize(app->cam_dir);
app->right = (t_vec3){cosf(app->yaw), 0, sinf(app->yaw)};
app->right = vec3_normalize(app->right);
app->cam_up = vec3_normalize(vec3_cross(app->right, app->cam_dir));
app->scene.camera.pitch -= app->scene.camera.rot_speed;
if (app->scene.camera.pitch > 1.57f - 0.01f)
app->scene.camera.pitch = 1.57f - 0.01f;
if (app->scene.camera.pitch < -1.57f + 0.01f)
app->scene.camera.pitch = -1.57f + 0.01f;
app->scene.camera.camDir.x = cosf(app->scene.camera.pitch) * sinf(app->scene.camera.yaw);
app->scene.camera.camDir.y = sinf(app->scene.camera.pitch);
app->scene.camera.camDir.z = -cosf(app->scene.camera.pitch) * cosf(app->scene.camera.yaw);
app->scene.camera.camDir = vec3_normalize(app->scene.camera.camDir);
app->scene.camera.right = (t_vec3){cosf(app->scene.camera.yaw), 0, sinf(app->scene.camera.yaw)};
app->scene.camera.right = vec3_normalize(app->scene.camera.right);
app->scene.camera.up = vec3_normalize(vec3_cross(app->scene.camera.right, app->scene.camera.camDir));
}
static void update_camera_movement(t_app *app)
{
if (app->key_w)
app->cam_pos = vec3_add(app->cam_pos,
vec3_scale(app->cam_dir, app->move_speed));
app->scene.camera.camPos = vec3_add(app->scene.camera.camPos,
vec3_scale(app->scene.camera.camDir, app->scene.camera.move_speed));
if (app->key_s)
app->cam_pos = vec3_sub(app->cam_pos,
vec3_scale(app->cam_dir, app->move_speed));
app->scene.camera.camPos = vec3_sub(app->scene.camera.camPos,
vec3_scale(app->scene.camera.camDir, app->scene.camera.move_speed));
if (app->key_a)
app->cam_pos = vec3_sub(app->cam_pos,
vec3_scale(app->right, app->move_speed));
app->scene.camera.camPos = vec3_sub(app->scene.camera.camPos,
vec3_scale(app->scene.camera.right, app->scene.camera.move_speed));
if (app->key_d)
app->cam_pos = vec3_add(app->cam_pos,
vec3_scale(app->right, app->move_speed));
app->scene.camera.camPos = vec3_add(app->scene.camera.camPos,
vec3_scale(app->scene.camera.right, app->scene.camera.move_speed));
}
void update_camera(t_app *app)