var scene, renderer, camera, controls;
init();
animate();
function init()
{
renderer = new THREE.WebGLRenderer( {antialias:true} );
var width = window.innerWidth;
var height = window.innerHeight;
renderer.setSize (width, height);
document.body.appendChild (renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera (60, width/height, 0.01, 10000);
camera.position.y = 16;
camera.position.z = 40;
camera.lookAt (new THREE.Vector3(0,0,0));
scene.add( camera );
controls = new THREE.OrbitControls(camera, renderer.domElement);
var gridXZ = new THREE.GridHelper(100, 10,
new THREE.Color(0xffffff),
new THREE.Color(0xffffff)
);
scene.add(gridXZ);
var customPlane = createTestPlane();
var testPoint = new THREE.Vector3(60, 65, 0);
createRayCastFromCamera(testPoint);
}
function createRayCastFromCamera(testPoint){
// get the direction towards the point
var rayDirection = new THREE.Vector3();
rayDirection.subVectors(testPoint, camera.getWorldPosition());
rayDirection.normalize();
// create ray cast
raycaster = new THREE.Raycaster();
//cast a ray in the direction towards the point
raycaster.set( camera.getWorldPosition(), rayDirection);
// only used for when doing mouse clicking from camera
//raycaster.setFromCamera({x:15, y:15}, camera);
//camera.getWorldDirection()
console.log(raycaster.intersectObjects(scene.children, true));
// line visual helper to simulate the ray from camera to test point
var lineGeo = new THREE.Geometry();
lineGeo.vertices.push(camera.getWorldPosition().clone(), testPoint.clone());
var line = new THREE.Line(lineGeo, new THREE.LineBasicMaterial());
scene.add(line);
/*
raycaster.ray.direction.copy( direction ).applyEuler(rotation);
raycaster.ray.origin.copy( camera.position );
*/
}
function createTestPlane(){
var points = [
new THREE.Vector2(0,0),
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.