Maxunderground news unavailable
|MAXScript: create ray / intersectRayScene - what am I doing wrong ?|
I have this very simple scene consisting of a targeted camera (camera @ [0, -100, 50], target @ [0, 50, 0]) and a box (25x25x60cm @ [0, 0, -30]). The active viewport's view is set to the camera and I'm using the following script to create a ray from the camera to the camera target and check it if intersects the box (it is, or rather ... it should):
my_obj = getActiveCamera()
my_pos = my_obj.pos
my_dir = my_obj.target.pos
-- Method 1 - use the camera and camera target's positions to create the ray
my_ray_1 = ray my_pos my_dir
-- returns #()
-- Method 2 - create a ray from a targeted object
my_ray_2 = my_obj as ray
-- returns #($Box:Box1 @ [0.000000,0.000000,-11.811024], (ray [0,-4.92126,8.2021] [0,-1,0]))
I don't understand why method 1 fails where method 2 works, since they both use the exact same points to create the ray. My question is - what am I doing wrong and how can I get method 1 to work ?
Any help would be greatly appreciated !
read 1586 times
11/15/2011 5:42:31 PM (last edit: 11/15/2011 5:49:06 PM)
In method 1, my_dir is not the direction but the target's position. It would be correct only if the camera's position (my_pos) were [0, 0, 0].
The direction vector is: (target's position) - (camera's position).
my_ray1 = my_obj.pos - my_obj.target.pos
This is what building the ray from the camera does (my_ray2 = my_obj as ray).
edit: a better alternative would be my_ray = ray my_obj.pos -my_obj.dir
This will work with both a target camera and a free camera.
read 1564 times
11/15/2011 7:35:07 PM (last edit: 11/15/2011 8:00:19 PM)
Ah, makes perfect sense. Somehow I had a feeling you'd be the one answering this, and sure enough you save my ass once again :D
You sir are a gentleman and a scholar !
read 1560 times
11/15/2011 8:08:56 PM (last edit: 11/15/2011 8:08:56 PM)