PDA

View Full Version : intersectRay () on a surface


wamo
04-03-2008, 05:29 AM
hello ,
is there someone who can help me on it?
it's about intersectRay ()

http://forums.cgsociety.org/showthread.php?f=98&t=616202

S-S
04-03-2008, 12:11 PM
This is cleary a maxscript issue, you should ask it in proper forum. But

aRay = ray $Teapot01.position -$Teapot01.dir

aHitLoc = intersectRay $plane01 aRay

$Box01.position = aHitLoc.pos

Gives you a ray which shoots from the bottom of a teapot to a plane, an moves a box to that location. I think jason and others exlained quite clearly, are you sure you are not shooting rays into wrong direction? (I'm using negative of teapots direction, which means ray is going down along teapot's local z.

wamo
04-04-2008, 06:38 AM
hi S-S,
i understood them and also what you said and i knew this stuffs ,
if you could understand me very well,then you will solve my problem,
the problem is :
the intersection works well,also direction is ok,
but when it goes to undefined area it shows an error,
that says ("pos" in undefined)
Jason said you use an IF statment
(if thehit != undefined then thehit.pos.z
else 0)
but it still dont solve the problem.

S-S
04-04-2008, 07:20 AM
I get what you are after. Maybe you can just give your object or variable some empty value. For example, if you were to move car tire to touch ground, when you don't find ground under wheel then, you would assign position value [0,0,0] to tire (so it would be on it's original position).

aRay = ray $Teapot01.position -$Teapot01.dir

aHitLoc = intersectRay $plane01 aRay

if aHitLoc == undefined then $Box01.position = [0,0,0] else
$Box01.position = aHitLoc.pos

wamo
04-04-2008, 07:35 AM
i got the answer,
the problem was:

if thehit != undefined do
(
thehit.pos.z
)
else 0

sorry i forgotten to put those paranteces.:thumbsup:

labbejason
04-04-2008, 07:37 AM
So here's what you had in your file:


dependson $point01 $plane01
aRay = ray $Point01.position -$Point01.dir
aHitLoc = intersectRay $plane01 aRay
if aHitloc.pos.z != undefined then aHitloc.pos.z
else 0


As soon as the ray can't find the plane, and a hit doesn't occur this is what happens.
ARay doesn't intersect with plane01, so all it returns is undefined. The problem is that you are trying to see if pos.z from the intersection is defined, which means you are basically doing this:

undefined.pos.z

Undefined doesn't have those properties, which will cause it to crash. Instead, you just need to see if aHitLoc itself returns undefined or not (undefined meaning no intersection), which will be:


dependson $point01 $plane01
aRay = ray $Point01.position -$Point01.dir
aHitLoc = intersectRay $plane01 aRay
if aHitloc != undefined then aHitloc.pos.z
else 0

labbejason
04-04-2008, 07:39 AM
hmmmm I replied to late :D


if thehit != undefined do
(
thehit.pos.z
)
else 0


Should be a 'then' statement if you're using else, not do.

wamo
04-04-2008, 10:33 AM
thank you Jason and S-S and Lan
yeah it was a simple stuff to solve your helps are perfect,i did them,
those comments work well :).
the new code is here:

val = 0
mypos = myself.pos
myray = ray (mypos+[0,0,10000]) [0,0,-1]
theintersect = intersectray theland myray
if theintersect != undefined do
(
val = (theintersect.pos).z - mypos.z
)
val

cheers,
Ehsan.

CGTalk Moderation
04-04-2008, 10:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.