WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Mirror issues (https://forum.worldviz.com/showthread.php?t=1436)

Frank Verberne 04-08-2008 08:20 AM

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.

farshizzo 04-08-2008 10:25 AM

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


Frank Verberne 04-08-2008 10:37 AM

Thanks for the quick reply! Replacing the section of the clip plane calculation did the trick. The mirror now works as it should work;)!


All times are GMT -7. The time now is 06:48 AM.

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