Prompt specification
Build or customize the Three.js 3D scene "Launch-angle range explorer" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Launch-angle range explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/launch-angle-range-explorer-x1420
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts projectile trajectories under gravity. Provide bounded speed and angle controls over flat ground; compare trajectories and landing positions under the displayed ballistic assumptions, with a fixed resettable launch point. Voxel style.
Working Three.js Starter (launch-angle-range-explorer-x1420):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Arc — Ballistics Lab</title>
<style>
:root {
--bg: #07111e;
--panel: rgba(9, 22, 37, 0.88);
--panel-solid: #0b1b2d;
--line: rgba(137, 184, 213, 0.2);
--text: #e5f3ff;
--muted: #82a0b8;
--cyan: #22d3ee;
--cyan-soft: #a5f3fc;
--orange: #fb923c;
--orange-soft: #fed7aa;
--yellow: #fde047;
--green: #4ade80;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 20%, #17324a 0, transparent 36%),
linear-gradient(180deg, #0a1727 0%, #07111e 65%, #050b13 100%);
color: var(--text);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--line);
box-shadow:
0 12px 35px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(14px);
clip-path: polygon(
0 9px,
9px 0,
calc(100% - 9px) 0,
100% 9px,
100% calc(100% - 9px),
calc(100% - 9px) 100%,
9px 100%,
0 calc(100% - 9px)
);
}
.brand {
top: 18px;
left: 18px;
width: 330px;
padding: 17px 19px 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
}
.pixel {
width: 8px;
height: 8px;
background: var(--cyan);
box-shadow:
4px 0 rgba(34, 211, 238, 0.45),
0 4px rgba(34, 211, 238, 0.45);
}
h1 {
margin: 9px 0 2px;
font-size: clamp(25px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.06em;
}
h1 span {
color: var(--cyan);
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.controls {
left: 18px;
bottom: 18px;
width: 330px;
padding: 17px 18px 16px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
}
.status {
padding: 4px 7px;
border: 1px solid rgba(74, 222, 128, 0.3);
background: rgba(74, 222, 128, 0.09);
color: var(--green);
font-size: 9px;
letter-spacing: 0.1em;
}
.status[data-state="flight"] {
border-color: rgba(34, 211, 238, 0.38);
background: rgba(34, 211, 238, 0.09);
color: var(--cyan-soft);
}
.status[data-state="paused"] {
border-color: rgba(251, 146, 60, 0.38);
background: rgba(251, 146, 60, 0.09);
color: var(--orange-soft);
}
.status[data-state="ready"] {
border-color: rgba(130, 160, 184, 0.3);
background: rgba(130, 160, 184, 0.08);
color: var(--muted);
}
.control {
margin-bottom: 17px;
}
.control-title {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-bottom: 9px;
}
.control-title span {
color: #c6d9e8;
font-size: 11px;
}
output {
color: var(--cyan-soft);
font-size: 13px;
font-weight: 800;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 6px;
margin: 0;
appearance: none;
border-radius: 0;
background:
linear-gradient(
90deg,
var(--cyan) 0,
var(--cyan) var(--fill),
#203449 var(--fill),
#203449 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 18px;
appearance: none;
border: 2px solid #07111e;
background: var(--cyan-soft);
box-shadow: 0 0 0 1px var(--cyan);
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 16px;
border: 2px solid #07111e;
border-radius: 0;
background: var(--cyan-soft);
box-shadow: 0 0 0 1px var(--cyan);
cursor: ew-resize;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #617f97;
font-size: 9px;
}
.button-row {
display: grid;
grid-template-columns: 1.15fr 1fr 1fr;
gap: 7px;
}
button {
min-height: 36px;
padding: 0 10px;
border: 1px solid #2b4359;
border-radius: 0;
background: #11263a;
color: #c9e0f2;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
transition:
background 120ms ease,
border-color 120ms ease,
transform 120ms ease;
}
button:hover {
border-color: #52748f;
background: #183149;
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: var(--cyan);
background: var(--cyan);
color: #04131c;
}
button.primary:hover {
background: #67e8f9;
}
.origin {
display: flex;
justify-content: space-between;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid rgba(137, 184, 213, 0.12);
color: var(--muted);
font-size: 9px;
}
.origin b {
color: #c9dceb;
font-weight: 600;
}
.comparison {
top: 18px;
right: 18px;
width: 360px;
padding: 17px 18px 16px;
}
.legend {
display: flex;
align-items: center;
gap: 16px;
margin-top: 13px;
color: var(--muted);
font-size: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 8px;
height: 8px;
box-shadow: 0 0 9px currentColor;
}
.legend-dot.current {
color: var(--cyan);
background: var(--cyan);
}
.legend-dot.reference {
color: var(--orange);
background: var(--orange);
}
.metric-grid {
display: grid;
grid-template-columns: 1.35fr 1fr 1fr;
gap: 0;
border: 1px solid rgba(137, 184, 213, 0.13);
}
.metric-cell {
min-height: 52px;
padding: 10px 9px;
border-right: 1px solid rgba(137, 184, 213, 0.12);
border-bottom: 1px solid rgba(137, 184, 213, 0.12);
}
.metric-cell:nth-child(3n) {
border-right: 0;
}
.metric-cell:nth-last-child(-n + 3) {
border-bottom: 0;
}
.metric-cell.head {
min-height: 31px;
padding-top: 8px;
padding-bottom: 7px;
color: #718ea5;
font-size: 8px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-cell.head.current {
color: var(--cyan);
}
.metric-cell.head.reference {
color: var(--orange);
}
.metric-cell span {
display: block;
color: #718ea5;
font-size: 8px;
line-height: 1.25;
}
.metric-cell b {
display: block;
margin-top: 5px;
color: #d9edf9;
font-size: 12px;
}
.metric-cell b.current {
color: var(--cyan-soft);
}
.metric-cell b.reference {
color: var(--orange-soft);
}
.delta {
margin-top: 10px;
color: #7897ae;
font-size: 9px;
text-align: right;
}
.delta b {
color: var(--cyan-soft);
}
.assumptions {
right: 18px;
bottom: 18px;
width: 360px;
padding: 16px 18px;
}
.assumption-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 14px;
margin-top: 12px;
}
.assumption {
display: flex;
justify-content: space-between;
gap: 8px;
padding-bottom: 7px;
border-bottom: 1px solid rgba(137, 184, 213, 0.1);
color: #7897ae;
font-size: 9px;
}
.assumption b {
color: #c9deec;
font-weight: 700;
}
.equation {
margin-top: 12px;
padding: 9px 10px;
border-left: 2px solid var(--cyan);
background: rgba(34, 211, 238, 0.055);
color: #b7cfdf;
font-size: 9px;
line-height: 1.6;
}
.camera-hint {
position: absolute;
left: 50%;
top: 20px;
transform: translateX(-50%);
padding: 7px 10px;
border: 1px solid rgba(137, 184, 213, 0.14);
background: rgba(7, 17, 30, 0.55);
color: #6e8ba1;
font-size: 8px;
letter-spacing: 0.12em;
white-space: nowrap;
}
.world-label {
position: fixed;
z-index: 4;
display: none;
min-width: 86px;
padding: 6px 8px;
border: 1px solid currentColor;
background: rgba(5, 13, 23, 0.88);
color: var(--cyan);
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
transform: translate(-50%, -100%);
pointer-events: none;
text-align: center;
}
.world-label b {
display: block;
font-size: 8px;
letter-spacing: 0.12em;
}
.world-label span {
display: block;
margin-top: 3px;
color: #e4f3ff;
font-size: 10px;
font-weight: 800;
}
#referenceLabel {
color: var(--orange);
}
#launchLabel {
color: var(--yellow);
min-width: 92px;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07111e;
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.18em;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loading-box {
padding: 18px 24px;
border: 1px solid rgba(34, 211, 238, 0.35);
background: rgba(9, 22, 37, 0.8);
}
@media (max-width: 860px) {
.brand,
.controls {
width: 290px;
}
.comparison,
.assumptions {
width: 305px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 650px) {
.brand {
top: 10px;
left: 10px;
width: calc(100% - 20px);
padding: 13px 15px;
}
.brand p {
display: none;
}
.comparison {
top: 100px;
right: 10px;
width: 230px;
padding: 13px;
}
.assumptions {
top: 100px;
left: 10px;
bottom: auto;
width: 190px;
padding: 12px;
}
.assumption-list {
grid-template-columns: 1fr;
}
.equation {
display: none;
}
.controls {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 40vh;
overflow: auto;
}
.world-label {
transform: translate(-50%, -100%) scale(0.85);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="brand panel">
<div class="eyebrow">
<span class="pixel"></span>
FLIGHT LAB / VOXEL SERIES
</div>
<h1>VOXEL <span>ARC</span></h1>
<p>Compare ideal projectile trajectories under constant gravity.</p>
</header>
<section class="controls panel">
<div class="panel-heading">
<span>LAUNCH PARAMETERS</span>
<span id="status" class="status" data-state="flight">IN FLIGHT</span>
</div>
<div class="control">
<div class="control-title">
<label for="speed">Launch speed</label>
<output id="speedOut" for="speed">32 m/s</output>
</div>
<input id="speed" type="range" min="10" max="50" step="1" value="32">
<div class="range-scale">
<span>10</span>
<span>50 m/s</span>
</div>
</div>
<div class="control">
<div class="control-title">
<label for="angle">Launch angle</label>
<output id="angleOut" for="angle">48°</output>
</div>
<input id="angle" type="range" min="10" max="80" step="1" value="48">
<div class="range-scale">
<span>10°</span>
<span>80°</span>
</div>
</div>
<div class="button-row">
<button id="fireButton" class="primary" type="button">PAUSE</button>
<button id="referenceButton" type="button">SET REF</button>
<button id="resetButton" type="button">RESET</button>
</div>
<div class="origin">
<span>FIXED ORIGIN</span>
<b>x = 0.0 m · height = 1.6 m</b>
</div>
</section>
<section class="comparison panel">
<div class="panel-heading">
<span>SHOT COMPARISON</span>
<span>IDEAL MODEL</span>
</div>
<div class="metric-grid">
<div class="metric-cell head">Measurement</div>
<div class="metric-cell head current">Current</div>
<div class="metric-cell head reference">Reference</div>
<div class="metric-cell">
<span>Landing X</span>
</div>
<div class="metric-cell">
<b id="currentRange" class="current">—</b>
</div>
<div class="metric-cell">
<b id="referenceRange" class="reference">—</b>
</div>
<div class="metric-cell">
<span>Peak height</span>
</div>
<div class="metric-cell">
<b id="currentHeight" class="current">—</b>
</div>
<div class="metric-cell">
<b id="referenceHeight" class="reference">—</b>
</div>
<div class="metric-cell">
<span>Flight time</span>
</div>
<div class="metric-cell">
<b id="currentTime" class="current">—</b>
</div>
<div class="metric-cell">
<b id="referenceTime" class="reference">—</b>
</div>
</div>
<div class="delta">
Landing difference: <b id="deltaText">—</b>
</div>
<div class="legend">
<span class="legend-item">
<span class="legend-dot current"></span>
Current shot
</span>
<span class="legend-item">
<span class="legend-dot reference"></span>
Saved reference
</span>
</div>
</section>
<aside class="assumptions panel">
<div class="panel-heading">
<span>BALLISTIC ASSUMPTIONS</span>
</div>
<div class="assumption-list">
<div class="assumption"><span>Gravity</span><b>9.81 m/s²</b></div>
<div class="assumption"><span>Air drag</span><b>None</b></div>
<div class="assumption"><span>Ground</span><b>Flat, y = 0</b></div>
<div class="assumption"><span>Launch height</span><b>1.6 m</b></div>
<div class="assumption"><span>Wind</span><b>0 m/s</b></div>
<div class="assumption"><span>Origin</span><b>x = 0 m</b></div>
</div>
<div class="equation">
x(t) = v₀ cos(θ)t<br>
y(t) = 1.6 + v₀ sin(θ)t − ½gt²<br>
z(t) = 0
</div>
</aside>
<div class="camera-hint">
DRAG TO ORBIT · WHEEL TO ZOOM · DOUBLE-CLICK FOR HOME VIEW
</div>
</div>
<div id="currentLabel" class="world-label">
<b>CURRENT</b>
<span>—</span>
</div>
<div id="referenceLabel" class="world-label">
<b>REFERENCE</b>
<span>—</span>
</div>
<div id="launchLabel" class="world-label">
<b>FIXED LAUNCH</b>
<span>0.0 m / 1.6 m</span>
</div>
<div id="loading">
<div class="loading-box">BUILDING VOXEL FLIGHT LAB...</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Physical and visual constants
// ---------------------------------------------------------------------
const GRAVITY = 9.81; // m/s²
const LAUNCH_HEIGHT = 1.6; // meters
const METERS_PER_UNIT = 0.25; // one Three.js unit represents four meters
const GROUND_LENGTH = 72; // world units
const GROUND_DEPTH = 42;
const ui = {
speed: document.getElementById("speed"),
angle: document.getElementById("angle"),
speedOut: document.getElementById("speedOut"),
angleOut: document.getElementById("angleOut"),
status: document.getElementById("status"),
fire: document.getElementById("fireButton"),
reference: document.getElementById("referenceButton"),
reset: document.getElementById("resetButton"),
currentRange: document.getElementById("currentRange"),
referenceRange: document.getElementById("referenceRange"),
currentHeight: document.getElementById("currentHeight"),
referenceHeight: document.getElementById("referenceHeight"),
currentTime: document.getElementById("currentTime"),
referenceTime: document.getElementById("referenceTime"),
delta: document.getElementById("deltaText"),
currentLabel: document.getElementById("currentLabel"),
referenceLabel: document.getElementById("referenceLabel"),
launchLabel: document.getElementById("launchLabel"),
loading: document.getElementById("loading")
};
const state = {
speed: 32,
angle: 48,
referenceSpeed: 26,
referenceAngle: 42,
elapsed: 0,
playing: true,
landed: false,
zoom: 1,
azimuth: -0.48,
polar: 1.08
};
const clamp = THREE.MathUtils.clamp;
// ---------------------------------------------------------------------
// Renderer, scene, and orthographic camera
// ---------------------------------------------------------------------
const host = document.getElementById("scene");
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x07111e, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-40, 40, 26, -26, 0.1, 300);
const cameraTarget = new THREE.Vector3(29, 4, 0);
const hemisphere = new THREE.HemisphereLight(0xb9e6ff, 0x142033, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b5, 3.0);
sun.position.set(-24, 58, 34);
sun.target.position.set(28, 0, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -90;
sun.shadow.camera.right = 90;
sun.shadow.camera.top = 55;
sun.shadow.camera.bottom = -55;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 170;
sun.shadow.bias = -0.0006;
scene.add(sun, sun.target);
const rim = new THREE.DirectionalLight(0x37b9ff, 1.1);
rim.position.set(50, 18, -30);
scene.add(rim);
// ---------------------------------------------------------------------
// Voxel ground
// ---------------------------------------------------------------------
const groundBase = new THREE.Mesh(
new THREE.BoxGeometry(84, 1.1, GROUND_DEPTH + 2),
new THREE.MeshStandardMaterial({
color: 0x081523,
roughness: 0.95,
metalness: 0.05
})
);
groundBase.position.set(30, -0.75, 0);
groundBase.receiveShadow = true;
scene.add(groundBase);
const tileGeometry = new THREE.BoxGeometry(1.92, 0.32, 1.92);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88,
metalness: 0.08,
vertexColors: true
});
const columns = 40;
const rows = 20;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
columns * rows
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
const x = -7 + column * 2;
const z = -19 + row * 2;
dummy.position.set(x, -0.16, z);
dummy.scale.set(1, 1, 1);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation = ((column * 13 + row * 7) % 11) / 80;
const laneDarkening = Math.abs(z) < 2.2 ? 0.025 : 0;
tileColor.setHSL(
0.565,
0.27,
0.105 + variation + laneDarkening
);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Dashed center line.
const dashGeometry = new THREE.BoxGeometry(1, 1, 1);
const dashMaterial = new THREE.MeshBasicMaterial({
color: 0x1e6374,
transparent: true,
opacity: 0.62
});
const dashes = new THREE.InstancedMesh(dashGeometry, dashMaterial, 40);
for (let i = 0; i < 40; i++) {
dummy.position.set(-7 + i * 2, 0.025, 0);
dummy.scale.set(0.72, 0.05, 0.08);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
dashes.setMatrixAt(i, dummy.matrix);
}
dashes.instanceMatrix.needsUpdate = true;
scene.add(dashes);
// Distance ticks every 20 meters.
const tickCount = 13;
const ticks = new THREE.InstancedMesh(
dashGeometry,
new THREE.MeshBasicMaterial({
color: 0x57748a,
transparent: true,
opacity: 0.7
}),
tickCount
);
for (let i = 0; i < tickCount; i++) {
dummy.position.set(i * 20 * METERS_PER_UNIT, 0.03, 1.7);
dummy.scale.set(0.08, 0.06, 1.25);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
ticks.setMatrixAt(i, dummy.matrix);
}
ticks.instanceMatrix.needsUpdate = true;
scene.add(ticks);
// Low voxel skyline at the far edge of the range.
const skyline = new THREE.InstancedMesh(
dashGeometry,
new THREE.MeshStandardMaterial({
color: 0x10263a,
roughness: 0.9
}),
34
);
for (let i = 0; i < 34; i++) {
const x = -3 + i * 2.2;
const h = 1.2 + ((i * 17) % 9) * 0.42;
const w = 1.1 + ((i * 7) % 4) * 0.22;
dummy.position.set(x, h * 0.5, -22.6);
dummy.scale.set(w, h, 1.7);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
skyline.setMatrixAt(i, dummy.matrix);
}
skyline.instanceMatrix.needsUpdate = true;
scene.add(skyline);
// ---------------------------------------------------------------------
// Fixed launcher
// ---------------------------------------------------------------------
const launcher = new THREE.Group();
scene.add(launcher);
const launcherDark = new THREE.MeshStandardMaterial({
color: 0x18344b,
roughness: 0.72,
metalness: 0.18
});
const launcherBright = new THREE.MeshStandardMaterial({
color: 0xfde047,
emissive: 0x7c5d00,
emissiveIntensity: 0.65,
roughness: 0.55
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(2.4, 0.16, 2.4),
launcherDark
);
pad.position.y = 0.08;
pad.castShadow = true;
pad.receiveShadow = true;
launcher.add(pad);
const padInset = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.08, 1.25),
launcherBright
);
padInset.position.y = 0.2;
padInset.castShadow = true;
launcher.add(padInset);
const originPillar = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 1.9, 0.18),
launcherDark
);
originPillar.position.set(-0.9, 0.95, -1.3);
originPillar.castShadow = true;
launcher.add(originPillar);
const originBeacon = new THREE.Mesh(
new THREE.BoxGeometry(0.28, 0.28, 0.28),
launcherBright
);
originBeacon.position.set(-0.9, 2.0, -1.3);
launcher.add(originBeacon);
// ---------------------------------------------------------------------
// Projectile, landing markers, and trajectory voxel paths
// ---------------------------------------------------------------------
const projectile = new THREE.Group();
scene.add(projectile);
const projectileMaterial = new THREE.MeshStandardMaterial({
color: 0xfff176,
emissive: 0xffb900,
emissiveIntensity: 1.35,
roughness: 0.35
});
const projectileCore = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.34, 0.34),
projectileMaterial
);
projectileCore.castShadow = true;
projectile.add(projectileCore);
const finGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.12);
const finOffsets = [
[0.22, 0, 0],
[-0.22, 0, 0],
[0, 0.22, 0],
[0, -0.22, 0]
];
for (const [x, y, z] of finOffsets) {
const fin = new THREE.Mesh(finGeometry, projectileMaterial);
fin.position.set(x, y, z);
fin.castShadow = true;
projectile.add(fin);
}
const projectileLight = new THREE.PointLight(0xffe36b, 1.6, 5);
projectile.add(projectileLight);
function makeLandingMarker(color) {
const group = new THREE.Group();
const solid = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.65,
roughness: 0.45
});
const beam = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.24,
depthWrite: false
});
const plate = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 0.08, 1.35),
solid
);
plate.position.y = 0.04;
plate.receiveShadow = true;
group.add(plate);
const center = new THREE.Mesh(
new THREE.BoxGeometry(0.38, 0.34, 0.38),
solid
);
center.position.y = 0.2;
center.castShadow = true;
group.add(center);
const beacon = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 2.5, 0.08),
beam
);
beacon.position.y = 1.3;
group.add(beacon);
for (const x of [-0.58, 0.58]) {
for (const z of [-0.58, 0.58]) {
const corner = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.2, 0.18),
solid
);
corner.position.set(x, 0.14, z);
group.add(corner);
}
}
scene.add(group);
return group;
}
const currentMarker = makeLandingMarker(0x22d3ee);
const referenceMarker = makeLandingMarker(0xfb923c);
function makeTrajectory() {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.94
});
const mesh = new THREE.InstancedMesh(geometry, material, 96);
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
mesh.frustumCulled = false;
scene.add(mesh);
return mesh;
}
const currentPath = makeTrajectory();
const referencePath = makeTrajectory();
function updatePath(mesh, model, sampleCount, cubeSize, startColor, endColor) {
const transform = new THREE.Object3D();
const color = new THREE.Color();
const start = new THREE.Color(startColor);
const end = new THREE.Color(endColor);
mesh.count = sampleCount;
for (let i = 0; i < sampleCount; i++) {
const t = i / (sampleCount - 1);
const time = t * model.flightTime;
const x = model.vx * time * METERS_PER_UNIT;
const y = (
LAUNCH_HEIGHT +
model.vy * time -
0.5 * GRAVITY * time * time
) * METERS_PER_UNIT;
transform.position.set(x, Math.max(0, y), 0);
transform.rotation.set(0, 0, 0);
transform.scale.setScalar(cubeSize * (1 - 0.16 * t));
transform.updateMatrix();
mesh.setMatrixAt(i, transform.matrix);
color.copy(start).lerp(end, t);
mesh.setColorAt(i, color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
}
// ---------------------------------------------------------------------
// Ballistic calculations
// ---------------------------------------------------------------------
function ballistic(speed, angleDegrees) {
const angle = angleDegrees * Math.PI / 180;
const vx = speed * Math.cos(angle);
const vy = speed * Math.sin(angle);
// Positive root of:
// LAUNCH_HEIGHT + vy*t - 0.5*g*t² = 0
const flightTime = (
vy + Math.sqrt(vy * vy + 2 * GRAVITY * LAUNCH_HEIGHT)
) / GRAVITY;
const peakHeight =
LAUNCH_HEIGHT + (vy * vy) / (2 * GRAVITY);
const range = vx * flightTime;
return {
speed,
angle: angleDegrees,
vx,
vy,
flightTime,
peakHeight,
range
};
}
let currentModel = ballistic(state.speed, state.angle);
let referenceModel = ballistic(
state.referenceSpeed,
state.referenceAngle
);
function formatRange(value) {
return `${value.toFixed(1)} m`;
}
function formatHeight(value) {
return `${value.toFixed(1)} m`;
}
function formatTime(value) {
return `${value.toFixed(2)} s`;
}
function setSliderFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percent}%`);
}
function updateComparison() {
ui.currentRange.textContent = formatRange(currentModel.range);
ui.referenceRange.textContent = formatRange(referenceModel.range);
ui.currentHeight.textContent = formatHeight(currentModel.peakHeight);
ui.referenceHeight.textContent = formatHeight(referenceModel.peakHeight);
ui.currentTime.textContent = formatTime(currentModel.flightTime);
ui.referenceTime.textContent = formatTime(referenceModel.flightTime);
const difference = currentModel.range - referenceModel.range;
const sign = difference >= 0 ? "+" : "−";
ui.delta.textContent = `${sign}${Math.abs(difference).toFixed(1)} m`;
ui.currentLabel.querySelector("span").textContent =
formatRange(currentModel.range);
ui.referenceLabel.querySelector("span").textContent =
formatRange(referenceModel.range);
}
function updateCurrentModel(resetShot = true) {
currentModel = ballistic(state.speed, state.angle);
updatePath(
currentPath,
currentModel,
82,
0.30,
0x22d3ee,
0xa5f3fc
);
currentMarker.position.x =
currentModel.range * METERS_PER_UNIT;
ui.speedOut.textContent = `${state.speed} m/s`;
ui.angleOut.textContent = `${state.angle}°`;
setSliderFill(ui.speed);
setSliderFill(ui.angle);
updateComparison();
if (resetShot) resetProjectile();
}
function updateReferenceModel() {
referenceModel = ballistic(
state.referenceSpeed,
state.referenceAngle
);
updatePath(
referencePath,
referenceModel,
48,
0.34,
0xfb923c,
0xfdba74
);
referenceMarker.position.x =
referenceModel.range * METERS_PER_UNIT;
updateComparison();
}
// ---------------------------------------------------------------------
// Shot state and impact particles
// ---------------------------------------------------------------------
function setStatus(text, type) {
ui.status.textContent = text;
ui.status.dataset.state = type;
}
function clearImpactParticles() {
for (const particle of impactParticles) {
scene.remove(particle.mesh);
}
impactParticles.length = 0;
}
function resetProjectile() {
state.elapsed = 0;
state.playing = false;
state.landed = false;
projectile.position.set(
0,
LAUNCH_HEIGHT * METERS_PER_UNIT,
0
);
projectile.rotation.set(0, 0, 0);
ui.fire.textContent = "FIRE";
setStatus("READY", "ready");
clearImpactParticles();
}
function spawnImpactParticles(x) {
clearImpactParticles();
for (let i = 0; i < 16; i++) {
const mesh = new THREE.Mesh(
impactParticleGeometry,
impactParticleMaterial
);
const angle = (i / 16) * Math.PI * 2;
const speed = 2.2 + (i % 4) * 0.45;
mesh.position.set(x, 0.16, 0);
mesh.scale.setScalar(0.12 + (i % 3) * 0.035);
scene.add(mesh);
impactParticles.push({
mesh,
velocity: new THREE.Vector3(
Math.cos(angle) * speed,
2.2 + (i % 5) * 0.32,
Math.sin(angle) * speed
),
life: 0.85
});
}
}
const impactParticleGeometry = new THREE.BoxGeometry(1, 1, 1);
const impactParticleMaterial = new THREE.MeshBasicMaterial({
color: 0x67e8f9
});
const impactParticles = [];
function updateProjectile(time) {
const x = currentModel.vx * time * METERS_PER_UNIT;
const y = (
LAUNCH_HEIGHT +
currentModel.vy * time -
0.5 * GRAVITY * time * time
) * METERS_PER_UNIT;
projectile.position.set(x, Math.max(0, y), 0);
projectile.rotation.x = time * 1.25;
projectile.rotation.y = time * 1.85;
}
ui.speed.addEventListener("input", () => {
state.speed = Number(ui.speed.value);
updateCurrentModel(true);
});
ui.angle.addEventListener("input", () => {
state.angle = Number(ui.angle.value);
updateCurrentModel(true);
});
ui.fire.addEventListener("click", () => {
if (state.playing) {
state.playing = false;
ui.fire.textContent = "RESUME";
setStatus("PAUSED", "paused");
return;
}
if (state.elapsed >= currentModel.flightTime - 0.001) {
state.elapsed = 0;
state.landed = false;
clearImpactParticles();
}
state.playing = true;
ui.fire.textContent = "PAUSE";
setStatus("IN FLIGHT", "flight");
});
ui.reference.addEventListener("click", () => {
state.referenceSpeed = state.speed;
state.referenceAngle = state.angle;
updateReferenceModel();
setStatus("REFERENCE SAVED", "ready");
});
ui.reset.addEventListener("click", resetProjectile);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
ui.fire.click();
}
if (event.key.toLowerCase() === "r") {
resetProjectile();
}
});
// ---------------------------------------------------------------------
// Voxel clouds
// ---------------------------------------------------------------------
const clouds = [];
const cloudGeometry = new THREE.BoxGeometry(1, 1, 1);
const cloudMaterial = new THREE.MeshBasicMaterial({
color: 0xb9dcf1,
transparent: true,
opacity: 0.08,
depthWrite: false
});
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
const pieces = [
[-1.0, 0.0, 0, 1.6, 0.65, 0.8],
[0.0, 0.15, 0, 2.0, 0.9, 1.0],
[1.4, 0.0, 0, 1.4, 0.6, 0.8],
[0.5, 0.65, 0, 1.2, 0.6, 0.8]
];
for (const [px, py, pz, sx, sy, sz] of pieces) {
const piece = new THREE.Mesh(cloudGeometry, cloudMaterial);
piece.position.set(px, py, pz);
piece.scale.set(sx, sy, sz);
cloud.add(piece);
}
cloud.scale.setScalar(scale);
cloud.userData.speed = 0.25 + scale * 0.12;
clouds.push(cloud);
scene.add(cloud);
}
addCloud(8, 15, -17, 1.25);
addCloud(30, 19, -19, 1.7);
addCloud(57, 14, -15, 1.0);
addCloud(72, 22, -20, 1.4);
// ---------------------------------------------------------------------
// Direct camera controls: no addon imports
// ---------------------------------------------------------------------
function updateCamera() {
const radius = 100;
camera.position.set(
cameraTarget.x +
radius * Math.sin(state.polar) * Math.sin(state.azimuth),
cameraTarget.y + radius * Math.cos(state.polar),
cameraTarget.z +
radius * Math.sin(state.polar) * Math.cos(state.azimuth)
);
camera.lookAt(cameraTarget);
camera.zoom = state.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
// Keep the full range visible on both wide and narrow screens.
const viewHeight = Math.max(52, 82 / aspect);
camera.left = -viewHeight * aspect * 0.5;
camera.right = viewHeight * aspect * 0.5;
camera.top = viewHeight * 0.5;
camera.bottom = -viewHeight * 0.5;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
state.azimuth -= deltaX * 0.005;
state.polar = clamp(
state.polar - deltaY * 0.005,
0.55,
1.42
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.zoom = clamp(
state.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
state.azimuth = -0.48;
state.polar = 1.08;
state.zoom = 1;
updateCamera();
});
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Screen-space labels for landing positions
// ---------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.playing) {
state.elapsed += delta;
if (state.elapsed >= currentModel.flightTime) {
state.elapsed = currentModel.flightTime;
state.playing = false;
state.landed = true;
ui.fire.textContent = "REPLAY";
setStatus("LANDED", "ready");
spawnImpactParticles(
currentModel.range * METERS_PER_UNIT
);
}
updateProjectile(state.elapsed);
}
for (const cloud of clouds) {
cloud.position.x += cloud.userData.speed * delta;
if (cloud.position.x > 85) {
cloud.position.x = -18;
}
}
for (let i = impactParticles.length - 1; i >= 0; i--) {
const particle = impactParticles[i];
particle.life -= delta;
particle.velocity.y -= 7.5 * delta;
particle.mesh.position.addScaledVector(
particle.velocity,
delta
);
particle.mesh.rotation.x += delta * 4;
particle.mesh.rotation.y += delta * 3;
if (particle.life <= 0) {
scene.remove(particle.mesh);
impactParticles.splice(i, 1);
}
}
if (state.landed) {
currentMarker.scale.lerp(
new THREE.Vector3(1, 1, 1),
1 - Math.exp(-delta * 8)
);
}
renderer.render(scene, camera);
placeLabel(
ui.currentLabel,
new THREE.Vector3(
currentModel.range * METERS_PER_UNIT,
2.7,
0
)
);
placeLabel(
ui.referenceLabel,
new THREE.Vector3(
referenceModel.range * METERS_PER_UNIT,
2.45,
0
)
);
placeLabel(
ui.launchLabel,
new THREE.Vector3(0, 2.5, 0)
);
requestAnimationFrame(animate);
}
// ---------------------------------------------------------------------
// Initialization
// ---------------------------------------------------------------------
resize();
updateCurrentModel(false);
updateReferenceModel();
updateProjectile(0);
ui.fire.textContent = "PAUSE";
setStatus("IN FLIGHT", "flight");
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
ui.loading.classList.add("hidden");
});
</script>
</body>
</html>
```