diff options
| author | arvyy <nma.arvydas.silanskas@gmail.com> | 2019-08-16 17:09:50 +0300 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2019-08-16 16:09:50 +0200 |
| commit | d8b8c0f3fc8ab3872c65bcfefd258bd6ad4ece51 (patch) | |
| tree | fb6b63936475f0d90702eb8e489ee102f2d5e90a /src | |
| parent | c387bc586d9c8b9fe9bb840926d12526aaad9116 (diff) | |
| download | raylib-d8b8c0f3fc8ab3872c65bcfefd258bd6ad4ece51.tar.gz raylib-d8b8c0f3fc8ab3872c65bcfefd258bd6ad4ece51.zip | |
change Camera2D behavior (#945)
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1251,11 +1251,24 @@ void BeginMode2D(Camera2D camera) rlLoadIdentity(); // Reset current matrix (MODELVIEW) rlMultMatrixf(MatrixToFloat(screenScaling)); // Apply screen scaling if required - // Camera rotation and scaling is always relative to target + //The camera in world-space is set by + //1. Move it to target + //2. Rotate by -rotation and scale by (1/zoom) + // When setting higher scale, it's more intuitive for the world to become bigger (= camera become smaller), + // not for the camera getting bigger, hence the invert. Same deal with rotation. + //3. Move it by (-offset); + // Offset defines target transform relative to screen, but since we're effectively "moving" screen (camera) + // we need to do it into opposite direction (inverse transform) + // + //Having camera transform in world-space, inverse of it gives the modelview transform. + //Since (A*B*C)' = C'*B'*A', the modelview is + //1. Move to offset + //2. Rotate and Scale + //3. Move by -target Matrix matOrigin = MatrixTranslate(-camera.target.x, -camera.target.y, 0.0f); Matrix matRotation = MatrixRotate((Vector3){ 0.0f, 0.0f, 1.0f }, camera.rotation*DEG2RAD); Matrix matScale = MatrixScale(camera.zoom, camera.zoom, 1.0f); - Matrix matTranslation = MatrixTranslate(camera.offset.x + camera.target.x, camera.offset.y + camera.target.y, 0.0f); + Matrix matTranslation = MatrixTranslate(camera.offset.x, camera.offset.y, 0.0f); Matrix matTransform = MatrixMultiply(MatrixMultiply(matOrigin, MatrixMultiply(matScale, matRotation)), matTranslation); |
