Use logarithmic zoom scaling in 2d camera zoom examples
This commit is contained in:
parent
cd9206956c
commit
8b84c999d2
2 changed files with 10 additions and 8 deletions
|
@ -14,6 +14,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define MAX_BUILDINGS 100
|
#define MAX_BUILDINGS 100
|
||||||
|
|
||||||
|
@ -81,7 +82,8 @@ int main(void)
|
||||||
else if (camera.rotation < -40) camera.rotation = -40;
|
else if (camera.rotation < -40) camera.rotation = -40;
|
||||||
|
|
||||||
// Camera zoom controls
|
// Camera zoom controls
|
||||||
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
// Uses log scaling to provide consistent zoom speed
|
||||||
|
camera.zoom = expf(logf(camera.zoom) + ((float)GetMouseWheelMove()*0.05f));
|
||||||
|
|
||||||
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
|
||||||
else if (camera.zoom < 0.1f) camera.zoom = 0.1f;
|
else if (camera.zoom < 0.1f) camera.zoom = 0.1f;
|
||||||
|
|
|
@ -73,9 +73,9 @@ int main ()
|
||||||
camera.target = mouseWorldPos;
|
camera.target = mouseWorldPos;
|
||||||
|
|
||||||
// Zoom increment
|
// Zoom increment
|
||||||
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
|
// Uses log scaling to provide consistent zoom speed
|
||||||
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
float scale = 0.2f*wheel;
|
||||||
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -96,10 +96,10 @@ int main ()
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
|
||||||
{
|
{
|
||||||
// Zoom increment
|
// Zoom increment
|
||||||
|
// Uses log scaling to provide consistent zoom speed
|
||||||
float deltaX = GetMouseDelta().x;
|
float deltaX = GetMouseDelta().x;
|
||||||
float scaleFactor = 1.0f + (0.01f*fabsf(deltaX));
|
float scale = 0.005f*deltaX;
|
||||||
if (deltaX < 0) scaleFactor = 1.0f/scaleFactor;
|
camera.zoom = Clamp(expf(logf(camera.zoom)+scale), 0.125f, 64.0f);
|
||||||
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -143,4 +143,4 @@ int main ()
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue