[Closed] ray between to nodes
Hi MaxScripters,
I need to create a ray from my camera to a node in the scene, but I cant find a way to go about it.
Does anyone know how to do this?
Thanks
theCamera = $Camera01
theObject = $Box02
theRay = theCamera.pos (normalize (theObject.pos-theCamera.pos))
assuming you are aiming at the pivot point of the object.
What do you need the ray for? Intersection test?
Bobo Thanks – it works like a charm.
I need the ray for the intersectRayScene function.
Im making some automatic hotspotgeneration for a objectVr viewer in flash, I previously made this one http://www.socosystem.com/Internet/Home/Popup/Virtual%20showroom%202008.aspx and here i handanimated all the hotspots (the small red dots) – wich was a bit teadious.
with the great help of this forum, the helpfiles and some luck I’ve put this code together:
screen_width=RenderWidth
screen_height=RenderHeight
back_vfb = bitmap screen_width screen_height
front_vfb = bitmap screen_width screen_height
--Returns true if the bounding boxes of the two specified nodes overlap, or false if they do not overlap.
fn sortByHitDistance n1 n2 = if n1[3] < n2[3] then -1 else if n1[3] > n2[3] then 1 else 0
fn VertexRendererFunction =
(
thePos = ($Sphere01.pos)* viewport.getTM()
screen_origin = mapScreenToView [0,0] (thePos.z) [screen_width,screen_height]
end_screen = mapScreenToView [screen_width,screen_height] (thePos.z) [screen_width,screen_height]
world_size = screen_origin-end_screen
x_aspect = screen_width/(abs world_size.x)
y_aspect = screen_height/(abs world_size.y)
screen_coords = point2 ((x_aspect*(thePos.x-screen_origin.x))as integer) ((-(y_aspect*(thePos.y-screen_origin.y))) as integer)
--testray = $Camera01 as ray
--testray = $Tape01 as ray
testray = ray $Camera01.pos (normalize ($Sphere01.pos-$Camera01.pos))
intersectsArray = for n in (intersectRayScene testray) where not n[1].isHidden collect #(n[1], n[2], distance testray.pos n[2].pos)
qsort intersectsArray sortByHitDistance
if intersectsArray[1][1] != $Sphere01 then(
print (screen_coords as string + "_hidden")
)else(
print (screen_coords as string)
)
--print(screen_coords)
)--end fn
for i = 0 to 100 do(
sliderTime = i
VertexRendererFunction()
)
The code projects the position of the $Sphere01 to the $Camera01’s plane and prints them out – and adds _hidden to the coordinates if the sphere is hidden behind other geometry.
Afterwards I collect all the values in an xmlfile that I load into flash at runtime, here they are to be used to animate the hotspots – hope this makes sense, I think its very clever
–change A and B if U want to
A=$Camera01
B=$GeoSphere01
–create ray from A position with A to B direction
ray A.pos ((A.pos – B.pos )/ length (A.pos – B.pos))
–U can check it with tape create tape Tape01
Tape01.pos=$Camera01
Tape01.target.pos=$GeoSphere01
$ as ray