You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.5 KiB
94 lines
2.5 KiB
//Standard lib
|
|
|
|
//Third party
|
|
#include "raylib.h"
|
|
|
|
//Our own files
|
|
#include "constants.h"
|
|
#include "programstate.h"
|
|
#include "camera.h"
|
|
|
|
extern ProgramState programState;
|
|
|
|
|
|
// https://www.raylib.com/examples/web/core/loader.html?name=core_2d_camera
|
|
//Camera controls, such as zoom and reset, are in gui.c
|
|
|
|
static int screenWidth;
|
|
static int screenHeight;
|
|
|
|
void cameraMoveUpdate() {
|
|
programState.camera.offset = (Vector2){ screenWidth/2+programState.cameraCenterOnX, screenHeight/2+programState.cameraCenterOnY };
|
|
}
|
|
|
|
void cameraLeft() {
|
|
programState.cameraCenterOnX -= 10;
|
|
cameraMoveUpdate();
|
|
}
|
|
void cameraRight() {
|
|
programState.cameraCenterOnX += 10;
|
|
cameraMoveUpdate();
|
|
}
|
|
void cameraUp() {
|
|
programState.cameraCenterOnY -= 10;
|
|
cameraMoveUpdate();
|
|
}
|
|
void cameraDown() {
|
|
programState.cameraCenterOnY += 10;
|
|
cameraMoveUpdate();
|
|
}
|
|
|
|
void cameraMaybeZoom() {
|
|
//float rememberZoom = programState.camera.zoom;
|
|
if (!programState.lockInput) {
|
|
programState.camera.zoom += ((float)GetMouseWheelMove()*0.05f);
|
|
if (programState.camera.zoom < 0)
|
|
programState.camera.zoom = 0.0f;
|
|
//if (rememberZoom != programState.camera.zoom) {}
|
|
}
|
|
}
|
|
|
|
void cameraReset() {
|
|
//Only called through user action. Camera startup values are either loaded from file or set in programstate.c
|
|
programState.camera.zoom = 1.0f;
|
|
programState.camera.rotation = 0.0f;
|
|
programState.cameraCenterOnX = 0;
|
|
programState.cameraCenterOnY = 0;
|
|
cameraMoveUpdate();
|
|
}
|
|
|
|
void cameraNormalizeRotation() {
|
|
if (programState.camera.rotation > 359) programState.camera.rotation -= 360;
|
|
else if (programState.camera.rotation < 0) programState.camera.rotation += 360;
|
|
}
|
|
|
|
void cameraRotateLeft() {
|
|
programState.camera.rotation--;
|
|
cameraNormalizeRotation();
|
|
}
|
|
|
|
void cameraRotateRight() {
|
|
programState.camera.rotation++;
|
|
cameraNormalizeRotation();
|
|
}
|
|
|
|
void cameraRotate180() {
|
|
programState.camera.rotation += 180.0f;
|
|
cameraNormalizeRotation();
|
|
}
|
|
|
|
void cameraFlip() {
|
|
programState.camera.zoom *= -1.0f; //this is the same as rotation by 180, and not mirror
|
|
//programState.camera.rotation += 180.0f;
|
|
}
|
|
|
|
void mainLoop_cameraReposition() {
|
|
if (programState.guiRedrawNeeded) {
|
|
screenWidth = GetScreenWidth(); //Changes on resize
|
|
screenHeight = GetScreenHeight(); //Changes on resize
|
|
programState.camera.target = (Vector2){ screenWidth/2, screenHeight/2 };
|
|
programState.camera.offset = (Vector2){ screenWidth/2+programState.cameraCenterOnX, screenHeight/2+programState.cameraCenterOnY };
|
|
}
|
|
}
|
|
|
|
|
|
|