WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-08-2008, 08:20 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Mirror issues

Hi,

I'm modifying my mirror to be able to use it in multiple experiments and I've run into a little problem. If you run the sample script in this post, you'll see that the mirrorquad doesn't reflect the lower part of the room properly. It seems that only if the quad is turned around it's Y-axis (the reflection works fine if you turn the quad around it's X and Z-axes), the reflection isn't correct anymore. Does someone know how to fix this?
Code:
import viz

viz.go()

import viz
viz.go()

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)
	
#Add gallery environment
gallery = viz.add('gallery.ive')

#Use existing painting as mirror and specify the matrix
mirrorsurface = viz.addTexQuad()
mirrorsurface.setPosition([0, 1, 2.5]) #Y,Z,X
mirrorsurfacerotation = [0,90,0] #rotation around the Z,Y,X axes
mirrorsurface.rotate(mirrorsurfacerotation) 
m = viz.Matrix()
m.setPosition(mirrorsurface.getPosition(viz.ABS_GLOBAL))
m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y

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

#Increase ambient lighting
viz.MainView.getHeadLight().ambient(1,1,1)
P.S. It can be the case that the order of the coordinates doesn't correspond to you coordinate-system. We also use dTrack software and therefore we had to adjust the coordinatesystem. Thanks to the comments you'll know which number represents which coordinate.
Reply With Quote
  #2  
Old 04-08-2008, 10:25 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
There is a bug in the clip plane calculation, replace that section with the following code:
Code:
#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.001])
Reply With Quote
  #3  
Old 04-08-2008, 10:37 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Thanks for the quick reply! Replacing the section of the clip plane calculation did the trick. The mirror now works as it should work!
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


All times are GMT -7. The time now is 05:40 PM.


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