Figured it out. I did find one problem with my solution. It turns out if you keep toggling the link (avatar with cube) it'll move the avatar a little bit, but that only happens if you keep toggling it without moving anything. If you can make any improvements to my solutions feel free.
Instructions: Click apply random rotation first, then click toggle link. Now that the link is enabled (text in upper right hand corner) you can rotate your object around using your cube. To set another random rotation you must first disable the link by clicking the toggle button again.
-Note each time you enable the link your cube will reset it's coord to make that it's origin (0,0,0);
Code:
import viz
import random;
viz.go();
#--------Create SkyBox-----------#
env = viz.add(viz.ENVIRONMENT_MAP, 'sky.jpg')
sky = viz.add('skydome.dlc')
sky.texture(env)
viz.clearcolor(0,0,1) # sky
#--------Create Tracker-----------#
isense = viz.add('intersense.dle')
tracker = isense.addTracker()
tracker.reset(); #Reset tracker to make it's current position it's origin 0,0,0
#--------Create Logo Model-----------#
logo = viz.add( 'logo.ive', pos =(0,1,5),euler = (-180,0,0) )
logo.setCenter(0,1,0);
#--------Create Initial Link-----------#
objectLink = viz.link(tracker,logo); # Create new link
objectLink.disable(); #Disable link until toggle enables it
#--------Create Labels-----------#
rotationLabel = viz.addButtonLabel('Apply Random Rotation')
rotationLabel.setPosition(.2,.9)
toggleLabel = viz.addButtonLabel('Toggle Link')
toggleLabel.setPosition(.2,.85)
toggleStatusLabel = viz.addText("Disabled",viz.SCREEN)
toggleStatusLabel.setPosition(.83,.95)
toggleStatusLabel.setScale(.5,.5);
def toggleLink(buttonState):
if(buttonState == viz.DOWN): #If button is being pressed down
global objectLink; # Gain access to global variable
if(toggleStatusLabel.getMessage() == "Disabled"):
tracker.reset(); # reset tracker ori matrix
objectLink.remove(); # Remove old link (Prevent accumulation from preEuler)
objectLink = viz.link(tracker,logo); # Create new link
objectLink.preEuler(logo.getEuler()); # Rotate link to logo's orginal Euler
toggleStatusLabel.message("Enabled");
elif(toggleStatusLabel.getMessage() == "Enabled"):
objectLink.disable();
toggleStatusLabel.message("Disabled");
def onButton(obj,state):
if obj == rotationLabel:
if(state == viz.DOWN): #If button is being pressed down
#Apply random rotation
logo.setEuler(random.randint(-180,180),
random.randint(-180,180),
random.randint(-180,180));
elif obj == toggleLabel:
toggleLink(state);
viz.callback(viz.BUTTON_EVENT,onButton) #Simply call to function when any button is pressed