WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-24-2008, 03:43 AM
dan12345 dan12345 is offline
Member
 
Join Date: Jan 2008
Posts: 58
Problem using mirror

Hello - I've been trying to use the mirror which was discussed in previous forum posts. Everything seemed to be working just fine when trying it out not on the HMD - But when i try it out with the helmet i get a very very weird bug -
the avatar linked to the viewpoint usually looks just dandy, but while moving it suddenly disappears for a second or two - this happens consistently in particular moving patterns. The avatar seems to vanish behind an invisible screen. I've put all my efforts to understand why this happens, but feel like i've run into a dead end. Would be very, very grateful, if you could help me out!

Attached after this is the code (simplified to the minimum relevant to the mirror problem)
it uses the bigroom.ive file used in the public speaking demo. There is a boolean variable TESTING at the beginning which decides if to run on the HMD or not - notice how running not on the HMD produces good results. The addMirror function was copy pasted from the one talked about in earlier forum posts....

Thanks alot
dan

THE CODE:
#coding: UTF-8
import viztracker
TESTING = False
if TESTING :
viz.go()
else :
print(3)
head = viztracker.add()
headlink = viz.link(head,viz.MainView)
viz.eyeheight(0)
headlink.postTrans([0,0,0.2])
viz.go(viz.HMD|viz.STEREO)

def headLightOnMirror():
light = viz.addLight()
light.setPosition(-4,1.8,1.2)
light.position(0,0,1,0)

def addMirror(mirror,mat=None):

#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=[1024,1024])
lens.attachTexture(tex)
lens.setInheritView(True,viz.POST_MULT)
lens.disable(viz.CULL_FACE,op=viz.OP_SET_OVERRIDE)

#Setup reflection matrix
rot = viz.Matrix.quat(quat)
invRot = rot.inverse()
lens.setMatrix(viz.Matrix.translate(pos*-1.0)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))

#Setup reflection clip plane
plane = vizmat.Plane(pos=pos,normal=dir)
dist = plane.distance([0,0,0])
lens.clipPlane([-dir[0],-dir[1],-dir[2],dist+0.001])

#Project reflection texture onto mirror
mirror.texture(tex)
mirror.texGen(viz.TEXGEN_PROJECT_EYE)


myRoom = viz.add('../art/models/bigroom.IVE')
#Apply mirror settings to mirror object
mirrorsurface = viz.addTexQuad()
mirrorsurface.scale(.3,.25,.6)
mirrorsurface.setPosition(0,1.8,1.2)
mirrorsurfacerotation = [0,0,0] #rotation around the Z,Y,X axes #changed from [90,0,0]
mirrorsurface.rotate(mirrorsurfacerotation)
m = viz.Matrix()
m.setPosition(mirrorsurface.getPosition(viz.ABS_GL OBAL))
m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y
addMirror(mirrorsurface,m)

female = viz.add('female.cfg')
headLink = viz.link(viz.MainView,female)
headLink.setPos([None,0,None])
headLightOnMirror()
Reply With Quote
  #2  
Old 07-25-2008, 01:30 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Please use the [code][/code] tags when posting code samples on the forum. It preserves the indentation, which is necessary for Python code.

I believe somebody else ran into this issue as well and I posted the fix for it. In case you cannot find it, here is the code again that should work in stereo mode.
Code:
import viz
viz.go(viz.STEREO)

REFLECT_MASK = viz.LAST_MASK << 1

def addMirror(mirror,mat=None):

	#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()
	
	for eye in (viz.RENDER_LEFT,viz.RENDER_RIGHT):
		
		#Create render texture
		tex = viz.addRenderTexture()

		#Create render node for rendering reflection
		lens = viz.addRenderNode(size=[1024,1024])
		lens.setCullMask(REFLECT_MASK)
		lens.attachTexture(tex)
		lens.setInheritView(True,viz.POST_MULT)
		lens.disable(viz.CULL_FACE,op=viz.OP_OVERRIDE)
		lens.disable(eye)
		
		#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.1])
		
		#Project reflection texture onto mirror
		mirror.texture(tex)
		mirror.texGen(viz.TEXGEN_PROJECT_EYE)
	
#Add gallery environment
gallery = viz.add('gallery.ive')

#Use existing painting as mirror and specify the matrix
mirror = gallery.getChild('art04-FACES')
m = viz.Matrix()
m.setPosition(mirror.getPosition(viz.ABS_GLOBAL))
m.setEuler(180,0,0)

#Apply mirror settings to mirror object
addMirror(mirror,m)

#Increase ambient lighting
viz.MainView.getHeadLight().ambient(1,1,1)

#Create a self avatar
avatar = viz.add('vcc_female.cfg')

#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=viz.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)
Reply With Quote
  #3  
Old 07-28-2008, 04:30 AM
dan12345 dan12345 is offline
Member
 
Join Date: Jan 2008
Posts: 58
Hi.
I tried using the code you posted here, but now i have a problem - it uses functionality of the newest version of vizard, but as posted a while ago, the newest version of vizard does not work for us, because of intersense driver issues.... Would still be VERY happy for a fix with the driver issues, but in the meantime could you maybe post the same code using old vizard functionalities? ) the problem is in viz.matrix.translate function, in the add mirror method...
thanks, dan
Reply With Quote
  #4  
Old 07-28-2008, 04:48 AM
dan12345 dan12345 is offline
Member
 
Join Date: Jan 2008
Posts: 58
Okay, mirror problem solved, as i changed the line that gave problems
with the line in the previous add mirror function. Intersense Driver problem still exists ofcourse though.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange bug concerning a mirror Frank Verberne Vizard 2 05-15-2008 05:09 AM
Eyes that keep looking at the mirror Frank Verberne Vizard 3 05-13-2008 05:39 AM
Mirror issues Frank Verberne Vizard 2 04-08-2008 10:37 AM
Getting a mirror to work in any environment Frank Verberne Vizard 5 03-27-2008 08:21 AM
problem with female animations vmonkey Vizard 1 10-07-2005 10:36 AM


All times are GMT -7. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC