How to rotate geometry to face the camera?

Software: Away3D 4.x

jhocking, Newbie
Posted: 24 October 2011 08:07 PM   Total Posts: 12

As explained in this other thread, I’m currently trying to do laser beams in Away3D:
http://away3d.com/forum/viewthread/1155/

I know the way most 3D games do laser beams is with a texture on a quad, stretch the quad from shooter to target, and rotate the quad to face the camera.

I also know that Away3D has the Sprite3D entity for doing quads that face the camera. The thing is, Sprite3D always faces the camera completely, but for a laser beam I would want it to only rotate on one axis. That is, the laser would roll to face the camera, but the pitch and yaw would be independent of the camera.

How would I roll the quad to face the camera in this way? I’m assuming I’d do a little vector math using the orientation of the camera and of the quad, but I don’t know what exactly to calculate.

Alternatively, where is the code to face Sprite3D toward the camera? I want to look at the math there to figure out what I need, but I can’t tell where that code is. When I look in Sprite3D.as I don’t see anything that looks promising.

—-

Incidentally, does Sprite3D already have this functionality? While it seems to always rotate on all axes, and I need a quad that rotates only on one axis, perhaps I just missed in the documentation how to restrict Sprite3D to only rotating on the Y axis or something.

   

luddet, Newbie
Posted: 24 October 2011 09:11 PM   Total Posts: 4   [ # 1 ]

I suppose you could use the lookAt function in Object3D. Set it to look at a Vector3D containing only the parts of the camera.position you like.

Something like:
var pos:Vector3D = new Vector3D(0, camera.position.y, 0);
laser.lookAt(pos);

   

jhocking, Newbie
Posted: 24 October 2011 09:25 PM   Total Posts: 12   [ # 2 ]

hm I don’t think I can directly use lookAt for my purposes (I don’t think you can simply use camera.position.y like that) but I can look in there to see how it does the math. That might help.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X