round camera xforms
This commit is contained in:
parent
e52470951a
commit
6bb1c07a94
@ -100,7 +100,7 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
|||||||
color *= albedo_tex[id];
|
color *= albedo_tex[id];
|
||||||
|
|
||||||
/* Apply lighting */
|
/* Apply lighting */
|
||||||
// color.rgb *= get_light_at_pos(id);
|
color.rgb *= get_light_at_pos(id);
|
||||||
|
|
||||||
/* Apply temporal accumulation */
|
/* Apply temporal accumulation */
|
||||||
float hysterisis = 0;
|
float hysterisis = 0;
|
||||||
|
|||||||
32
src/user.c
32
src/user.c
@ -888,6 +888,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
if (G.debug_camera) {
|
if (G.debug_camera) {
|
||||||
G.ui_size = G.screen_size;
|
G.ui_size = G.screen_size;
|
||||||
G.ui_to_screen_xf = XFORM_IDENT;
|
G.ui_to_screen_xf = XFORM_IDENT;
|
||||||
|
G.ui_to_screen_xf.og = v2_round(G.ui_to_screen_xf.og);
|
||||||
} else {
|
} else {
|
||||||
/* Determine ui size by camera & window dimensions */
|
/* Determine ui size by camera & window dimensions */
|
||||||
f32 aspect_ratio = (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT);
|
f32 aspect_ratio = (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT);
|
||||||
@ -911,6 +912,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
f32 x = math_round(G.screen_size.x / 2 - width / 2);
|
f32 x = math_round(G.screen_size.x / 2 - width / 2);
|
||||||
f32 y = math_round(G.screen_size.y / 2 - height / 2);
|
f32 y = math_round(G.screen_size.y / 2 - height / 2);
|
||||||
G.ui_to_screen_xf = XFORM_TRS(.t = V2(x, y));
|
G.ui_to_screen_xf = XFORM_TRS(.t = V2(x, y));
|
||||||
|
G.ui_to_screen_xf.og = v2_round(G.ui_to_screen_xf.og);
|
||||||
}
|
}
|
||||||
|
|
||||||
G.ui_cursor = xform_mul_v2(xform_invert(G.ui_to_screen_xf), G.screen_cursor);
|
G.ui_cursor = xform_mul_v2(xform_invert(G.ui_to_screen_xf), G.screen_cursor);
|
||||||
@ -948,6 +950,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
G.world_to_ui_xf = xform_scaled(G.world_to_ui_xf, V2(zoom, zoom));
|
G.world_to_ui_xf = xform_scaled(G.world_to_ui_xf, V2(zoom, zoom));
|
||||||
G.world_to_ui_xf = xform_translated(G.world_to_ui_xf, v2_neg(world_cursor));
|
G.world_to_ui_xf = xform_translated(G.world_to_ui_xf, v2_neg(world_cursor));
|
||||||
}
|
}
|
||||||
|
G.world_to_ui_xf.og = v2_round(G.world_to_ui_xf.og);
|
||||||
} else {
|
} else {
|
||||||
struct xform xf = sim_ent_get_xform(local_camera);
|
struct xform xf = sim_ent_get_xform(local_camera);
|
||||||
|
|
||||||
@ -975,23 +978,16 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
G.world_to_ui_xf = xform_rotated(G.world_to_ui_xf, trs.r);
|
G.world_to_ui_xf = xform_rotated(G.world_to_ui_xf, trs.r);
|
||||||
G.world_to_ui_xf = xform_scaled(G.world_to_ui_xf, trs.s);
|
G.world_to_ui_xf = xform_scaled(G.world_to_ui_xf, trs.s);
|
||||||
G.world_to_ui_xf = xform_translated(G.world_to_ui_xf, v2_neg(pivot));
|
G.world_to_ui_xf = xform_translated(G.world_to_ui_xf, v2_neg(pivot));
|
||||||
|
G.world_to_ui_xf.og = v2_round(G.world_to_ui_xf.og);
|
||||||
}
|
}
|
||||||
|
|
||||||
G.world_cursor = xform_invert_mul_v2(G.world_to_ui_xf, G.ui_cursor);
|
G.world_cursor = xform_invert_mul_v2(G.world_to_ui_xf, G.ui_cursor);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Update world to render xform from camera
|
* Update world to render xform from world to ui xform
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
//DEBUGBREAKABLE;
|
|
||||||
/* FIXME:
|
|
||||||
* At 180p & 360p, objects increment in uniform but grid does not.
|
|
||||||
* At 270p, grid increments in uniform but objects do not */
|
|
||||||
|
|
||||||
//G.render_vis_size = V2(320, 180);
|
|
||||||
//G.render_vis_size = V2(480, 270);
|
|
||||||
G.render_vis_size = V2(640, 360);
|
G.render_vis_size = V2(640, 360);
|
||||||
|
|
||||||
G.render_size = G.render_vis_size;
|
G.render_size = G.render_vis_size;
|
||||||
G.render_size.x += RENDER_MARGIN;
|
G.render_size.x += RENDER_MARGIN;
|
||||||
G.render_size.y += RENDER_MARGIN;
|
G.render_size.y += RENDER_MARGIN;
|
||||||
@ -1000,25 +996,12 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
struct xform ui_to_world_xf = xform_invert(G.world_to_ui_xf);
|
struct xform ui_to_world_xf = xform_invert(G.world_to_ui_xf);
|
||||||
struct v2 world_center = xform_mul_v2(ui_to_world_xf, v2_mul(G.ui_size, 0.5));
|
struct v2 world_center = xform_mul_v2(ui_to_world_xf, v2_mul(G.ui_size, 0.5));
|
||||||
|
|
||||||
//world_center = v2_sub(world_center, V2(1, 1));
|
|
||||||
|
|
||||||
/* Scale view into viewport based on camera size */
|
|
||||||
//struct v2 scale = v2_div_v2(G.render_size, G.ui_size);
|
|
||||||
struct v2 scale = ZI;
|
|
||||||
//scale = v2_mul(G.render_size, IMAGE_PIXELS_PER_UNIT);
|
|
||||||
//scale = V2(IMAGE_PIXELS_PER_UNIT, IMAGE_PIXELS_PER_UNIT);
|
|
||||||
//scale = v2_div_v2(V2(1, 1), scale);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
scale = xform_get_scale(G.world_to_ui_xf);
|
|
||||||
#elif 1
|
|
||||||
struct v2 vis_scale = v2_div_v2(G.render_vis_size, G.render_size);
|
struct v2 vis_scale = v2_div_v2(G.render_vis_size, G.render_size);
|
||||||
vis_scale.x = min_f32(vis_scale.x, vis_scale.y);
|
vis_scale.x = min_f32(vis_scale.x, vis_scale.y);
|
||||||
vis_scale.y = vis_scale.x;
|
vis_scale.y = vis_scale.x;
|
||||||
|
|
||||||
scale = V2(IMAGE_PIXELS_PER_UNIT, IMAGE_PIXELS_PER_UNIT);
|
struct v2 scale = V2(IMAGE_PIXELS_PER_UNIT, IMAGE_PIXELS_PER_UNIT);
|
||||||
scale = v2_mul_v2(scale, vis_scale);
|
scale = v2_mul_v2(scale, vis_scale);
|
||||||
#endif
|
|
||||||
|
|
||||||
struct xform xf = XFORM_IDENT;
|
struct xform xf = XFORM_IDENT;
|
||||||
|
|
||||||
@ -1027,6 +1010,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
|
|
||||||
xf = xform_scaled(xf, scale);
|
xf = xform_scaled(xf, scale);
|
||||||
xf = xform_translated(xf, v2_mul(world_center, -1));
|
xf = xform_translated(xf, v2_mul(world_center, -1));
|
||||||
|
xf.og = v2_round(xf.og);
|
||||||
|
|
||||||
G.world_to_render_xf = xf;
|
G.world_to_render_xf = xf;
|
||||||
}
|
}
|
||||||
@ -1060,7 +1044,7 @@ INTERNAL void user_update(struct sys_window *window)
|
|||||||
* ========================== */
|
* ========================== */
|
||||||
|
|
||||||
{
|
{
|
||||||
f32 thickness = 1;
|
f32 thickness = 2;
|
||||||
|
|
||||||
struct v2 offset = v2_neg(xform_mul_v2(G.world_to_render_xf, V2(0, 0)));
|
struct v2 offset = v2_neg(xform_mul_v2(G.world_to_render_xf, V2(0, 0)));
|
||||||
f32 spacing = xform_get_scale(G.world_to_render_xf).x;
|
f32 spacing = xform_get_scale(G.world_to_render_xf).x;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user