RunicVTT Open Source Virtual Tabletop for TTRPG using P2P
Loading...
Searching...
No Matches
BoardManager.cpp File Reference
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "BoardManager.h"
#include "UiTypingGuard.h"
#include "Renderer.h"
#include "Shader.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
#include "VertexArray.h"
#include "VertexBufferLayout.h"
#include "Texture.h"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include <glm/gtc/round.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/common.hpp>
#include "Components.h"
#include <filesystem>
#include <random>
#include <atomic>
#include <cstdint>
#include "Serializer.h"
#include "NetworkManager.h"
#include "Logger.h"
#include <chrono>
#include <cstdlib>
#include <functional>
#include <string>
#include <thread>
#include <unordered_map>
Include dependency graph for BoardManager.cpp:

Go to the source code of this file.

Functions

static glm::vec2 snapToSquareCenter (const glm::vec2 &worldPos, const glm::vec2 &offset, float cell)
 
static glm::vec2 snapToGridCenter (const glm::vec2 &worldPos, const Grid &grid)
 

Function Documentation

◆ snapToGridCenter()

static glm::vec2 snapToGridCenter ( const glm::vec2 & worldPos,
const Grid & grid )
inlinestatic

Definition at line 830 of file BoardManager.cpp.

831{
832 if (!grid.snap_to_grid || grid.cell_size <= 0.0f)
833 return worldPos;
834 return snapToSquareCenter(worldPos, grid.offset, grid.cell_size);
835}
static glm::vec2 snapToSquareCenter(const glm::vec2 &worldPos, const glm::vec2 &offset, float cell)
bool snap_to_grid
Definition Components.h:68
glm::vec2 offset
Definition Components.h:65
float cell_size
Definition Components.h:66
Here is the call graph for this function:

◆ snapToSquareCenter()

static glm::vec2 snapToSquareCenter ( const glm::vec2 & worldPos,
const glm::vec2 & offset,
float cell )
inlinestatic

Definition at line 817 of file BoardManager.cpp.

818{
819 // transform to grid-local space (subtract offset, not add)
820 const glm::vec2 local = worldPos - offset;
821
822 // center within a cell
823 const glm::vec2 half(cell * 0.5f);
824
825 // round to nearest cell center in local space, then bring back to world
826 const glm::vec2 snappedLocal = glm::round((local - half) / cell) * cell + half;
827 return snappedLocal + offset;
828}
Here is the caller graph for this function: