Question

I have a cuboid (THREE.CubeGeometry 1x1x10 for example). Here's what I'm trying to accomplish:

  1. Given some point, I want to place the cuboid some distance away from the origin, but along the line formed by the origin and said point

  2. Rotate the cuboid so it faces the origin

enter image description here

I'm tried using

obj.lookAt(new THREE.Vector3(0, 0, 0));

but that rotates the object in such a way that its side faces the origin, instead of its end.

As for the first step (finding a point along that line that is N units away from the origin), I don't even know where to start. What I did was normalize the vec with the point, which [I think] gets me, essentially, a line of length 1, from (0, 0, 0) pointing towards the point. To move that point to where I want (N distance from the origin), I can scale that vector accordingly. Not sure if that makes sense...


Edit

In answer to one of the comments saying how obj.lookAt() should work, here's what I'm getting, and what I'd like to have it do instead:

How the cuboid is being drawn after position is set to some point, then lookAt() invoked enter image description here

Note that the side of the object is looking at the origin (not what I want) enter image description here

What I'd like to do is have the object look at that point from its end (I guess I'm one rotation away from that, but that's one rotation I'm not sure how to calculate) enter image description here

Was it helpful?

Solution

When you call object.lookAt( 0, 0, 0 ), the object's local z-axis will point toward the origin.

So, if your cuboid is 1x1x10, with the long side parallel to the z-axis, you should get exactly the result you want.

three.js r.97

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top