![]() |
#6
|
|||
|
|||
I am also having a lot of trouble trying to implement a mirror. In this version I cannot seem to get the mirror to reflect avatars:
import viz import time import vizact viz.go() clock = 0 PERSON_HEIGHT = 1.5 GRAVITY = 9.81 OFFSET = 0 #Offset due to the room model load print OFFSET light = viz.MainView.getHeadLight() light.disable() roomGroup = None viz.clearcolor(0.1,0.1,0.3) labRoom = viz.add('LabRoom.ive') labRoom.setPosition(0, OFFSET, 0) #Correct view height viz.MainView.eyeheight(0) ##--------------------------------------------------------------------- ##Configure tracking ##--------------------------------------------------------------------- ##Orientation of the HMD #isense = viz.add('intersense.dls') ##isense.addTracker() #adding the tracker #Commented out because of the dls file (instead of a dle #view = viz.MainView #defining the main view #vrpn = viz.add('vrpn7.dle') #Interface with PPT computer #PPT_HOSTNAME = '171.64.33.43' #PPT IP address ##Adding the tracker to the orientation #headMarker = vrpn.addTracker('PPT0@' + PPT_HOSTNAME, 0) ##Linking the orientation to the main view #headOri = viz.link(isense, view, mask = viz.LINK_ORI, priority = 0) ##Linking the PPT to the mainview #headPos = viz.link(headMarker, view, mask = viz.LINK_POS, priority = 0) ##Specify HMD model #nvis.nvisorSX111() #-------------------------------------------------------- #Mirror #-------------------------------------------------------- REFLECT_MASK = viz.addNodeMask() def addMirror(mirror,mat=None,eye=viz.BOTH_EYE): #If mirror matrix is not specifed, get matrix of mirror object if mat is None: mat = mirror.getMatrix() #Position of mirror pos = viz.Vector(mat.getPosition()) #Direction mirror is pointing dir = viz.Vector(mat.getForward()) dir.normalize() #Quaternion rotation of mirror quat = mat.getQuat() #Create render texture tex = viz.addRenderTexture() #Create render node for rendering reflection lens = viz.addRenderNode(size=[512,512]) lens.attachTexture(tex) lens.setInheritView(True,viz.POST_MULT) lens.disable(viz.CULL_FACE,op=viz.OP_OVERRIDE) if eye == viz.LEFT_EYE: lens.disable(viz.RENDER_RIGHT) mirror.disable(viz.RENDER_RIGHT) elif eye == viz.RIGHT_EYE: lens.disable(viz.RENDER_LEFT) mirror.disable(viz.RENDER_LEFT) mirror.renderToAllRenderNodesExcept([lens]) #Setup reflection matrix rot = viz.Matrix.quat(quat) invRot = rot.inverse() lens.setMatrix(viz.Matrix.translate(-pos)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos)) #Setup reflection clip plane s = viz.sign(viz.Vector(dir) * viz.Vector(pos)) plane = vizmat.Plane(pos=pos,normal=dir) dist = plane.distance([0,0,0]) lens.clipPlane([dir[0],dir[1],dir[2],s*dist-0.01]) #Project reflection texture onto mirror mirror.texture(tex) mirror.texGen(viz.TEXGEN_PROJECT_EYE) viz.startlayer(viz.QUADS) #Hardcoding the mirror's plane viz.texcoord(0,0) viz.vertex( 6.35 , OFFSET + 1.4 , -3.1) viz.texcoord(0,1) viz.vertex( 6.35 , OFFSET + 2.85, -3.1) viz.texcoord(1,1) viz.vertex( 2.8 , OFFSET + 2.85, -3.1) viz.texcoord(1,0) viz.vertex( 2.8 , OFFSET + 1.4 , -3.1) mirrorRight = viz.endlayer( ) mirrorLeft = mirrorRight.copy() #specify the matrix m = viz.Matrix() m.setPosition([0.25,1,0.25]) m.setEuler(0 , 0 ,0) #This determines which way the mirror is facing #Apply mirror settings to mirror object addMirror(mirrorRight,m,viz.RIGHT_EYE) addMirror(mirrorLeft,m,viz.LEFT_EYE) #Increase ambient lighting #viz.MainView.getHeadLight().ambient(1,1,1) #-------------------------------------------------------- #Create a self avatar #-------------------------------------------------------- avatar = viz.add('vcc_female.cfg') avatar.setScale(1.7,1.7,1.7) #Link avatar body to viewpoint avatarLink = viz.link(viz.MainView,avatar) avatarLink.setPos([None,0,None]) #Keep avatar on floor avatarLink.setEuler([None,0,0]) #Only update avatar yaw avatar.setMask(viz.LEFT_MASK|viz.RIGHT_MASK,mode=v iz.MASK_REMOVE) #Only draw avatar in mirror #Link avatar head to viewpoint head = avatar.getBone('Bip01 Head') head.lock() viz.link(viz.MainView,head,mask=viz.LINK_ORI) avatar2 = viz.add('vcc_female.cfg') avatar2.setPosition(4, .1, 0) avatar2.setScale(1.7,1.7,1.7) |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating a Vizard Sensor Plugin | farshizzo | Plug-in development | 25 | 08-01-2019 12:24 AM |
Vizard and Augmented Reality | realvision | Vizard | 4 | 04-04-2008 10:59 AM |
Vizard won't run | wouters | Vizard | 5 | 02-05-2008 11:12 AM |
Fall 2007 release of Vizard R3 | 3 D | Announcements | 0 | 10-15-2007 04:50 PM |
wxPython with Vizard | farshizzo | Vizard | 18 | 09-29-2005 08:49 AM |