fixed fps
This commit is contained in:
parent
58eaf2a92e
commit
778b6efeee
@ -1,6 +1,6 @@
|
|||||||
C 0,0,-5 0,0,5 90
|
C 0,0,-5 0,0,1 90
|
||||||
L 0,2,-2 1 255,255,200
|
L 0,2,-2 1 255,255,200
|
||||||
A 0.5 0,0,100
|
A 0.5 0,0,100
|
||||||
sp 0,0,0 2 234,123,123
|
sp 0,0,0 2 234,123,123
|
||||||
sp 0,0,0 2 123,234,123
|
sp 0,0,0 2 123,234,123
|
||||||
cy 0,0,0 0,1,0 1 5 123,123,234
|
cy 0,0,0 0,1,0 1 5 123,123,234
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
C 20,20,-20 -20,-20,20 60
|
|
||||||
L 0,0.5,-1 1 255,255,200
|
|
||||||
A 0.5 100,100,100
|
|
||||||
pl 0,-1.5,2 0,-1,0 234,234,123
|
|
||||||
sp 0,-1.25,2 1 234,234,234
|
|
||||||
sp 0,-0.5,2 0.75 234,234,234
|
|
||||||
sp 0,0,2 0.5 234,234,234
|
|
||||||
cy 0,0.25,2 0,1,0 0.3 0.3 50,50,50
|
|
||||||
di 0,0.2,2 0,1,0 0.5 150,150,150
|
|
||||||
cn 0,0,1.3 0,1,100 0.1 0.5 255,200,100
|
|
||||||
BIN
out/miniRT
BIN
out/miniRT
Binary file not shown.
@ -13,6 +13,8 @@
|
|||||||
#include "../../minirt.h"
|
#include "../../minirt.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
const char *asset_root = ROOT_DIRECTORY"/assets";
|
||||||
|
|
||||||
void container_item_dirent_create(t_item *item, char *title, \
|
void container_item_dirent_create(t_item *item, char *title, \
|
||||||
int type, void (*func)(void *, void *))
|
int type, void (*func)(void *, void *))
|
||||||
{
|
{
|
||||||
@ -31,8 +33,8 @@ void explorer_create(t_container *explorer, t_data *data)
|
|||||||
ft_fprintf(STDERR_FILENO, "Failed to get current directory, exiting...\n");
|
ft_fprintf(STDERR_FILENO, "Failed to get current directory, exiting...\n");
|
||||||
lst_memory(NULL, NULL, FAIL);
|
lst_memory(NULL, NULL, FAIL);
|
||||||
}
|
}
|
||||||
if (ft_strncmp(cwd, ROOT_DIRECTORY, ft_strlen(ROOT_DIRECTORY)) != 0) {
|
if (ft_strncmp(cwd, asset_root, ft_strlen(asset_root)) != 0) {
|
||||||
if (chdir(ROOT_DIRECTORY) != 0) {
|
if (chdir(asset_root) != 0) {
|
||||||
ft_fprintf(STDERR_FILENO, "Failed to change directory, exiting...\n");
|
ft_fprintf(STDERR_FILENO, "Failed to change directory, exiting...\n");
|
||||||
lst_memory(NULL, NULL, FAIL);
|
lst_memory(NULL, NULL, FAIL);
|
||||||
}
|
}
|
||||||
@ -46,8 +48,7 @@ void explorer_read_dir_loop(DIR *dir, void *param, \
|
|||||||
{
|
{
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
t_item item;
|
t_item item;
|
||||||
|
bool is_root_dir = ft_strncmp(cwd, asset_root, ft_strlen(cwd)) == 0;
|
||||||
bool is_root_dir = ft_strncmp(cwd, ROOT_DIRECTORY, ft_strlen(cwd)) == 0;
|
|
||||||
|
|
||||||
ft_strlcpy(explorer->title, cwd, CONTAINER_TITLE_LEN);
|
ft_strlcpy(explorer->title, cwd, CONTAINER_TITLE_LEN);
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
@ -16,6 +16,8 @@ uint key_misc_function(int keycode, t_scene *scene, t_data *data)
|
|||||||
{
|
{
|
||||||
if (keycode == KEY_P)
|
if (keycode == KEY_P)
|
||||||
scene_save(scene);
|
scene_save(scene);
|
||||||
|
else if (keycode == KEY_X)
|
||||||
|
return (scene->anti_aliasing = scene->anti_aliasing == 0 ? ANTI_ALIASING_FACTOR : 0, true);
|
||||||
else if (keycode == KEY_M)
|
else if (keycode == KEY_M)
|
||||||
return (data->current_menu = &data->menu[MENU_MAIN], true);
|
return (data->current_menu = &data->menu[MENU_MAIN], true);
|
||||||
else if (keycode == KEY_Y)
|
else if (keycode == KEY_Y)
|
||||||
@ -42,11 +44,11 @@ int key_move_camera(int keycode, t_camera *camera)
|
|||||||
calc_camera_space(camera);
|
calc_camera_space(camera);
|
||||||
if (keycode == KEY_A || keycode == KEY_D)
|
if (keycode == KEY_A || keycode == KEY_D)
|
||||||
translation = scale_vector(camera->right, \
|
translation = scale_vector(camera->right, \
|
||||||
(keycode - KEY_A - 1.5) * 0.66);
|
(keycode - KEY_A - 1.5) * 0.1);
|
||||||
else if (keycode == KEY_W || keycode == KEY_S)
|
else if (keycode == KEY_W || keycode == KEY_S)
|
||||||
translation = scale_vector(camera->normal, (keycode - KEY_S - 2) * 0.5);
|
translation = scale_vector(camera->normal, (keycode - KEY_S - 2) * 0.1);
|
||||||
else if (keycode == KEY_Q || keycode == KEY_E)
|
else if (keycode == KEY_Q || keycode == KEY_E)
|
||||||
translation = scale_vector(camera->up, (keycode - KEY_E - 6) * 0.33);
|
translation = scale_vector(camera->up, (keycode - KEY_E - 6) * 0.1);
|
||||||
else
|
else
|
||||||
return (false);
|
return (false);
|
||||||
camera->position = add_vector(camera->position, translation);
|
camera->position = add_vector(camera->position, translation);
|
||||||
|
|||||||
@ -79,7 +79,7 @@ bool calc_camera_rotation(int key, t_camera *camera)
|
|||||||
float rotation_angle;
|
float rotation_angle;
|
||||||
t_vector perpendicular_normal;
|
t_vector perpendicular_normal;
|
||||||
|
|
||||||
rotation_angle = 10;
|
rotation_angle = 5;
|
||||||
if (key == KEY_UP)
|
if (key == KEY_UP)
|
||||||
{
|
{
|
||||||
perpendicular_normal = camera->up;
|
perpendicular_normal = camera->up;
|
||||||
|
|||||||
@ -49,15 +49,15 @@ void help_menu_draw(void *data_ptr, void *pixel)
|
|||||||
(void)pixel;
|
(void)pixel;
|
||||||
rt_draw_rect_blend(background, data->pixel, 0, HELP_MENU_BG);
|
rt_draw_rect_blend(background, data->pixel, 0, HELP_MENU_BG);
|
||||||
glyph_print(x + 2, y + 2, \
|
glyph_print(x + 2, y + 2, \
|
||||||
"controls\n" \
|
"controls\n\n" \
|
||||||
"main menu: m\n" \
|
"main menu: m\n" \
|
||||||
"movement: \n" \
|
"movement: \n" \
|
||||||
"move: wasdqe\n" \
|
"move: wasdqe\n" \
|
||||||
"rotate: arrow keys\n" \
|
"rotate: arrow keys\n" \
|
||||||
"move light: hjklio\n" \
|
"move light: hjklio\n" \
|
||||||
|
"toggle anti aliasing: x\n" \
|
||||||
"select next light: n\n\n" \
|
"select next light: n\n\n" \
|
||||||
"drag object: lmouse\nchange object: rmouse + use menu\n\n" \
|
"drag object: lmouse\nchange object: rmouse + use menu\n\n" \
|
||||||
"resolution and anti-aliasing:\n\nnumpad + or -; Enter to reset\n" \
|
|
||||||
"backsp: reset_cam\n" \
|
"backsp: reset_cam\n" \
|
||||||
"p: save file\nesc: exit\n", \
|
"p: save file\nesc: exit\n", \
|
||||||
data->pixel);
|
data->pixel);
|
||||||
|
|||||||
33
src/minirt.c
33
src/minirt.c
@ -112,6 +112,7 @@ void initialize_data(t_data *data, char *path)
|
|||||||
data->texture = LoadTextureFromImage(img);
|
data->texture = LoadTextureFromImage(img);
|
||||||
data->should_rerender = true;
|
data->should_rerender = true;
|
||||||
pixels_image_syncronize(data->pixel_colors, data->pixel);
|
pixels_image_syncronize(data->pixel_colors, data->pixel);
|
||||||
|
SetTargetFPS(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* validate_file_extension(int argc, char **argv)
|
char* validate_file_extension(int argc, char **argv)
|
||||||
@ -130,6 +131,34 @@ void get_key_code(int keys[]) {
|
|||||||
keys[c++] = KEY_ESCAPE;
|
keys[c++] = KEY_ESCAPE;
|
||||||
if (c == 3) return;
|
if (c == 3) return;
|
||||||
}
|
}
|
||||||
|
if ((IsKeyPressed(KEY_H) || IsKeyDown(KEY_H))) {
|
||||||
|
keys[c++] = KEY_H;
|
||||||
|
if (c == 3) return;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_L) || IsKeyDown(KEY_L))) {
|
||||||
|
keys[c++] = KEY_L;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_K) || IsKeyDown(KEY_K))) {
|
||||||
|
keys[c++] = KEY_K;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_I) || IsKeyDown(KEY_I))) {
|
||||||
|
keys[c++] = KEY_J;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_O) || IsKeyDown(KEY_O))) {
|
||||||
|
keys[c++] = KEY_K;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_J) || IsKeyDown(KEY_J))) {
|
||||||
|
keys[c++] = KEY_J;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
|
if ((IsKeyPressed(KEY_X))) {
|
||||||
|
keys[c++] = KEY_X;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
if ((IsKeyPressed(KEY_W) || IsKeyDown(KEY_W))) {
|
if ((IsKeyPressed(KEY_W) || IsKeyDown(KEY_W))) {
|
||||||
keys[c++] = KEY_W;
|
keys[c++] = KEY_W;
|
||||||
if (c == 3) return;
|
if (c == 3) return;
|
||||||
@ -174,6 +203,10 @@ void get_key_code(int keys[]) {
|
|||||||
keys[c++] = KEY_M;
|
keys[c++] = KEY_M;
|
||||||
if (c == 3) return ;
|
if (c == 3) return ;
|
||||||
}
|
}
|
||||||
|
if (IsKeyPressed(KEY_N)) {
|
||||||
|
keys[c++] = KEY_N;
|
||||||
|
if (c == 3) return ;
|
||||||
|
}
|
||||||
if (IsKeyPressed(KEY_P)) {
|
if (IsKeyPressed(KEY_P)) {
|
||||||
keys[c++] = KEY_P;
|
keys[c++] = KEY_P;
|
||||||
if (c == 3) return ;
|
if (c == 3) return ;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user