Monday, July 21, 2008
AE / closestpointOnLine
closestpointOnLine(ラインのポイント1,ラインのポイント2,ドラッグするオブジェクトのロケーション)
closestpointOnLine(tLoc1,tLoc2,tLoc3)
ドラッグするオブジェクト(サンプルではグリーンの円)のロケーションのポイントから、2点間の直線が常に直角になる線上のポイント(ロケーション)を返します。
直線「tLine」、直線の左右の円「point1」「point2」、直線上の円(ブルー)「pointIndicator」、ドラッグで移動する円(グリーン)「dragCircle」とします。
AE / constrainrectangular
始めにメッセージボックスから「 constrainrectangular」を設定します。
set the constrainrectangular of grc "point1" to the rect of this card
set the constrainrectangular of grc "point2" to the rect of this card
set the constrainrectangular of grc "dragCircle" to the rect of this card
「 constrainrectangular」は、カスタムプロパティにそのオブジェクトが、マウスダウンでドラックできる「uAllowConstrainDrag」を作り、ドラッグできるthe rect の範囲をカスタムプロパティ「 constrainrectangular」で設定します。オブジェクト内には「grab me」は必要ありません。
-- 直線の両端のオブジェクトには
on constrainRectangularCallback
put the loc of grc "point1" into tLoc1
put the loc of grc "point2" into tLoc2
put the loc of grc "dragCircle" into tLoc3
set the points of grc "tLine" to tLoc1 & cr & tLoc2
set the loc of grc "pointIndicator" to closestpointOnLine(tLoc1,tLoc2,tLoc3)
end constrainRectangularCallback
-- ドラッグするオブジェクトには
on constrainRectangularCallback
put the loc of grc "point1" into tLoc1
put the loc of grc "point2" into tLoc2
put the loc of grc "dragCircle" into tLoc3
set the loc of grc "pointIndicator" to closestpointOnLine(tLoc1,tLoc2,tLoc3)
end constrainRectangularCallback
始めにAnimation Engineを開いて、start using stack "animationEngine"
サンプルスタックは、下記をメッセージボックスにコピペしてリターンキーを
go stack url "http://homepage.mac.com/kenjikojima/jrevnote/closestPointOnLine.rev"