// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Point to nearest hex-grid cell // Not compiled or tested in-world // Setup: Use a spare owned prim. Set POINT and positive hex RADIUS. Touch for owner-only results. // Stop / restore: Disable/remove. No scene properties change. // Notes: Uses cube-coordinate rounding to keep the three hex axes consistent; radius is center-to-corner distance. // License: see LICENSE in this distribution. // Original Incoprea. MIT. vector POINT=<5.2,3.1,0.0>; float RADIUS=1.0; default { touch_start(integer detectedCount) { if(llDetectedKey(0)!=llGetOwner())return; if(RADIUS<=0.0) { llOwnerSay("Positive radius required."); return; } float q=(llSqrt(3.0)/3.0*POINT.x-POINT.y/3.0)/RADIUS; float r=(2.0/3.0*POINT.y)/RADIUS; float y=-q-r; integer rx=llRound(q); integer ry=llRound(y); integer rz=llRound(r); float dx=llFabs(rx-q); float dy=llFabs(ry-y); float dz=llFabs(rz-r); if(dx>dy&&dx>dz)rx=-ry-rz; else if(dy>dz)ry=-rx-rz; else rz=-rx-ry; vector centre=; llOwnerSay("Axial q/r="+(string)rx+"/"+(string)rz+"; centre="+(string)centre); } }