ScriptSpot

Forum topic · Scripts Wanted

Distance Between Two Objects (Automate Camera's Focal Point)

By JokerMartini · 2011-02-09

Description

I would like a way to find the distance between two objects. What is the best way to go about doing this through maxscript?
Using the measuring tool, getting the distance value between the two objects and then deleting it?

Thoughts.

Thanks.

Comments (2)

Help

JokerMartini · 2011-02-09

Maybe you could help me on this. It doesn't work entirely correctly but I feel that it is going in the right direction. It is for animating the Camera's Focal point. It seems to bug out when obj is not directly in front of the camera.


rollout rlCameraFocus "Camera Focus"
(
local FocusObj
local RendCam

fn ObjFilter obj =
(
superclassof obj != Camera --Helpers
)

fn camFilter obj =
(
superclassof obj == Camera --Cameras
)

groupbox gobxFocusObj "Focus Object" width:140 height:52 pos:[5,2]
pickbutton pkbtnFocusObj "Pick Object" width:120 height:24 pos:[15,20] filter:ObjFilter

groupbox gobxCamera "Camera" width:140 height:52 pos:[5,60]
pickbutton pkbtnCamera "Pick Camera" width:120 height:24 pos:[15,80] filter:camFilter

button btnMakeInFocus "Make In Focus" width:140 height:24 pos:[5,120]

on pkbtnCamera picked obj do
(
RendCam = obj
pkbtnCamera.text = RendCam.name
)

on pkbtnFocusObj picked obj do
(
FocusObj = obj
pkbtnFocusObj.text = FocusObj.name
)

-- Calculation
on btnMakeInFocus pressed do
(
fromHere = RendCam
toThere = FocusObj
FocVal = (distance fromHere toThere)
print FocVal
RendCam.baseObject.targetDistance = FocVal
)

)
createDialog rlCameraFocus 150 150

"distance"

br0t · 2011-02-09

Theres an existing command:


fromHere = $Teapot001
toThere = $Teapot002

distance fromHere toThere

Cheers