Skip to content

Commit

Permalink
Fix camera rotation
Browse files Browse the repository at this point in the history
Ensure rotation and scale happen after translation, and from the center of the camera.

Fixes grimfang4#133 and grimfang4#124
  • Loading branch information
albertvaka authored Oct 4, 2020
1 parent 47a3e2b commit c124d52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/renderer_GL_common.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1191,24 +1191,27 @@ static void changeCamera(GPU_Target* target)

static void get_camera_matrix(GPU_Target* target, float* result)
{
float offsetX, offsetY;
float offsetX, offsetY;

GPU_MatrixIdentity(result);

GPU_MatrixTranslate(result, -target->camera.x, -target->camera.y, -target->camera.z);

if(target->camera.use_centered_origin)
{
offsetX = target->w/2.0f;
offsetY = target->h/2.0f;
GPU_MatrixTranslate(result, offsetX, offsetY, 0);
}

// Always rotate from the camera center
GPU_MatrixRotate(result, target->camera.angle, 0, 0, 1);
GPU_MatrixScale(result, target->camera.zoom_x, target->camera.zoom_y, 1.0f);

if(target->camera.use_centered_origin)
GPU_MatrixTranslate(result, -offsetX, -offsetY, 0);

GPU_MatrixTranslate(result, -target->camera.x, -target->camera.y, -target->camera.z);

GPU_MatrixScale(result, target->camera.zoom_x, target->camera.zoom_y, 1.0f);

}


Expand Down

0 comments on commit c124d52

Please sign in to comment.