Added new comment to examples
This commit is contained in:
parent
8bd3ecaa66
commit
c1b01c0d5d
119 changed files with 376 additions and 46 deletions
|
@ -13,21 +13,14 @@
|
|||
|
||||
#include "raylib.h"
|
||||
|
||||
#define max(a, b) ((a)>(b)? (a) : (b))
|
||||
#define min(a, b) ((a)<(b)? (a) : (b))
|
||||
#include "raymath.h" // Required for: Vector2Clamp()
|
||||
|
||||
// Clamp Vector2 value with min and max and return a new vector2
|
||||
// NOTE: Required for virtual mouse, to clamp inside virtual game size
|
||||
Vector2 ClampValue(Vector2 value, Vector2 min, Vector2 max)
|
||||
{
|
||||
Vector2 result = value;
|
||||
result.x = (result.x > max.x)? max.x : result.x;
|
||||
result.x = (result.x < min.x)? min.x : result.x;
|
||||
result.y = (result.y > max.y)? max.y : result.y;
|
||||
result.y = (result.y < min.y)? min.y : result.y;
|
||||
return result;
|
||||
}
|
||||
#define MAX(a, b) ((a)>(b)? (a) : (b))
|
||||
#define MIN(a, b) ((a)<(b)? (a) : (b))
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
const int windowWidth = 800;
|
||||
|
@ -57,7 +50,7 @@ int main(void)
|
|||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// Compute required framebuffer scaling
|
||||
float scale = min((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);
|
||||
float scale = MIN((float)GetScreenWidth()/gameScreenWidth, (float)GetScreenHeight()/gameScreenHeight);
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
|
@ -70,7 +63,7 @@ int main(void)
|
|||
Vector2 virtualMouse = { 0 };
|
||||
virtualMouse.x = (mouse.x - (GetScreenWidth() - (gameScreenWidth*scale))*0.5f)/scale;
|
||||
virtualMouse.y = (mouse.y - (GetScreenHeight() - (gameScreenHeight*scale))*0.5f)/scale;
|
||||
virtualMouse = ClampValue(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ (float)gameScreenWidth, (float)gameScreenHeight });
|
||||
virtualMouse = Vector2Clamp(virtualMouse, (Vector2){ 0, 0 }, (Vector2){ (float)gameScreenWidth, (float)gameScreenHeight });
|
||||
|
||||
// Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
|
||||
//SetMouseOffset(-(GetScreenWidth() - (gameScreenWidth*scale))*0.5f, -(GetScreenHeight() - (gameScreenHeight*scale))*0.5f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue