Changed ray test to use the player's movement direction instead of forward direction when checking for collisions. Added ray drawing function that directly takes ray origin and directions as params instead of ray struct

dev
Shariq Shah 6 years ago
parent 1514f3990f
commit e6a748c458
  1. 2
      src/common/version.h
  2. 8
      src/game/im_render.c
  3. 1
      src/game/im_render.h
  4. 13
      src/game/player.c
  5. 4
      todo.txt

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 310
#define SYMMETRY_VERSION_REVISION 311
#define SYMMETRY_VERSION_BRANCH "dev"
#endif

@ -220,6 +220,14 @@ void im_ray(struct Ray* ray, float length, vec4 color, int draw_order)
im_line(ray->origin, ending_pos, (vec3) { 0.f, 0.f, 0.f }, (quat) { 0.f, 0.f, 0.f, 1.f }, color, draw_order);
}
void im_ray_origin_dir(vec3 origin, vec3 direction, float length, vec4 color, int draw_order)
{
vec3 ending_pos = { 0.f, 0.f, 0.f };
vec3_scale(&ending_pos, &direction, length);
vec3_add(&ending_pos, &ending_pos, &origin);
im_line(origin, ending_pos, (vec3) { 0.f, 0.f, 0.f }, (quat) { 0.f, 0.f, 0.f, 1.f }, color, draw_order);
}
void im_end(void)
{
active_geom->num_vertices = current_vertex_index + 1;

@ -50,6 +50,7 @@ void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec4 color, int dra
void im_circle(float radius, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, int draw_order);
void im_arc(float radius, float angle_start, float angle_end, int num_divisions, bool filled, vec3 position, quat rotation, vec4 color, int draw_order);
void im_ray(struct Ray* ray, float length, vec4 color, int draw_order);
void im_ray_origin_dir(vec3 origin, vec3 direction, float length, vec4 color, int draw_order);
void im_end(void);
void im_render(struct Camera* active_viewer);

@ -148,19 +148,14 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
vec3_norm(&move_direction, &move_direction);
if(move_direction.x != 0 || move_direction.z != 0)
{
//quat_mul_vec3(&move_direction, &player->camera_node->base.transform.rotation, &move_direction);
quat_mul_vec3(&move_direction, &player->base.transform.rotation, &move_direction);
//offset.y = 0.f;
}
/* Check for collisions ahead */
int mouse_x = 0, mouse_y = 0;
platform_mouse_position_get(&mouse_x, &mouse_y);
//struct Ray forward_ray = camera_screen_coord_to_ray(player->camera_node, 0, 0);
struct Ray forward_ray = { 0 };
transform_get_absolute_position(player, &forward_ray.origin);
transform_get_absolute_forward(player->camera_node, &forward_ray.direction);
vec3_assign(&forward_ray.direction, &move_direction);
// Get all the entities that intersect then check the distance if it is less than
// or equal to min_collision_distance then we are colliding
@ -184,10 +179,8 @@ void player_update(struct Player* player, struct Scene* scene, float dt)
struct Bounding_Box* box = &colliding_entity->derived_bounding_box;
vec3 normal = bv_bounding_box_normal_from_intersection_point(box, intersection_point);
struct Ray normal_ray;
normal_ray.origin = intersection_point;
normal_ray.direction = normal;
im_ray(&normal_ray, 5.f, (vec4) { 1.f, 0.f, 0.f, 1.f }, 3);
im_ray_origin_dir(intersection_point, normal, 5.f, (vec4) { 1.f, 0.f, 0.f, 1.f }, 3);
im_ray(&forward_ray, min_collision_distance, (vec4) { 0.f, 1.f, 0.f, 1.f }, 3);
float dot = (vec3_dot(&move_direction, &normal));
vec3 norm_scaled = { 0.f };

@ -1,5 +1,6 @@
Todo:
- Improve player collision by impelenting sliding along collision plane in case of collision
- Bring back sprinting
- Fix aggressive frustum culling when camera looks up and the object right infront of the viewer gets culled
- Check if running in a lower frame rate affects movement
- Move player movement related variables from function to player struct and load them from config file
? Write entity flags to scene file or when saving entity to file?
@ -399,3 +400,4 @@ Done:
* We no longer keep geoemtry data loaded from files as it is not needed after data is passed on to opengl
* Shift-A to add entity to scene
* Fixed crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted
* Improve player collision by impelenting sliding along collision plane in case of collision
Loading…
Cancel
Save