PDA

View Full Version : Center Viewport on Object (5DT Glove)


bjgold
07-21-2006, 02:04 PM
All:

Some time ago, you wrote us some code to display and capture data from a 5DT DataGlove 5 Ultra. I am now experimenting with the code, and would like to be able to center the viewport around the glove initially (the glove and viewport will not move subsequent to the initial centering), but cannot figure out how to accomplish this. Attached is some sample code.

Thanks,
Brian

# MAIN Start
#
viz.go()
viz.fov(65,1.3)
#viz.fov(114,1.3)
#viz.get(viz.MAIN_VIEWPOINT).translate( STARTING_VIEWPOINT_POS )
#viz.get(viz.MAIN_VIEWPOINT).lookat(0,.3,0)

phase = SHOULDER_CALIBRATION

#Setup instructions
instructions = viz.add( viz.TEXT3D, SHOULDER_CALIBRATION_INSTRUCT, viz.SCREEN )
instructions.translate( .5, .5 )
instructions.scale( INSTRUCTION_SIZE, INSTRUCTION_SIZE )
instructions.alignment( viz.TEXT_CENTER_CENTER )

#Setup videoObject
#Create a texture quad to display video texture
videoQuad = viz.add( viz.TEXQUAD, viz.SCREEN )
videoQuad.translate( .5, .5 )
videoQuad.scale( VIDEO_SCREEN_SIZE, VIDEO_SCREEN_SIZE )
#Create a transform to scale coordinates to size of video
xform = viz.Transform()
xform.setScale(640,480,1)
#Apply texture matrix to quad
videoQuad.texmat(xform)
videoQuad.visible( viz.OFF )

view = viz.get(viz.MAIN_VIEWPOINT)

#Add sensors
handSensor = viz.add('patriot.dls')
armSensor = viz.add('patriot.dls')

#Add 5DT glove
PORT_5DT_USB = 0
gloveSensor = viz.add('5dt.dls')
#viz.gloveSensor()
#gloveSensor.reset()
print gloveSensor.get()

farshizzo
07-25-2006, 02:46 PM
You have the following in your sample code:#viz.get(viz.MAIN_VIEWPOINT).translate( STARTING_VIEWPOINT_POS )
#viz.get(viz.MAIN_VIEWPOINT).lookat(0,.3,0) This should do what you wish, assuming that the glove is centered around [0,0.3,0]. Does this not work for you?

bjgold
07-25-2006, 03:19 PM
I guess the question would be how do we find the initial position of the glove (or shoulder), regardless of where the glove is in relation to the transmitter cube, since we don't necessarily know that it's at (0, .3, 0)?

To extend this, how would we center the viewport around the glove so that the glove is always centered in the viewport regardless of where the arm moves (this time allowing the arm and glove to move subsequent to the initial centering)?

farshizzo
07-25-2006, 03:22 PM
Just get the absolute position of the glove model and use the lookat command. I'm assuming you have some sort of 3d model representation of the glove:glovePos = gloveModel.get(viz.POSITION,viz.ABSOLUTE_WORLD)
view.lookat(glovePos)