New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get 3d coordinates from 2d point #312
Labels
Comments
Never mind found it |
How did you end up doing it? |
I'm having this problem myself. I'm not even get a hit from the collider. How did you solve it? |
@inear: did you try with the |
Thanks! That works like a charm. The point-property is just what I needed. var vector = mouse2D;
projector.unprojectVector( vector, camera );
var r = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize());
var c = r.intersectObject(wave)
if( c.length > 0 ) {
sphere.position = c[0].point;
} |
var getZvalue = function (e)
{
var rect = e.target.getBoundingClientRect();
// 2D
var mouseX = e.clientX - rect.left;
var mouseY = e.clientY - rect.top;
// 3D
SCREEN_WIDTH = window.innerWidth;
SCREEN_HEIGHT= window.innerHeight;
var mouse = new THREE.Vector2();
mouse.x = (mouseX/SCREEN_WIDTH) *2 - 1;
mouse.y = -(mouseY/SCREEN_HEIGHT) *2 + 1;
// Raycaster
if (TerraDroneViewer.raycaster == null)
{
TerraDroneViewer.raycaster = new THREE.Raycaster();
}
TerraDroneViewer.raycaster.setFromCamera( mouse, TerraDroneViewer.camera );
var intersects = TerraDroneViewer.raycaster.intersectObjects( TerraDroneViewer.maps.children );
console.log("raycast=" + intersects.length);
if (intersects.length != 0)
{
var x = mouse.x * 10;
var y = mouse.y * 10;
console.log("x = " + intersects[0].point.x + " y = " + intersects[0].point.y);
var z = parseFloat(intersects[0].point.z) * 10;
return {
x: x,
y: y,
z: z
}
}
return null;
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi guys
I would like to know how can i get the 3d coordinates from a collision point mouse 2d
from this code
The collision object is a plane which i use as ground and i want to know the collision point 3d coords in order to set an object's position.
Thanks in advance
The text was updated successfully, but these errors were encountered: