Whenever the camera is moved, all dynamic bodies seem to jitter for some reason.
At render, transforms are converted into pixels with:
SDL_FRect transform_to_dst(const Scene& scene, const Transform& transform, const Renderable& renderable) noexcept {
const Transform& cam_transform = scene.registry.get<Transform>(scene.get_active_camera());
SDL_FRect dst{};
dst.x = ((transform.value.x - transform.value.w) - (cam_transform.value.x - cam_transform.value.w)) * renderable.scale_factor;
dst.y = -((transform.value.y + transform.value.h) - (cam_transform.value.y + cam_transform.value.h)) * renderable.scale_factor;
dst.w = (transform.value.w * 2) * renderable.scale_factor;
dst.h = (transform.value.h * 2) * renderable.scale_factor;
return dst;
}
Then rendered like so:
for (auto [entity, transform, renderable, visuals] : scene.registry.view<Transform, Renderable, Static_visuals>().each()) {
const SDL_FRect dst{transform_to_dst(scene, transform, renderable)};
visuals.content.render(renderable.renderer, &dst, util::to_degrees(transform.angle));
}
The two entities I have for testing have a b2PolygonShape
with sizes of (0.5, 0.5). Whenever the camera is moved, these two entities seem to shift by about 1 pixel. If I don't give them a b2Body
, they stay in their place as they should. Any idea what could be causing this?
Video: https://imgur.com/a/YBLRQGn
Currently the camera's position gets set to the player at every update, but moving the camera on its own results in the same issue.
Edit: disabling the b2Bodies
but setting their positions to the spots they would've fallen to still results in the same issue, so the problem doesn't seem to be with Box2D.