Modifed ray intersection and Added misc windows related files

dev
Shariq Shah 7 years ago
parent ad5b56b717
commit b691df0e1b
  1. 1
      README.md
  2. 3
      misc/ed.bat
  3. BIN
      misc/launch_cmd.lnk
  4. 8
      misc/setup_env.bat
  5. 6
      src/common/hashmap.c
  6. 2
      src/game/platform.c
  7. 8
      src/libsymmetry/bounding_volumes.h
  8. 22
      src/libsymmetry/camera.c
  9. 31
      src/libsymmetry/editor.c
  10. 22
      src/libsymmetry/gui.c
  11. 3
      src/libsymmetry/player.c
  12. 11
      src/libsymmetry/scene.c
  13. 2
      src/libsymmetry/scene.h

@ -155,6 +155,7 @@
- ## TODO - ## TODO
- Fix mouse button press/release behaviour by investigating how sdl handles mouse release or by explicitly caching mouse state by using event callbacks recieved when a mousebutton release event is reported by sdl
- Improve bounding sphere calculation - Improve bounding sphere calculation
- Screen mouse coordinates to world-coordinates for aiming - Screen mouse coordinates to world-coordinates for aiming
- Player projectiles and sounds - Player projectiles and sounds

@ -0,0 +1,3 @@
@echo off
"C:\Program Files\emacs-26.1-x86_64\bin\runemacs.exe"

Binary file not shown.

@ -0,0 +1,8 @@
@echo off
call D:\VS_2017\VC\Auxiliary\Build\vcvarsall.bat x64
cls
set edito="C:\Program Files\emacs-26.1-x86_64\bin\runemacs.exe"
set path=W:\misc;%path% rem

@ -30,9 +30,9 @@ static struct Hashmap_Entry* hashmap_entry_new(struct Hashmap* hashmap, const ch
{ {
if(strncmp(key, hashmap->buckets[index][i].key, HASH_MAX_KEY_LEN) == 0) if(strncmp(key, hashmap->buckets[index][i].key, HASH_MAX_KEY_LEN) == 0)
{ {
new_entry = &hashmap->buckets[index][i]; new_entry = &hashmap->buckets[index][i];
if(new_entry->key) free(new_entry->key); if(new_entry->key) free(new_entry->key);
break; break;
} }
} }
if(!new_entry) new_entry = array_grow(hashmap->buckets[index], struct Hashmap_Entry); if(!new_entry) new_entry = array_grow(hashmap->buckets[index], struct Hashmap_Entry);

@ -347,7 +347,7 @@ int platform_mousebutton_state_get(uint button)
{ {
int pressed = 0; int pressed = 0;
uint32 current_button_state = SDL_GetMouseState(NULL, NULL); uint32 current_button_state = SDL_GetMouseState(NULL, NULL);
if((current_button_state & SDL_BUTTON(button)) > 0) pressed = 1; if((current_button_state & SDL_BUTTON(button))) pressed = 1;
return pressed; return pressed;
} }

@ -4,6 +4,8 @@
#include "../common/linmath.h" #include "../common/linmath.h"
#include "../common/num_types.h" #include "../common/num_types.h"
#define MAX_RAYCAST_ENTITIES_INTERSECT 256
struct Bounding_Box struct Bounding_Box
{ {
vec3 min; vec3 min;
@ -40,6 +42,12 @@ struct Ray
vec3 origin; vec3 origin;
}; };
struct Raycast_Result
{
struct Entity* entities_intersected[MAX_RAYCAST_ENTITIES_INTERSECT];
int num_entities_intersected;
};
int bv_intersect_frustum_box(vec4* frustum, struct Bounding_Box* box, vec3* box_abs_position, vec3* box_abs_scale); int bv_intersect_frustum_box(vec4* frustum, struct Bounding_Box* box, vec3* box_abs_position, vec3* box_abs_scale);
int bv_intersect_frustum_sphere(vec4* frustum, struct Bounding_Sphere* sphere, vec3* sphere_abs_pos, vec3* sphere_abs_scale); int bv_intersect_frustum_sphere(vec4* frustum, struct Bounding_Sphere* sphere, vec3* sphere_abs_pos, vec3* sphere_abs_scale);
bool bv_intersect_frustum_point(vec4* frustum, const vec3* point); bool bv_intersect_frustum_point(vec4* frustum, const vec3* point);

@ -241,26 +241,4 @@ struct Ray camera_screen_coord_to_ray(struct Camera* camera, int mouse_x, int mo
transform_get_absolute_position(&camera->base, &ray.origin); transform_get_absolute_position(&camera->base, &ray.origin);
return ray; return ray;
/*vec4 clip_coords = {normalized_x, normalized_y, -1.f, 1.f};
vec4 ray_eye = {0.f};
mat4 inverse_proj_mat;
mat4_identity(&inverse_proj_mat);
mat4_inverse(&inverse_proj_mat, &camera->proj_mat);
vec4_mul_mat4(&ray_eye, &clip_coords, &inverse_proj_mat);
ray_eye.z = -1.f;
ray_eye.w = 0.f;
vec4 ray_world = {0.f};
mat4 inverse_view_mat;
mat4_identity(&inverse_view_mat);
mat4_inverse(&inverse_view_mat, &camera->view_mat);
vec4_mul_mat4(&ray_world, &ray_eye, &inverse_view_mat);
vec3 world_coords = {ray_world.x, ray_world.y, ray_world.z};
vec3_norm(&world_coords, &world_coords);
return world_coords;*/
} }

@ -19,6 +19,7 @@
#include "../common/num_types.h" #include "../common/num_types.h"
#include "../common/string_utils.h" #include "../common/string_utils.h"
#include "../common/common.h" #include "../common/common.h"
#include "bounding_volumes.h"
#include "input.h" #include "input.h"
#include "scene.h" #include "scene.h"
@ -584,9 +585,37 @@ void editor_camera_update(float dt)
else else
{ {
input_mouse_mode_set(MM_NORMAL); input_mouse_mode_set(MM_NORMAL);
//log_message("ud : %.3f, lr : %.3f", turn_up_down, turn_left_right);
turn_up_down *= dt; turn_up_down *= dt;
turn_left_right *= dt; turn_left_right *= dt;
//Picking
//If we're not looking around then allow picking
if(input_mousebutton_state_get(MSB_LEFT, KS_RELEASED))
{
int mouse_x = 0, mouse_y = 0;
platform->mouse_position_get(&mouse_x, &mouse_y);
struct Ray ray = camera_screen_coord_to_ray(editor_camera, mouse_x, mouse_y);
//log_message("Ray: %.3f, %.3f, %.3f", ray.direction.x, ray.direction.y, ray.direction.z);
struct Scene* scene = game_state_get()->scene;
struct Raycast_Result ray_result;
scene_ray_intersect(scene, &ray, &ray_result);
if(ray_result.num_entities_intersected > 0)
{
//For now, just select the first entity that is intersected
struct Entity* intersected_entity = ray_result.entities_intersected[0];
if(editor_state.selected_entity && editor_state.selected_entity != intersected_entity)
{
editor_state.selected_entity->editor_selected = false;
editor_state.selected_entity = NULL;
}
intersected_entity->editor_selected = true;
editor_state.selected_entity = intersected_entity;
}
}
} }
total_up_down_rot += turn_up_down; total_up_down_rot += turn_up_down;

@ -91,7 +91,7 @@ bool gui_init(void)
platform->textinput_callback_set(&gui_handle_textinput_event); platform->textinput_callback_set(&gui_handle_textinput_event);
//gui_font_set("Ubuntu-R.ttf", 14); //gui_font_set("Ubuntu-R.ttf", 14);
//gui_font_set("FiraSans-Regular.ttf", 14); //gui_font_set("FiraSans-Regular.ttf", 14);
gui_font_set("roboto_condensed.ttf", 16); gui_font_set("roboto_condensed.ttf", 18);
// gui_theme_set(GT_RED); // gui_theme_set(GT_RED);
gui_theme_set(GT_DEFAULT); gui_theme_set(GT_DEFAULT);
success = true; success = true;
@ -113,10 +113,10 @@ void gui_upload_atlas(const void *image, int width, int height)
void gui_cleanup(void) void gui_cleanup(void)
{ {
nk_font_atlas_clear(&gui_state->atlas); nk_font_atlas_clear(&gui_state->atlas);
nk_free(&gui_state->context); nk_free(&gui_state->context);
shader_remove(gui_state->shader); shader_remove(gui_state->shader);
texture_remove(gui_state->font_tex); texture_remove(gui_state->font_tex);
glDeleteBuffers(1, &gui_state->vbo); glDeleteBuffers(1, &gui_state->vbo);
glDeleteBuffers(1, &gui_state->ebo); glDeleteBuffers(1, &gui_state->ebo);
nk_buffer_free(&gui_state->cmds); nk_buffer_free(&gui_state->cmds);
@ -128,13 +128,13 @@ void gui_render(enum nk_anti_aliasing AA)
int width, height; int width, height;
int display_width, display_height; int display_width, display_height;
struct nk_vec2 scale; struct nk_vec2 scale;
mat4 gui_mat; mat4 gui_mat;
mat4_identity(&gui_mat); mat4_identity(&gui_mat);
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
platform->window.get_size(game_state->window, &width, &height); platform->window.get_size(game_state->window, &width, &height);
platform->window.get_drawable_size(game_state->window, &display_width, &display_height); platform->window.get_drawable_size(game_state->window, &display_width, &display_height);
mat4_ortho(&gui_mat, 0, display_width, display_height, 0, -100, 100); mat4_ortho(&gui_mat, 0.f, display_width, display_height, 0.f, -100.f, 100.f);
scale.x = (float)display_width/(float)width; scale.x = (float)display_width/(float)width;
scale.y = (float)display_height/(float)height; scale.y = (float)display_height/(float)height;
@ -149,9 +149,9 @@ void gui_render(enum nk_anti_aliasing AA)
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
/* setup program */ /* setup program */
shader_bind(gui_state->shader); shader_bind(gui_state->shader);
glUniform1i(gui_state->uniform_tex, 0); glUniform1i(gui_state->uniform_tex, 0);
shader_set_uniform(UT_MAT4, gui_state->uniform_proj, &gui_mat); shader_set_uniform(UT_MAT4, gui_state->uniform_proj, &gui_mat);
{ {
/* convert from command queue into draw list and draw to screen */ /* convert from command queue into draw list and draw to screen */
const struct nk_draw_command *cmd; const struct nk_draw_command *cmd;
@ -173,7 +173,7 @@ void gui_render(enum nk_anti_aliasing AA)
/* fill convert configuration */ /* fill convert configuration */
struct nk_convert_config config; struct nk_convert_config config;
static const struct nk_draw_vertex_layout_element vertex_layout[] = static const struct nk_draw_vertex_layout_element vertex_layout[] =
{ {
{NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, pos)}, {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, pos)},
{NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, uv)}, {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct Gui_Vertex, uv)},
{NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct Gui_Vertex, col)}, {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct Gui_Vertex, col)},

