do zoom ability in here, to zoom in and out inside that cube grid with mouse wheel.…
- User
do zoom ability in here, to zoom in and out inside that cube grid with mouse wheel. also, do some rotation on all axis by mous dragging in empty space, set flag for auto-rotation to false. also, try to fit the entire 3d matrix grid on full canvas automatically, independent of gridSize or gridSpacing, with some small empty space around borders. need to preserve that clicking functionality to draw lines on grid. try integrate all described above but preserve mouse clicking on points that draw lines between 3d matrix grid points. output full javascript code, without shortages, but without html code included.:
canvas.width = window.innerWidth; canvas.height = window.innerHeight;
const rotationSpeed = 0.001; const gridSize = 50; const gridSpacing = 25;
let grid = []; for (let x = -gridSize; x <= gridSize; x += gridSpacing) { for (let y = -gridSize; y <= gridSize; y += gridSpacing) { for (let z = -gridSize; z <= gridSize; z += gridSpacing) { grid.push({ x, y, z }); } } } let lastClickedPoint = null; const clickedPoints = []; let angleX = 0; let angleY = 0;
function rotate(point, angleX, angleY) { const { x, y, z } = point; const cosX = Math.cos(angleX); const sinX = Math.sin(angleX); const cosY = Math.cos(angleY); const sinY = Math.sin(angleY);
codeconst newY = y * cosX - z * sinX; const newZ = y * sinX + z * cosX; const newX = x * cosY - newZ * sinY; const newZ2 = x * sinY + newZ * cosY; return { x: newX, y: newY, z: newZ2 };}
function project(point, width, height) { const { x, y, z } = point;
codeconst scale = 800 / (400 + z); const newX = x * scale + width / 2; const newY = y * scale + height / 2; return { x: newX, y: newY };}
function findClosestPoint(point) { const threshold = 20; // Adjust this value to set the click tolerance let minDist = Infinity; let minIndex = -1;
codefor (let i = 0; i < grid.length; i++) { const projected = project(rotate(grid[i], angleX, angleY), canvas.width, canvas.height); const dx = point.x - projected.x; const dy = point.y - projected.y; const dist = Math.sqrt(dx * dx + dy * dy); if (dist < minDist && dist <= threshold) { minDist = dist; minIndex = i; } } return minIndex !== -1 ? grid[minIndex] : null; - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.