var camera, scene, renderer, controls;
var h, L0, v0, theta;
var clock;
var pos, vel, force, start;
var increaseV0 = false;
var shootStart = false;
init();
animate();
$('#reset').click (function() {
pos.set (-L0, h, 0)
start.position.copy (pos)
shootStart = false
})
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 500;
let gridXZ = new THREE.GridHelper(200, 20, 'red', 'white');
scene.add(gridXZ);
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x888888);
controls = new THREE.OrbitControls(camera, renderer.domElement);
document.body.appendChild(renderer.domElement);
///////////////////////////////////////////////////////////
h = 10;
L0 = 20;
v0 = 25;
g = 10;
theta = Math.PI/6; // 30 deg
let line = makeParabola();
scene.add (line)
let normalMat = new THREE.MeshNormalMaterial();
start = new THREE.Mesh(new THREE.SphereGeometry(2,20,20), normalMat );
scene.add(start);
start.position.set (-L0, h, 0)
/////////////////
clock = new THREE.Clock();
pos = new THREE.Vector3();
vel = new THREE.Vector3();
force = new THREE.Vector3(0,-g,0);
/////////////////
document.addEventListener('mousedown', onMouseDown, false);
document.addEventListener('mouseup', onMouseUp, false);
}
function onMouseDown() {
v0 = 5
increaseV0 = true
}
function onMouseUp() {
increaseV0 = false;
shootStart = true;
pos.copy (start.position);
vel.set (v0*Math.cos(theta), v0*Math.sin(theta),0);
clock.getDelta(); // get the FIRST delta
}
function makeParabola() {
let tStar = ( v0*Math.sin(theta) + Math.sqrt(v0*v0*Math.sin(theta)*Math.sin(theta) + 2*g*h) )/g;
let N = 30;
let dt = tStar/N;
let geometry = new THREE.Geometry();
for (let t = 0; t <= tStar; t += dt) {
geometry.vertices.push (new...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.