WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-14-2008, 08:47 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Strange bug concerning a mirror

Hi all,

I'm having some strange problems with my mirror. When I use viz.go(viz.HMD | viz.STEREO), the right half of the mirror doesn't reflect everything (mainly not my avatar and the frames of the paintings) but the left half does. When I use viz.go(viz.HMD), the whole mirror works fine. I have absolutely no clue why this happens, and it happens on both screens of the HMD in STEREO mode. Any clue on how to fix this problem is appreciated! See the pictures for the difference.
Attached Thumbnails
Click image for larger version

Name:	bad.JPG
Views:	1670
Size:	244.3 KB
ID:	241   Click image for larger version

Name:	good.JPG
Views:	1639
Size:	186.3 KB
ID:	242  
Reply With Quote
  #2  
Old 05-14-2008, 06:00 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I've modified the original mirror sample script to support stereo. The main differences are that a render node must be created for each eye. Also, I had to increase the clip plane scale factor to remove the clipping issues. Let me know if this works:
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_SET_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 05-15-2008, 05:09 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Hi farshizzo,

The modification of the original mirror script works fine. The only error in it is the line
Code:
lens.setMatrix(viz.Matrix.translate(-pos)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))
This should be:
Code:
lens.setMatrix(viz.Matrix.translate(pos*-1)*invRot*viz.Matrix.scale(1,1,-1)*rot*viz.Matrix.translate(pos))
Thanks for helping me again!
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
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
Strange Rendering Lag Spikes theuberk Vizard 3 02-26-2008 09:55 AM
Strange Speak animation and VRML rendering zoltantoth Vizard 2 04-19-2007 10:24 AM


All times are GMT -7. The time now is 02:10 AM.


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