Skip to content
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

Ray casting not working #1325

Closed
lukebitts opened this issue Feb 14, 2012 · 7 comments
Closed

Ray casting not working #1325

lukebitts opened this issue Feb 14, 2012 · 7 comments
Labels

Comments

@lukebitts
Copy link

var geometry = new THREE.CubeGeometry( 30, 30, 30 );
var object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial({color:0x0000ff}) );
object.position.x = 0;
object.position.y = 200;
object.position.z = 0;

ray = new THREE.Ray(new THREE.Vector3(-500,210,0),new THREE.Vector3(500,210,0));
var c = ray.intersectObject( object );

am I forgetting something here? Because c is always empty but I don't see anything being done differently in the ray examples.

@mrdoob
Copy link
Owner

mrdoob commented Feb 14, 2012

Could you do a jsfiddle of it?

@lukebitts
Copy link
Author

@alteredq
Copy link
Contributor

There is a known bug about non-planar quads, but CubeGeometry should be fine.

We should have some helper for Ray. Whenever issue like this pops up, I can never tell if there is a bug in Ray or just Ray is pointing somewhere to empty space (bear in mind second argument is direction vector, not end point of line starting in origin).

@mrdoob
Copy link
Owner

mrdoob commented Feb 14, 2012

We should have some helper for Ray. Whenever issue like this pops up, I can never tell if there is a bug in Ray or just Ray is pointing somewhere to empty space (bear in mind second argument is direction vector, not end point of line starting in origin).

Indeed. Will work on that.

@WestLangley
Copy link
Collaborator

You need to call object.updateMatrixWorld() or render() prior to your call to ray.intersectObjects(). Also, as @alteredq pointed out, the second argument in the Ray constructor must be a direction vector -- of unit length.

@mrdoob
Copy link
Owner

mrdoob commented Feb 15, 2012

@WestLangley well spotted!

Here's the fixed jsfiddle.

@mrdoob mrdoob closed this as completed Feb 15, 2012
@lukebitts
Copy link
Author

Thanks everyone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants