Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

MAXScript: create ray / intersectRayScene - what am I doing wrong ?
show user profile  FreekOne
Hi guys,

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 =

-- Method 1 - use the camera and camera target's positions to create the ray
my_ray_1 = ray my_pos my_dir
intersectRayScene my_ray_1
-- returns #()

-- Method 2 - create a ray from a targeted object
my_ray_2 = my_obj as ray
intersectRayScene my_ray_2
-- 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)
show user profile  Garp
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 -

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)
show user profile  FreekOne
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 !

Thanks :D
read 1560 times
11/15/2011 8:08:56 PM (last edit: 11/15/2011 8:08:56 PM)
#Maxforums IRC
Open chat window