Sample for eyes that follow the mouse


[ Zettels Traum ] [ search / suche ]

von dp am 18.Februar 97 um 12:39:53:

zu: Perlen aus dem Strom der Nachrichten im direct_L von Daniel am 22.Dezember 96 um 02:00:59:

>Does anyone have code for Director movie, or a pointer to one, for a set
>of eyes that follow the cursor around the screen. I've seen an example
>on the web (shockwave) and have seen a number of java versions at
>Gamelan, but no Director source...(ok, I'm lazy, I want to use the
>algorithm in something and would rather not mess with coding and
>debugging it from scratch). Thanks, Andy
>.-

Well I don't have the movie, but here are the two handlers that do the
trick. I apologize for having lost the name of the person who was so
creative and generous. I don't believe it was copyrighted or else I would
have defniitely kept the name.

(The movie may reside at Marvyn's Shared Cast ftp.)

on updateMouseMap
set the locH of sprite 2 = the left of sprite 1 + the mouseH / 10
set the locV of sprite 2 = the top of sprite 1 + the mouseV / 10
put the mouseH &", "& the mouseV into field "mouseLoc"
end

on initEyes
global Eye_LeftOrg, Eye_RightOrg, Eye_Radius
set the puppet of sprite 3 = true -- left pupil
set the puppet of sprite 4 = true -- right pupil
set Eye_LeftOrg = the loc of sprite 1 -- bitmap reg point
set Eye_RightOrg = the loc of sprite 2
-- alternative dray center (not used here)
-- set Eye_LeftOrg = the loc of sprite 1 + ¬
point( (the width of sprite 1) / 2, (the height of sprite 1) / 2 ) --
draw obj, center
-- set Eye_RightOrg = the loc of sprite 2 + ¬
point( (the width of sprite 2) / 2, (the height of sprite 2) / 2 ) --
draw obj, center
-- redius less pupel radius. for precision: may need multiple of 2 diameter
set Eye_Radius = (the width of sprite 1 / 2 - the width of sprite 3 / 2 )
end

on UpdateEye
global Eye_LeftOrg, Eye_RightOrg, Eye_Radius
-- move left eye
set mH = mouseH() -- freeze snapshot
set mV = mouseV()
set DeltaH = mH - the locH of Eye_LeftOrg
set DeltaV = mV - the locV of Eye_LeftOrg
set Delta = sqrt(DeltaH * DeltaH + DeltaV * deltaV)
set Scale = 0.0 + Delta / (Eye_Radius + 0.0)
if scale < 1 then -- mouse in eye
set the loc of sprite 3 = point(mH,mV)
else -- mouse outsize
set the locH of sprite 3 = the locH of Eye_LeftOrg + DeltaH / Scale
set the locV of sprite 3 = the locV of Eye_LeftOrg + DeltaV / Scale
end if
-- move right eye
set DeltaH = mH - the locH of Eye_RightOrg
set DeltaV = mV - the locV of Eye_RightOrg
set Delta = sqrt(DeltaH * DeltaH + DeltaV * deltaV)
set Scale = 0.0 + Delta / (Eye_Radius + 0.0)
-- put "Delta, scale="& delta &", "& scale --$$$
if scale < 1 then -- mouse in eye
set the loc of sprite 4 = point(mH,mV)
else -- mouse outsize
set the locH of sprite 4 = the locH of Eye_RightOrg + DeltaH / Scale
set the locV of sprite 4 = the locV of Eye_RightOrg + DeltaV / Scale
end if
put "H="& the mouseH &return& "V="& the mouseV into field "mouseLoc" --
show mouseLoc
end


Of course, there is always more than one way to do it in Director. (THere's
a bumper sticker in this "Lingoists do it more than one way.) Long time
Direct-Ler Bosaiya also posted a solution sometime late in this millenium.

Michael B.



Dazu:























D. Plänitz