Skip to content

Instantly share code, notes, and snippets.

View monxa's full-sized avatar

monxa

  • Germany
View GitHub Profile
@monxa
monxa / smooth_camera_zoom_and_pan.gd
Created February 8, 2025 13:21 — forked from Tam/smooth_camera_zoom_and_pan.gd
A smoothly panning and zooming camera for Godot 4 (now with mouse edge panning)
extends Camera2D
# Note: Limit smoothing and position smoothing must be disabled
const V2_2: Vector2 = Vector2.ONE * 2
const PAN_SPEED: int = 2000
const PAN_SMOOTHING: int = 8
# How far from the edge of the screen panning starts (% of screen size)
const EDGE_PAN_THRESHOLD_MIN: Vector2 = Vector2(0.06, 0.12)
@monxa
monxa / godot_uv_scale_inverse.txt
Last active November 6, 2023 13:28
inverse uv scaling for compressed mesh data in godot 4.2
// Adjusts UV and UV2 vectors based on provided uv_scale
void adjust_uv_scale(input_data &input, godot::Vector4 uv_scale) {
// If the uv_scale is an empty/default vector, no adjustment is necessary.
if (uv_scale == godot::Vector4())
return;
// Adjust UV coordinates
for (auto &uv : input.uvs) {
// The UV is shifted from a [0.5,1] range to [0,0.5] and then scaled according to the uv_scale.x and uv_scale.y.
// see: godot/servers/rendering_server.cpp:718 (line number might change obviously)