[VarDef,docWidth,[iGet,document:modifiers:width]]
[VarDef,docHeight,[iGet,document:modifiers:height]]
[VarDef,Xangle,0][VarDef,Yangle,0]
[VarDef,curmX][VarDef,curmY][VarDef,curmZ]
[VarDef,newmX][VarDef,newmY][VarDef,newmZ]

[iSlider,"X Center",docWidth/2,.1,-4096,4096,"X Component",,,120]
[iSlider,"Y Center",docHeight/2,.1,-4096,4096,"Y Component",,,120]
[iSlider,"Z Center",0,.1,-4096,4096,"Z Component",,,120]
[iButton,"Use Current","Put current object's position into these sliders",
	[transformGet,curmX,curmY,curmZ]
	[iSet,-3,curmX]
	[iSet,-2,curmY]
	[iSet,zscript:zcenter,curmZ]
,,100] // end iButton

[sectionBegin,"?",0,"Help",
[Note,,-4,-1][Note,,-3,-1][Note,"Use these sliders to set an X, Y, and Z position in space...",-2,-1][Note,"\n\n(Click to continue)"]
[Note,"To set them automatically, draw an object where you'd like other objects to point to, and press this button...",-1,-1][Note,"\n\n(Click to continue)"]
[Note,"To point an object toward the position you've set, draw it and press this large red button.",1,-1][Note,"\n\n(Click to finish)"]
[iUnpress,0]][sectionEnd]

[pd]
[iButton,"Point to this location","Point current 3D object toward the center indicated above",
	[if,[isDisabled,transform:move],
		[messageOK,"Most recently-drawn item must be a 3D object in a Transform or Edit mode"]
	, // else
	[transformGet,curmX,curmY,curmZ,cursX,cursY,cursZ,currX,currY,currZ]
	[varSet,newmX,[iGet,zscript:xcenter]]
	[varSet,newmY,[iGet,zscript:ycenter]]
	[varSet,newmZ,[iGet,zscript:zcenter]]
	[routineCall,PointFromTo,curmX,curmY,curmZ,newmX,newmY,newmZ,Xangle,Yangle]
	[transformSet,curmX,curmY,curmZ,cursX,cursY,cursZ,Xangle,Yangle,currZ]
	]
,,460] // end iButton

[pd]
[pd]
[PenMove,50][ibutton,"Return to Menu","Load the Script Selection Interface",[fileNameSetNext,"DefaultZScript.txt"][iPress,7427]]

[routineDef,PointFromTo,
[varSet,deltaX,lnewmX-lcurmX]
[varSet,deltaY,lnewmY-lcurmY]
[varSet,deltaZ,lnewmZ-lcurmZ]
[varSet,Rxz,sqrt((deltaX^^2)+(deltaZ^^2))]
[if,Rxz=0,
	[varSet,lXangle,(abs(deltaY)/deltaY)*-90]
	[varSet,lYangle,0]
, // else Rxz != 0
	[if,deltaZ=0,
		[varSet,deltaZ,-0.01]
	] // end if
	[varSet,lXangle,-atan(deltaY/Rxz)]
	[varSet,lYangle,-atan(deltaX/deltaZ)]
	[if,deltaZ > 0,[varSet,lYangle,-180+lYangle]]
] // end if
,lcurmX,lcurmY,lcurmZ,lnewmX,lnewmY,lnewmZ,lXangle,lYangle
] // end pointfromto routine
