// ********************************************************************************
// Code for orienting tool objects.
// David Ikeda - 2004

// ********************************************************************************
[VarDef, includeOrientation, 0]
[If, #includeOrientation= 0,

<zscriptinsert, "include/ikeda_common.txt">

// ********************************************************************************
[RoutineDef, "GetTransformation",
	[TransformGet, 
		t(0), t(1), t(2), 
		t(3), t(4), t(5), 
		t(6), t(7), t(8)
	]
, t]

// ********************************************************************************
[RoutineDef, "SetTransformation",
	[TransformSet, 
		#t(0), #t(1), #t(2), 
		#t(3), #t(4), #t(5), 
		#t(6), #t(7), #t(8)
	]
, t]

// ********************************************************************************
[RoutineDef, "SetToolWithTransformation",
	[ISet, Tool:ItemInfo, #toolNumber]

	[CanvasClick, 320, 240, 320, 200]

	[RoutineCall, "SetTransformation", #t]
	[IPress, Transform:Edit]
	
, toolNumber, t]

// ********************************************************************************
[RoutineDef, "SpinObject", 
	[Loop, #cManyIterations,
		[If, #angle > -180, [LoopExit] ]
		[VarAdd, angle, 360]
	]

	[Loop, #cManyIterations,
		[If, #angle < 180, [LoopExit] ]
		[VarSub, angle, 360]
	]

	[VarDef, tempTransformation(9)]
	[RoutineCall, "GetTransformation", #tempTransformation]
	[VarSet, tempTransformation(6), 0]
	[VarSet, tempTransformation(7), #angle]

	[Loop, 1,
		[If, #tempTransformation(7) >= 90, [VarSet, tempTransformation(8), 180][LoopExit] ]
		[If, #tempTransformation(7) <= -90, [VarSet, tempTransformation(8), 180][LoopExit] ]
		[VarSet, tempTransformation(8), 0]
	]
	
	[RoutineCall, "SetTransformation", #tempTransformation]
, angle]

// ********************************************************************************
[RoutineDef, "SetToolRotation",
	[VarDef, temp(9) ]
	[RoutineCall, "GetTransformation", #temp]

	[VarSet, temp(6), #xAngle]
	[VarSet, temp(7), #yAngle]
	[VarSet, temp(8), #zAngle]

	[RoutineCall, "SetTransformation", #temp]

, xAngle, yAngle, zAngle]

// ********************************************************************************
[RoutineDef, "ResetToolRotation",
	[RoutineCall, "SetToolRotation", 0, 0, 0]
]

// ********************************************************************************
][VarSet, includeOrientation, 1]
