Created
March 28, 2021 17:00
-
-
Save JeffM2501/edb5b8bbfd5a1744d4f97865ad4be989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************************* | |
* | |
* raylib [core] example - Basic window | |
* | |
* Welcome to raylib! | |
* | |
* To test examples, just press F6 and execute raylib_compile_execute script | |
* Note that compiled executable is placed in the same folder as .c file | |
* | |
* You can find all basic examples on C:\raylib\raylib\examples folder or | |
* raylib official webpage: www.raylib.com | |
* | |
* Enjoy using raylib. :) | |
* | |
* This example has been created using raylib 1.0 (www.raylib.com) | |
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) | |
* | |
* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) | |
* | |
********************************************************************************************/ | |
#include "raylib.h" | |
#include "raymath.h" | |
int main(void) | |
{ | |
// Initialization | |
//-------------------------------------------------------------------------------------- | |
const int screenWidth = 800; | |
const int screenHeight = 450; | |
InitWindow(screenWidth, screenHeight, "raylib [2d] example - world space paning"); | |
Camera2D cam = { 0 }; | |
cam.zoom = 1; | |
cam.offset.x = GetScreenWidth() / 2.0f; | |
cam.offset.y = GetScreenHeight() / 2.0f; | |
Vector2 prevMousePos = GetMousePosition(); | |
SetTargetFPS(60); // Set our game to run at 60 frames-per-second | |
//-------------------------------------------------------------------------------------- | |
// Main game loop | |
while (!WindowShouldClose()) // Detect window close button or ESC key | |
{ | |
Vector2 mapDelta = { 0,0 }; | |
float mouseDelta = GetMouseWheelMove(); | |
float newZoom = cam.zoom + mouseDelta * 0.01f; | |
if (newZoom <= 0) | |
newZoom = 0.01f; | |
cam.zoom = newZoom; | |
Vector2 thisPos = GetMousePosition(); | |
Vector2 delta = Vector2Subtract(prevMousePos, thisPos); | |
prevMousePos = thisPos; | |
if (IsMouseButtonDown(0)) | |
{ | |
mapDelta = Vector2Scale(delta, 1.0f/cam.zoom); | |
cam.target = Vector2Add(cam.target, mapDelta); | |
} | |
BeginDrawing(); | |
ClearBackground(RAYWHITE); | |
BeginMode2D(cam); | |
float size = 5000; | |
for (float x = -size; x <= size; x += 10) | |
{ | |
DrawLine(x, -size, x, size, GRAY); | |
} | |
for (float y = -size; y <= size; y += 10) | |
{ | |
DrawLine(-size, y, size, y, GRAY); | |
} | |
DrawLine(-size, 0, size, 0, RED); | |
DrawLine(0, -size, 0, size, RED); | |
EndMode2D(); | |
DrawText(TextFormat("%f %f", delta.x, delta.y),10, 10, 20, BLACK); | |
DrawText(TextFormat("%f %f", mapDelta.x, mapDelta.y), 10, 30, 20, BLACK); | |
EndDrawing(); | |
//---------------------------------------------------------------------------------- | |
} | |
// De-Initialization | |
//-------------------------------------------------------------------------------------- | |
CloseWindow(); // Close window and OpenGL context | |
//-------------------------------------------------------------------------------------- | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment