Changed how spot and directional lights get their direction from rotation and implemented im_ray

dev
Shariq Shah 6 years ago
parent 329075f6f5
commit a3cd984225
  1. 43
      src/game/editor.c
  2. 2
      src/game/editor.h
  3. 12
      src/game/im_render.c
  4. 4
      src/game/im_render.h
  5. 2
      src/game/renderer.c

@ -136,7 +136,7 @@ void editor_init(struct Editor* editor)
editor->draw_cursor_entity = false;
editor->tool_scale_started = false;
vec4_fill(&editor->projected_entity_color, 0.f, 1.f, 1.f, 1.f);
vec4_fill(&editor->cursor_entity_color, 0.f, 1.f, 1.f, 1.f);
vec3_fill(&editor->tool_scale_amount, 1.f, 1.f, 1.f);
vec4_fill(&editor->tool_mesh_color, 0.f, 1.f, 1.f, 1.f);
vec4_fill(&editor->selected_entity_color, 0.96, 0.61, 0.17, 0.5f);
@ -215,6 +215,21 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
transform_get_absolute_position(editor->selected_entity, &abs_pos);
transform_get_absolute_rot(editor->selected_entity, &abs_rot);
im_sphere(1.f, abs_pos, abs_rot, editor->selected_entity_color, GDM_TRIANGLES, 1);
switch(editor->selected_entity->type)
{
case ET_LIGHT:
{
struct Light* light = (struct Light*)editor->selected_entity;
if(light->type != LT_POINT)
{
struct Ray light_ray;
vec3_assign(&light_ray.origin, &abs_pos);
transform_get_absolute_forward(light, &light_ray.direction);
im_ray(&light_ray, 5.f, editor->cursor_entity_color, 3);
}
}
break;
}
}
/* Draw selected entity with projected transformation applied */
@ -224,7 +239,7 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
shader_bind(renderer->debug_shader);
{
static mat4 mvp;
shader_set_uniform_vec4(renderer->debug_shader, "debug_color", &editor->projected_entity_color);
shader_set_uniform_vec4(renderer->debug_shader, "debug_color", &editor->cursor_entity_color);
struct Static_Mesh* mesh = editor->cursor_entity;
struct Model* model = editor->selected_entity->type == ET_STATIC_MESH ? &((struct Static_Mesh*)editor->selected_entity)->model : &mesh->model;
struct Transform* transform = &mesh->base.transform;
@ -247,9 +262,9 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
float half_axis_line_length = editor->axis_line_length / 2.f;
im_line((vec3) { -half_axis_line_length, 0.f, 0.f }, (vec3) { half_axis_line_length, 0.f, 0.f }, position, rotation, scale, editor->axis_color_x, 1); // X Axis
im_line((vec3) { 0.f, -half_axis_line_length, 0.f }, (vec3) { 0.f, half_axis_line_length, 0.f }, position, rotation, scale, editor->axis_color_y, 1); // Y Axis
im_line((vec3) { 0.f, 0.f, -half_axis_line_length }, (vec3) { 0.f, 0.f, half_axis_line_length }, position, rotation, scale, editor->axis_color_z, 1); // Z Axis
im_line((vec3) { -half_axis_line_length, 0.f, 0.f }, (vec3) { half_axis_line_length, 0.f, 0.f }, position, rotation, editor->axis_color_x, 1); // X Axis
im_line((vec3) { 0.f, -half_axis_line_length, 0.f }, (vec3) { 0.f, half_axis_line_length, 0.f }, position, rotation, editor->axis_color_y, 1); // Y Axis
im_line((vec3) { 0.f, 0.f, -half_axis_line_length }, (vec3) { 0.f, 0.f, half_axis_line_length }, position, rotation, editor->axis_color_z, 1); // Z Axis
//Draw Grid
if(editor->grid_enabled)
@ -523,25 +538,25 @@ void editor_update(struct Editor* editor, float dt)
switch(editor->current_axis)
{
case EDITOR_AXIS_Y:
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, scale, editor->axis_color_y, 3);
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, editor->axis_color_y, 3);
break;
case EDITOR_AXIS_X:
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, scale, editor->axis_color_x, 3);
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, editor->axis_color_x, 3);
break;
case EDITOR_AXIS_Z:
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, scale, editor->axis_color_z, 3);
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, editor->axis_color_z, 3);
break;
case EDITOR_AXIS_XZ:
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, scale, editor->axis_color_x, 3);
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, scale, editor->axis_color_z, 3);
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, editor->axis_color_x, 3);
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, editor->axis_color_z, 3);
break;
case EDITOR_AXIS_XY:
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, scale, editor->axis_color_x, 3);
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, scale, editor->axis_color_y, 3);
im_line((vec3) { -editor->axis_line_length, 0.f, 0.f }, (vec3) { editor->axis_line_length, 0.f, 0.f }, position, rotation, editor->axis_color_x, 3);
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, editor->axis_color_y, 3);
break;
case EDITOR_AXIS_YZ:
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, scale, editor->axis_color_y, 3);
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, scale, editor->axis_color_z, 3);
im_line((vec3) { 0.f, -editor->axis_line_length, 0.f }, (vec3) { 0.f, editor->axis_line_length, 0.f }, position, rotation, editor->axis_color_y, 3);
im_line((vec3) { 0.f, 0.f, -editor->axis_line_length }, (vec3) { 0.f, 0.f, editor->axis_line_length }, position, rotation, editor->axis_color_z, 3);
break;
}
}

@ -19,7 +19,7 @@ struct Editor
int camera_looking_around;
struct Entity* selected_entity;
struct Static_Mesh* cursor_entity;
vec4 projected_entity_color;
vec4 cursor_entity_color;
bool draw_cursor_entity;
int top_panel_height;
float camera_turn_speed;

@ -153,9 +153,9 @@ void im_sphere(float radius, vec3 position, quat rotation, vec4 color, int draw_
active_geom = NULL;
}
void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 color, int draw_order)
void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec4 color, int draw_order)
{
im_begin(position, rotation, scale, color, GDM_LINES, draw_order);
im_begin(position, rotation, (vec3) { 1.f, 1.f, 1.f }, color, GDM_LINES, draw_order);
im_pos(p1.x, p1.y, p1.z);
im_pos(p2.x, p2.y, p2.z);
im_end();
@ -212,6 +212,14 @@ void im_arc(float radius, float angle_start, float angle_end, int num_divisions,
im_end();
}
void im_ray(struct Ray* ray, float length, vec4 color, int draw_order)
{
vec3 ending_pos = { 0.f, 0.f, 0.f };
vec3_scale(&ending_pos, &ray->direction, length);
vec3_add(&ending_pos, &ending_pos, &ray->origin);
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_end(void)
{
active_geom->num_vertices = current_vertex_index + 1;

@ -38,6 +38,7 @@ struct IM_Geom
};
struct Camera;
struct Ray;
void im_init(void);
void im_cleanup(void);
@ -45,9 +46,10 @@ void im_begin(vec3 position, quat rotation, vec3 scale, vec4 color, int draw_mod
void im_pos(float x, float y, float z);
void im_box(float x, float y, float z, vec3 position, quat rotation, vec4 color, int draw_mode, int draw_order);
void im_sphere(float radius, vec3 position, quat rotation, vec4 color, int draw_mode, int draw_order);
void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec3 scale, vec4 color, int draw_order);
void im_line(vec3 p1, vec3 p2, vec3 position, quat rotation, vec4 color, int draw_order);
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_end(void);
void im_render(struct Camera* active_viewer);

@ -185,7 +185,7 @@ void renderer_render(struct Renderer* renderer, struct Scene* scene)
{
snprintf(uniform_name, MAX_UNIFORM_NAME_LEN, "lights[%d].direction", light_count);
vec3 light_dir = { 0.f, 0.f, 0.f };
transform_get_absolute_lookat(&light->base, &light_dir);
transform_get_absolute_forward(&light->base, &light_dir);
vec3_norm(&light_dir, &light_dir);
shader_set_uniform_vec3(material->shader, uniform_name, &light_dir);
memset(uniform_name, '\0', MAX_UNIFORM_NAME_LEN);

Loading…
Cancel
Save