简体   繁体   中英

Using Three.js how can I move an object along a specified plane?

I'm looking at the example on http://threejs.org site ( http://threejs.org/examples/webgl_interactive_draggablecubes.html ) and I see they are moving the selected cube along a plane relative to the camera. I get how the unprojection works with raycaster. What I don't get is how to set this up to always move the object along the ground (plane) even if the camera is at an angle. The idea is to have the user use a the mouse to move the object along the ground even if the camera is at an angle and is NOT looking perfectly down at it. I'm new to using Three.js so you might want to be verbose in explaining what I'm missing. Or maybe ask questions back if I didn't explain myself.

My project looks like this and I'm looking to move the boxes around with a mouse.

在此处输入图片说明

The example code creates a plane and updates it in the MouseMove event whenever the camera angle changes:

plane.setFromNormalAndCoplanarPoint(camera.getWorldDirection(plane.normal), INTERSECTED.position);

Instead of doing that, create the plane as

var plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);

which is the XZ plane at the origin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM