//***************************************************// Digit's Widgets - A Zbrush Zscript
// Widgets_Common.txt
// Include File to hold all Common Variables and Subroutines
// Version 3.0 - 09/12/01 - Incorporated Digit_Widgets_Animation Script 
// Added recall of position mark Material, Color and Tool if the user isn't holding an object in transform
//	Version 3.1 - 09/15/01 - Updated with Advanced and Standard Animation Scripts
//***************************************************
//Document stuff
[VarSet,docWidth,DOCUMENT:MODIFIERS:WIDTH]
[VarSet,docHeight,DOCUMENT:MODIFIERS:HEIGHT]
[VarSet,docMidX,docWidth/2]
[VarSet,docMidY,docHeight/2]
//Widget's Stuff
[varDef,ICurrX,0]
[varDef,ICurrY,0]
[varDef,ICurrZ,0]
[varDef,ICurrXS,0]
[varDef,ICurrYS,0]
[varDef,ICurrZS,0]
[varDef,CurrXR,0]
[varDef,CurrYR,0]
[varDef,CurrZR,0]
//****************************
// Position Marker Definitions
//****************************
[VarDef,SpointX(2)]
[VarDef,SpointY(2)]
[VarDef,SpointZ(2)]
[VarDef,SpointXS(2)]
[VarDef,SpointYS(2)]
[VarDef,SpointZS(2)]
[VarDef,SpointXR(2)]
[VarDef,SpointYR(2)]
[VarDef,SpointZR(2)]
//****************************
//Keep Points
//****************************
[VarDef,KpointX(2)]
[VarDef,KpointY(2)]
[VarDef,KpointZ(2)]
[VarDef,KpointXS(2)]
[VarDef,KpointYS(2)]
[VarDef,KpointZS(2)]
[VarDef,KpointXR(2)]
[VarDef,KpointYR(2)]
[VarDef,KpointZR(2)]
[VarDef,sel1,1]
[VarDef,sel2,2]
//****************************
//Position Mark Common
//****************************
[VarDef,maxAvailablemarks,10] 
[VarDef,MarkTool(maxAvailablemarks+1),0]
[VarDef,MarkMat(maxAvailablemarks+1),0]
[VarDef,MarkR(maxAvailablemarks+1),0]
[VarDef,MarkG(maxAvailablemarks+1),0]
[VarDef,MarkB(maxAvailablemarks+1),0]
[varDef,MarkX(maxAvailablemarks+1)]  
[varDef,MarkY(maxAvailablemarks+1)]  
[varDef,MarkZ(maxAvailablemarks+1)]  
[varDef,MarkXS(maxAvailablemarks+1)]  
[varDef,MarkYS(maxAvailablemarks+1)]  
[varDef,MarkZS(maxAvailablemarks+1)]  
[varDef,MarkXR(maxAvailablemarks+1)]  
[varDef,MarkYR(maxAvailablemarks+1)]  
[varDef,MarkZR(maxAvailablemarks+1)]  
[varDef,MarkIndex,1]
//****************************
//Angle Common
//****************************
[VarDef,dangle,0]
[VarDef,dangle1,0]
[VarDef,zdangle,0]
[VarDef,zdangle1,0]
[VarDef,ZRead,0]
[VarDef,Gxyangle,0]
[VarDef,Gxzangle,0]
//[PenMove,0,2][Title,"      A Digit Widget      "]
//[Image,Widgetsbanner.psd,0]
//****************************
//Pointer Common
//****************************
[VarDef,curmX]
[VarDef,curmY]
[VarDef,curmZ]
[VarDef,Xangle,0]
[VarDef,Yangle,0]
[VarDef,kx,0]
[VarDef,ky,0]
[VarDef,kz,0]
[VarDef,pkx,0]
[VarDef,pky,0]
[VarDef,pkz,0]
//****************************
//moveto common
//****************************
[VarDef,sel1,1]
[VarDef,sel2,2]
[VarDef,middlex,0]
[VarDef,middley,0]
[VarDef,middlez,0]
//****************************
//mousecommon
//****************************
[varDef,Hval1,320]
[varDef,Vval1,258]
[varDef,Hval2,320]
[varDef,Vval2,258]
[varDef,Zval1,0]
[varDef,Zval2,0]
[varDef,Ldiam,10]
//****************************
//pixol information common
//****************************
[VarDef,theStroke,0]
[VarDef,GetColors,0]
[VarDef,GetDepthandMat,1]
[VarDef,GetNorms,2]
[VarDef,CenterColor,0]
[VarDef,CColor,0]
[VarDef,Rcolor,0]
[VarDef,Gcolor,0]
[VarDef,Bcolor,0]
[VarDef,Pmat,0]
[VarDef,Normx,0]
[VarDef,Normy,0]
[VarDef,Normz,0]
[VarDef,dummy,0]
[VarDef,Aptr,0]
[FontSetSizeMedium][FontSetColor,255,255,255]
[FontSetColor,255,200,0]**************** Digit's Widgets ****************[FontSetColor,160,160,160]
[pd][FontSetSizeSmall][FontSetColor,255,255,255]
[PD]
//***************************************************
// Widget_Layer Include File
// Layer Manipulation Script
//***************************************************
[varDef,Lvmove,0]
[varDef,Lhmove,0]
[varDef,Lzmove,0]
[FontSetColor,255,200,0]Layer Control...[FontSetColor,160,160,160]
//**************************************************************************
//********************Layer Control ****************************************
//**************************************************************************
[iSlider,"LayerH  ",0,1,-DocWidth,DocWidth,"Layer Horiz", 	[varSet,Lhmove,zscript:LayerH],0,[TextCalcWidth,MaxZdepth123456]]
[iSlider,"LayerV  ",0,1,-DocWidth,DocWidth,"Layer Vert",	[varSet,Lvmove,zscript:LayerV],0,[TextCalcWidth,MaxZdepth123456]]
[iSlider,"LayerZ  ",0,1,-5000,5000,"Layer Zdepth",		[varSet,Lzmove,zscript:LayerZ],0,[TextCalcWidth,MaxZdepth123456]]

[iButton," LayerMove ","Move Layer Coords",
	[Iset, Layer:Modifiers:DisplaceH,Lhmove]
	[ISet, Layer:Modifiers:DisplaceV,Lvmove]
	[ISet, Layer:Modifiers:DisplaceZ,Lzmove]
] //end of LayerMove
[PD]
//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Widget_Zdepth 
// Calculate Size according to ZDepth Area and ZReference  
//********************************************************
[FontSetColor,255,200,0]ZDepth Area Size[FontSetColor,160,160,160]
//Automatically set size of object according to depth. Size drawn will become size determined from Reference point
//Set defaults so that user doesn't get an error if he forgets to set it
[VarDef,ZArea,500]
[VarDef,RefX,DocMidX]
[VarDef,RefY,DocMidY]
[VarDef,RefZ,0]
[VarDef,RefXS,20]
[VarDef,RefYS,20]
[VarDef,RefZS,20]
[VarDef,RefMult,.5]
[VarDef,Zfactor,0]
[VarDef,ZDmult,1]
[iSlider,"MaxZdepth   ",500,.1,0,4000,"Zdepth Cube Setting",[varSet,ZArea,zscript:MaxZdepth],0,[TextCalcWidth,MaxZdepth12345678]]
[iSlider,"ZDepthMult  ",1,.1,1,100,"Zdepth Muliplier Setting",[varSet,ZDmult,zscript:ZDepthMult],0,[TextCalcWidth,MaxZdepth12345678]]
[iButton," RefObject ","Grab Reference according to MaxZDepth",
	[TransformGet,RefX,RefY,RefZ,RefXS,RefYS,RefZS]
	[VarSet,Zfactor,ZArea-RefZ]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,RefMult,Zfactor/TotalArea]
]
[iButton," SizeObject ","Size Object according to MaxZDepth",
	//go ahead and get all of the current data 
	[TransformGet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
	[RoutineCall,DepthCalc]
]//end SizeObject
//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Widget_NosePointer by Davey
// Point Nose of 3D object to any point in space
// Origin Point entered here will be used by other functions  
//********************************************************

[PD]
[FontSetColor,255,200,0]Nose Pointer[FontSetColor,160,160,160]

[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,zscript:xcenter,curmX]
	[iSet,zscript:ycenter,curmY]
	[iSet,zscript:zcenter,curmZ]
,,] // end iButton

[iButton,"Point","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,ICurrX,ICurrY,ICurrZ,ICurrXS,ICurrYS,ICurrZS,CurrXR,CurrYR,CurrZR]
	[varSet,curmX,[iGet,zscript:xcenter]]
	[varSet,curmY,[iGet,zscript:ycenter]]
	[varSet,curmZ,[iGet,zscript:zcenter]]
	[routineCall,PointFromTo,ICurrX,ICurrY,ICurrZ,curmX,curmY,curmZ,Xangle,Yangle]
	[transformSet,,,,,,,Xangle,Yangle,CurrZR]
	]
,,] // end iButton

//***************************************************
// Digit's Widgets - A Zbrush Zscript
// Random Object Placer
// Enter Radius of Random Space
//********************************************************

[PD]
[FontSetColor,255,200,0]3D Random [FontSetColor,160,160,160]
[VarDef,RRadius,100]
[VarDef,hradius,0]
[VarDef,vradius,0]
[VarDef,zradius,0]
[iSlider,"RandomRange  ",100,1,1,4000,"Diameter Range from Origin",[varSet,RRadius,zscript:RandomRange],0,[TextCalcWidth,XYAngle12345]]
[IButton,"Randomize a Object","Make Random the current object",
	[varSet,zradius,rand(RRadius)]
	[varSet,vradius,rand(RRadius)]
	[varSet,hradius,rand(RRadius)]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,zradius,zradius*-1]
	]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,vradius,vradius*-1]
	]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,hradius,hradius*-1]
	]
	
	[TransformGet,IcurrX,IcurrY,IcurrZ]
	[transformSet,IcurrX + hradius,IcurrY + vradius,IcurrZ + zradius]

]
[VarDef,Clicked,0]
[VarDef,Zdopick,0]
[IButton,"Pick Randomize a Object","Make Random Depth the current selection by mouseclick",
	[RoutineCall,Mouselook,Hval1,Vval1,Hval2,Vval2,Clicked]
	//figure out the line here now that we have the Z values and positions	
	//place current selection on canvas and go to edit
	[canvasClick,320,258,320,264]
	[iPress,transform:Move]
	//Do the line
	//make scaling right
	[VarSet,Zdopick,rand(ZArea)]
	[varSet,tmp,rand(10)]
	[if,tmp>5,
		[VarSet,Zdopick,Zdopick*-1]
	]
	[Note,zradius,,1]
	[TransformSet,Hval1,Vval1,Zdopick,Ldiam,Ldiam,Ldiam]
]
[PD]
//***************************************************
// Widget_Marker_Main - Include File
// Master Marker Include
//**************************************************************************
//********************Position Marks****************************************
//**************************************************************************
[varDef,MZ,0]
[varDef,MY,0]
[varDef,MZ,0]
[varDef,M1,0]
[varDef,M2,0]
[varDef,M3,0]
[FontSetColor,255,200,0]Position Marks..[FontSetColor,160,160,160]

[iSlider,"SelectMark",1,1,1,10,"Select Mark Index",
	[varSet,MarkIndex,zscript:SelectMark]
	[note,"Selected Mark...",,-1]
	[Note,MarkIndex,,1]
,0,[TextCalcWidth,SelectMark123]]
[iButton,"M+ ","Increment Mark",
	[VarInc,MarkIndex]
	[if, MarkIndex>10,[VarSet,MarkIndex,1]]
	[ISet,zscript:SelectMark,MarkIndex]
,0,0,.]
[iButton,"M- ","Decrement Mark",
	[VarDec,MarkIndex]
	[if, MarkIndex<1,[VarSet,MarkIndex,10]]
	[ISet,zscript:SelectMark,MarkIndex]
]
[iButton," Save ","Save Current Object Mark",
	[VarSet,MarkIndex,[IGet,zscript:SelectMark]]
	[note,"Saving Mark....",,-1]
	[Note,MarkIndex,,1]
	[TransformGet,MarkX(MarkIndex),MarkY(MarkIndex),MarkZ(MarkIndex),MarkXS(MarkIndex),MarkYS(MarkIndex),MarkZS(MarkIndex),MarkXR(MarkIndex),MarkYR(MarkIndex),MarkZR(MarkIndex)]
	//Gather pertinent info about the object
	[VarSet,MarkTool(MarkIndex),[IGet,TOOL:iteminfo]]
	[note,MarkTool(MarkIndex),,1]
	[VarSet,MarkMat(MarkIndex),[IGet,MATERIAL:iteminfo]]
	[VarSet,MarkR(MarkIndex),[IGet,Color:Redcomponent]]
	[VarSet,MarkG(MarkIndex),[IGet,Color:Greencomponent]]
	[VarSet,MarkB(MarkIndex),[IGet,Color:Bluecomponent]]
,,,CTRL+'m'
]
[iButton," Load ","Load Current Object Mark",
	[RoutineCall,LoadMark,MarkIndex]
,,,SHIFT+"l"
]
[RoutineDef,LoadMark,
	[VarDef,newchk,0]
	[VarDef,isold,0]
	[VarSet,newchk,0]	
	[if,[IGet,Transform:DrawPointer] == 1,[VarSet,isold,1],[VarSet,isold,0]]

	[ISet,zscript:SelectMark,imptr]
	[VarSet,MX,MarkX(imptr)]
	[VarSet,MY,MarkY(imptr)]
	[VarSet,MZ,MarkZ(imptr)]
	[VarSet,newchk,MX+MY+MZ]
	//check to see if a new marker
	//if user isn't holding an object make the original
	[if,isold == 1,
		[if,newchk <> 0,
			[ISet,Tool:ItemInfo,MarkTool(imptr)]
			[CanvasClick,MX,MY,MX+10,MY+10]
			[ISet,Transform:Move,1]
			[ISet,Material:ItemInfo,MarkMat(imptr)]
			[IColorSet,MarkR(MarkIndex),MarkG(imptr),MarkB(imptr)]
		]
	]
	[if,newchk <> 0,
		[if,isold == 1,
			[TransformSet,MX,MY,MZ,MarkXS(imptr),MarkYS(imptr),MarkZS(imptr),MarkXR(imptr),MarkYR(imptr),MarkZR(imptr)]
		,//else
			[TransformSet,MX,MY,MZ]
		]
	,//else
		[Note,"New Marker...",,-1]
		[note,MarkIndex,,1]
	]
//parameter
,imptr]
[iButton,"M1","Load Current Object Mark",
	[ISet,zscript:SelectMark,1]
,,,SHIFT+'1'
]
[iButton,"M2","Load Current Object Mark",
	[ISet,zscript:SelectMark,2]
,,,SHIFT+'2'
]
[iButton,"M3","Load Current Object Mark",
	[ISet,zscript:SelectMark,3]
,,,SHIFT+'3'
]
[iButton,"M4","Load Current Object Mark",
	[ISet,zscript:SelectMark,4]
,,,SHIFT+'4'
]
[iButton,"M5","Load Current Object Mark",
	[ISet,zscript:SelectMark,5]
,,,SHIFT+'5'
]
[iButton,"M6","Load Current Object Mark",
	[ISet,zscript:SelectMark,6]
,,,SHIFT+'6'
]
[iButton,"M7","Load Current Object Mark",
	[ISet,zscript:SelectMark,7]
,,,SHIFT+'7'
]
[iButton,"M8","Load Current Object Mark",
	[ISet,zscript:SelectMark,8]
,,,SHIFT+'8'
]
[iButton,"M9","Load Current Object Mark",
	[ISet,zscript:SelectMark,9]
,,,SHIFT+'9'
]
[iButton,"M10","Load Current Object Mark",
	[ISet,zscript:SelectMark,10]
,,,SHIFT+'0'
]
[PD]
//********************************************************
//******* SUBROUTINES ************************************
//********************************************************

//*********************************************
// Subroutine DepthCalc
// Calculate Size of current object using Zdepth Reference
//*********************************************
[RoutineDef,DepthCalc,
[VarDef,Zfactor,0]
[VarDef,ZMult,10]
[VarDef,TotalArea,0]
[VarDef,Delta]
	[VarSet,Delta,IcurrZ-RefZ]
	[VarSet,Zfactor,ZArea-Delta]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,ZMult,Zfactor/TotalArea]
	[VarAdd,ZMult,RefMult]
	//apply multiplier to result
	[VarSet,ZMult,ZMult*ZDmult]
	//set back to reference size
	[TransformSet,,,,RefXS,RefYS,RefZS]
	[TransformGet,Delta,Delta,Delta,IcurrXS,IcurrYS,IcurrZS]
	[VarMul,IcurrXS,ZMult]
	[VarMul,IcurrYS,ZMult]
	[VarMul,IcurrZS,ZMult]
	[TransformSet,IcurrX,IcurrY,IcurrZ,IcurrXS,IcurrYS,IcurrZS]
]
[PD]
//*********************************************
// Subroutine DistCalc
// Calculate Spacing Between 2 Zdepth Referenced Objects
//*********************************************
[RoutineDef,DistCalc,
[VarDef,Zfactor,0]
[VarDef,ZMult,10]
[VarDef,TotalArea,0]
	[VarSet,Delta,IcurrZ-RefZ]
	[VarSet,Zfactor,ZArea-Delta]
	[if,Zfactor<1,[VarSet,Zfactor,1]]
	[VarSet,TotalArea,ZArea*2]
	[VarSet,ZMult,Zfactor/TotalArea]
	[VarAdd,ZMult,RefMult]
	//don't forget to add Z multiplier factor here
	[VarSet,Dmult,ZMult*ZDmult]
]
//*********************************************
// Subroutine GetDistance
// Calculate 2D Distance between 2 Points
//*********************************************
[VarDef,DistToMark,0]
[VarDef,DDistToMark,0]
[RoutineDef,GetDistance,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[VarSet,Xresult,Xtmp*Xtmp]
	[VarSet,Yresult,Ytmp*Ytmp]
	[VarSet,DistToMark,SQRT(Xresult+Yresult)]

//list of inputs
,Ox1,Ex1,Oy1,Ey1
]
//*********************************************
// Subroutine Get3DDistance
// Calculate 3D Distance between 2 Points
//*********************************************
[RoutineDef,Get3DDistance,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Ztmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,Zresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[VarSet,Ztmp,Oz1-Ez1]
	[VarSet,Xresult,Xtmp^^2]
	[VarSet,Yresult,Ytmp^^2]
	[VarSet,Zresult,Ztmp^^2]
	[VarSet,tmp,Xresult+Yresult+Zresult]
	[VarSet,DDistToMark,SQRT(tmp)]

//list of inputs
,Ox1,Ex1,Oy1,Ey1,Oz1,Ez1
]
//*********************************************
// Subroutine GetAngle
// Get 2D angle between 2 XY Points
//*********************************************
[RoutineDef,GetAngle,
[VarDef,Xtmp,0]
[VarDef,Ytmp,0]
[VarDef,Xresult,0]
[VarDef,Yresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ytmp,Oy1-Ey1]
	[varSet,tmp,Xtmp/Ytmp]
	[VarSet,dangle,ATAN(tmp)]
	[if,Ytmp<0,
		[VarSet,dangle,dangle + 180]]
	//convert to user
	[VarSet,tmp,360-dangle+180]
	[VarSet,dangle,ABS(tmp)-360]
	[if,dangle<0,
		[VarSet,dangle,360-ABS(dangle)]]
	[VarAdd,Gxyangle,180]
	[if,dangle>360,[VarSet,dangle,dangle-360]]
//list of inputs
,Ox1,Ex1,Oy1,Ey1
]
//*********************************************
// Subroutine GetZAngle
// Get 2D angle between 2 XZ Points
//*********************************************
[RoutineDef,GetZAngle,
[VarDef,Xtmp,0]
[VarDef,Ztmp,0]
[VarDef,Xresult,0]
[VarDef,Zresult,0]
[VarDef,tmp,0]
	[VarSet,Xtmp,Ox1-Ex1]
	[VarSet,Ztmp,Oz1-Ez1]
	[varSet,tmp,Xtmp/Ztmp]
	[VarSet,zdangle,ATAN(tmp)]
	[if,Ztmp<0,
		[VarSet,zdangle,zdangle + 180]]
	//convert to user
	[VarSet,tmp,360-zdangle+180]
	[VarSet,zdangle,ABS(tmp)-360]
	[if,zdangle<0,
		[VarSet,zdangle,360-ABS(zdangle)]]
	[VarAdd,zdangle,180]
	[if,zdangle>360,[VarSet,zdangle,zdangle-360]]
//list of inputs
,Ox1,Ex1,Oz1,Ez1
]
//*****************************
//SuperDooper Point script by Doctor Davey
//*****************************
[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


[RoutineDef,MakeLine,
	[RoutineCall,Get3DDistance,mlx,mrx,mly,mry,mlz,mrz]

	[VarSet,middlex,[Interpolate,.5,mlx,mrx]]
	[VarSet,middley,[Interpolate,.5,mly,mry]]
	[VarSet,middlez,[Interpolate,.5,mlz,mrz]]

	[TransformSet,middlex,middley,middlez,,,DDistToMark*.5]
	//let us now rotate it to the mark
	[routineCall,PointFromTo,middlex,middley,middlez,mrx,mry,mrz,Xangle,Yangle]
	[transformSet,,,,,,,Xangle,Yangle,mez]

,mlx,mrx,mly,mry,mlz,mrz,mez]

[RoutineDef,GetPosition,
	//rotate xyAxis and get x&ypt
	[VarSet,tmp,ang*2]
	[VarSet,tmp,180-tmp]
	[VarSet,ang1,ang+tmp]
	[if,ang1<0,
		[VarSet,ang1,360-ABS(ang1)]]
	//calc XY angle
	[VarSet,tmp,COS(ang1)]
	[VarSet,ypt,DIST1*tmp]
	[VarSet,tmp,SIN(ang1)]
	[VarSet,xpt,DIST1*tmp]

	//rotate xzAxis and get zpt
	[VarSet,tmp,zang*2]
	[VarSet,tmp,180-tmp]
	[VarSet,ang1,zang+tmp]
	[if,ang1<0,
		[VarSet,ang1,360-ABS(ang1)]]
	//calc XY angle
	[VarSet,tmp,SIN(ang1)]
	[VarSet,zpt,DIST1*tmp]

	,ang,zang,DIST1
]
//******************************
//Mouselook
// Routine to return Mouse Position values
//******************************
[RoutineDef,Mouselook,
	[loop,999999, // "endless" loop, user keeps clicking

		[loop,999999, // wait for mouse click
			[if,[mouseLbutton] = 1,
				[varSet,IHval1,[mouseHpos]]
				[varSet,IVval1,[mouseVpos]]
				[loopexit]
			] // end if
		] // end wait for mouse click loop

		[loop,999999, // now wait for mouse up
			[if,[mouseLbutton] = 0,
				[varSet,IHval2,[mouseHpos]]
				[varSet,IVval2,[mouseVpos]]
				[loopexit]
			] // end if
		] // end wait for mouse up loop

		[if,(IVval1 > 0), //(on the canvas)
			[if,(abs(IHval2-IHval1)<3) && (abs(IVval2-IVval1)<3),
				// single click
				[VarSet,IClicked,0]
			, // else = click + drag
				[VarSet,IClicked,1]
			] // end if click or drag
			[loopExit]
		] // end if (top button clicked/not clicked)
		[loop,99999, // ensure mouse button is up before continuing
			[if,[mouseLbutton] = 0,
				[loopExit]
			] // end if
		] // end ensure loop
	] // end "endless" loop
//parameters
,IHval1,IVval1,IHval2,IVval2,IClicked
]//end Mouselook
//******************************
//Pixollook
// Routine to return All Pixol values
//******************************
[RoutineDef,PixolLook,
	[if,itype = 0,	//return color information
		[VarSet,val1,[PixolPick,0,ihval,ivval]]
		[VarSet,val2,[PixolPick,2,ihval,ivval]]
		[VarSet,val3,[PixolPick,3,ihval,ivval]]
		[VarSet,val4,[PixolPick,4,ihval,ivval]]
	,//else
		[if,itype = 1,	//Return Zdepth and material
			[VarSet,val1,[PixolPick,1,ihval,ivval]]
			[VarSet,val2,[PixolPick,5,ihval,ivval]]
		,//else
			[if,itype = 2,	//Return Normals
				[VarSet,val1,[PixolPick,6,ihval,ivval]]
				[VarSet,val2,[PixolPick,7,ihval,ivval]]
				[VarSet,val3,[PixolPick,8,ihval,ivval]]
			]
		]
	]
//Parameters here
,ihval,ivval,itype,val1,val2,val3,val4
]
//*************************
//Find the max of three numbers
//*************************
[RoutineDef,FindMax,
	[varDef,ts1,0]
	[varDef,ts2,0]
	[VarSet,ismax,0]
	[VarSet,ts1,Max(abs(md1),abs(md2))]
	[VarSet,ts2,Max(abs(md1),abs(md3))]
	[VarSet,ismax,Max(ts1,ts2)]
	[VarSet,ismax,abs(ismax)]
,md1,md2,md3,ismax
]