@ -76,6 +76,7 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
struct Ray ray = camera_screen_coord_to_ray(player->camera_node, mouse_x, mouse_y); struct Ray ray = camera_screen_coord_to_ray(player->camera_node, mouse_x, mouse_y);
log_message("Ray: %.3f, %.3f, %.3f", ray.direction.x, ray.direction.y, ray.direction.z); log_message("Ray: %.3f, %.3f, %.3f", ray.direction.x, ray.direction.y, ray.direction.z);
scene_ray_intersect(scene, &ray); struct Raycast_Result ray_result;
scene_ray_intersect(scene, &ray, &ray_result);
} }
} }

@ -555,9 +555,13 @@ void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct
transform_parent_set(entity, parent, true); transform_parent_set(entity, parent, true);
} }
void scene_ray_intersect(struct Scene* scene, struct Ray* ray, struct Raycast_Result* out_results)
void scene_ray_intersect(struct Scene* scene, struct Ray* ray)
{ {
assert(out_results);
memset(&out_results[0], '\0', sizeof(struct Entity*) * MAX_RAYCAST_ENTITIES_INTERSECT);
out_results->num_entities_intersected = 0;
for(int i = 0; i < MAX_STATIC_MESHES; i++) for(int i = 0; i < MAX_STATIC_MESHES; i++)
{ {
struct Static_Mesh* mesh = &scene->static_meshes[i]; struct Static_Mesh* mesh = &scene->static_meshes[i];
@ -568,7 +572,8 @@ void scene_ray_intersect(struct Scene* scene, struct Ray* ray)
struct Geometry* geometry = geom_get(mesh->model.geometry_index); struct Geometry* geometry = geom_get(mesh->model.geometry_index);
if(bv_intersect_sphere_ray(&geometry->bounding_sphere, &abs_pos, ray)) if(bv_intersect_sphere_ray(&geometry->bounding_sphere, &abs_pos, ray))
{ {
log_message("Ray intersected with %s", &mesh->base.name); out_results->entities_intersected[out_results->num_entities_intersected] = &mesh->base;
out_results->num_entities_intersected++;
} }
} }
} }

@ -56,7 +56,7 @@ struct Entity* scene_base_entity_get(struct Scene* scene, int id, int type
void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct Entity* parent); void scene_entity_parent_set(struct Scene* scene, struct Entity* entity, struct Entity* parent);
void scene_entity_parent_reset(struct Scene* scene, struct Entity* entity); // Sets root entity as parent void scene_entity_parent_reset(struct Scene* scene, struct Entity* entity); // Sets root entity as parent
void scene_ray_intersect(struct Scene* scene, struct Ray* ray); void scene_ray_intersect(struct Scene* scene, struct Ray* ray, struct Raycast_Result* out_results);
// //
//void scene_init(void); //void scene_init(void);

Loading…
Cancel
Save