WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

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


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?
import viz


import viz

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())

	#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])
	#Setup reflection matrix
	rot = viz.Matrix.quat(quat)
	invRot = rot.inverse()
	#Setup reflection clip plane
	plane = vizmat.Plane(pos=pos,normal=dir)
	dist = plane.distance([0,0,0])
	#Project reflection texture onto mirror
#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
m = viz.Matrix()
m.setEuler(mirrorsurfacerotation[0]-180,-mirrorsurfacerotation[1], mirrorsurfacerotation[2]) #Z,X,Y

#Apply mirror settings to mirror object

#Increase ambient lighting
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
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:
#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])
Reply With Quote
Old 04-08-2008, 10:37 AM
Frank Verberne Frank Verberne is offline
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

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 06:56 AM.

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