WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-25-2008, 09:01 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Getting a mirror to work in any environment

I used the code from this thread (http://www.worldviz.com/forum/showthread.php?t=1303) to create a mirror in the gallery environment. However, when I want to use the mirror in an other environment, it doesn't work anymore. Can somebody explain me why it doesn't work anymore and how I can make it work in any environment (even without an environment)? Or do I have to adjust the mirror for the environment I'm using? If so, how can I do that? Here is my code I'm currently using:
Code:
import viz
import socket
import math
import vizmat
import csv
import time
import random

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=[512,512]) #set to [1024,1024] in the lab!
	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')
environment = viz.add('tut_ground.wrl')

#Create a mirror
mirror = viz.addTexQuad()
mirror.scale(1.3,3,1)
mirror.setPosition([0, 1, 2])
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(3,3,3) #adjust avatar lighting

#Create two self avatars, possible: vcc_male.cfg, vcc_female.cfg, male.cfg, male_bbox.cfg, duck.cfg, hand.cfg
avatar1 = viz.add('vcc_male.cfg')
avatar1.setPosition(0.5,0,0) #(Y,Z,X)
avatar2 = viz.add('vcc_female.cfg')
avatar2.setPosition(-0.5,0,0) #(Y,Z,X)
Reply With Quote
  #2  
Old 03-25-2008, 10:17 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Can you be more specific about what doesn't work? I ran your script and it worked fine.
Reply With Quote
  #3  
Old 03-25-2008, 10:47 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Quote:
Originally Posted by farshizzo View Post
Can you be more specific about what doesn't work? I ran your script and it worked fine.
It seems to be that the computer I was testing on was the problem. When I tested it in the lab, all was fine like you say. I don't know why my testing computer has this issue, but it doesn't matter that much if it works in the lab.
Reply With Quote
  #4  
Old 03-26-2008, 05:25 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
I'm still having problems with the mirror. When I don't adjust the ambient lighting like this:
Code:
#Increase ambient lighting
viz.MainView.getHeadLight().ambient(3,3,3)
the mirrorimages of the avatars are very dark. This can be fixed with the code above, but then the skin of a Moroccan avatar I will be using is way to bright. So how can I adjust the mirrorimages of the avatar so that the mirrorimages look exactly like the avatars in front of the mirror?
Reply With Quote
  #5  
Old 03-26-2008, 01:43 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
By default Vizard has a light source attached to the head position. So when you look in the mirror the head light is not facing the avatar. You should disable the head light and add a fixed light source. For example, the following code will create a directional light that point downward:
Code:
viz.MainView.getHeadLight().disable()
sunlight = viz.addLight()
sunlight.position(0,1,0,0)
sunlight.ambient([0.6]*3)
Also, try reducing the ambient light value. The values range from 0-1, so setting it to 3 will max out the ambient value and make everything look over bright.
Reply With Quote
  #6  
Old 03-27-2008, 09:21 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Thanks farshizzo! After trying some things I managed to get the reflection the way I wanted. Putting the light on the position of the mirror seemed to do the trick. Because I have several conditions (where participants view the world through the eyes of the avatar or through a point outside of the body of the avatar) I had to disable the headlight and add a light that pointed on the avatar, which had to be the same as the light on the mirror. Anyway, the problem is solved!
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
Best Modelling Environment for Vizard? tmcw Vizard 6 02-24-2007 12:15 PM
newbie problem getting vizard to work Colin Vizard 2 11-10-2006 11:54 AM
MainWindow.frustum doesn't work Joran Vizard 2 06-13-2006 06:24 PM
peoplemaker not work in viz 2.53? bailenson Vizard 3 10-21-2005 01:43 PM
environment maps, scenes, and you! vadrian Vizard 1 01-12-2005 05:04 PM


All times are GMT -7. The time now is 09:43 PM.


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