WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Problems with using WIRKS without the Kinect in a mirror setting (https://forum.worldviz.com/showthread.php?t=4615)

Jennifer 06-03-2013 04:17 PM

Problems with using WIRKS without the Kinect in a mirror setting
 
Hello,

we have a problem with a setting in which we want to connect the head of an avatar to the camera in front of a mirror. When we use the 2D display this works just fine with the mirror code from this forum.

However, what we would like to do is using the WIRKS system WITHOUT the Kinect. Instead we just use the Inertia Cube and the HMD and want to connect that to the head of the avatar. Therefore, we used parts of the code of the balloonPop Demo file.

This did not work. What happens is that the avatar flies in the middle of the room and through the mirror it seems that the viewpoint is connected to the avatars feet (instead of the head). Somehow the connection of the avatar`s head and the camera seems to be overwritten by the code setting up the HMD.

Probably the problem has to do with the fact that there is still some code that uses Kinect data although we do not use the Kinect (e.g. myTrackers.getHead()). But we have no idea how to set this up properly.

It would be great if you could help us find the problem with this code!

Thanks in advance,
Jennifer


Code:

# Add the path of the common modules.
import sys
sys.path.insert(0,'C:/Program Files (x86)/WorldViz/Wirks/Vizard Files/Common Modules/')

import viz
import vizact
import vizmat
import math
import random

import Config
import DisplayMode
import InertialLabs
import Instruction
from FAAST import Trackers
from FAAST import Gestures

INSTRUCTION = \
"""

"""

#######################################


#########################################


class BalloonPop(viz.EventClass):
        """
       
        """
       
        def __init__(self, headTracker=None):
                viz.EventClass.__init__(self)
               
                self.headTracker = headTracker       
       
       
############################################################
# Main.

import viztask
import Curtain

viz.setMultiSample(4)
viz.setOption('viz.fullscreen.monitor', Config.DISPLAY_ID)
viz.go(viz.FULLSCREEN)


def addKinectTrackers():
        """
        Add Kinect trackers for each body part, taking into account SENSOR_HEIGHT and MIRROR_MODE.
        """
        trackers = Trackers.add(sensorHeight=Config.SENSOR_HEIGHT, head=True, mirrorMode=Config.MIRROR_MODE)
        return trackers
       
       
def addKinectGestures():
        """
        Add Kinect gestures to enable the FAAST reset gesture.
        """
       
        gestures = Gestures.add()
        return gestures       


def addInertialLabs():
        """
        Add an InertialLabs sensor with the correct USB COM port number.
        """
        sensor = InertialLabs.addSensor(port=Config.COM_PORT)
        return sensor


def resetHeading(sensor, link, yawOffset):
        """
        Reset OS3D heading (such that, upon reset, the user initializes facing virtual north) (this is necessiarily relative to the HMD)
        Virtual north refers to the direction of the positive z axis, or virtual 0 degrees yaw (in Vizard's standard coordinate system)
        """
       
        if sensor is not None and link is not None:
                link.reset(viz.RESET_OPERATORS)
                # Get yaw offset
                yaw = sensor.getEuler()[0]
                # Subtract known yaw offset from mounting
                yaw -= yawOffset
                m = sensor.getMatrix()
                m.postEuler(-yaw,0,0)
                m.invert()
                quat = m.getQuat()
                # Apply offset to link
                link.postEuler([-yaw,0,0],target=viz.LINK_ORI_OP,priority=-20)
                link.preQuat(quat,target=viz.LINK_ORI_OP,priority=-20)       


myTrackers = None
displayMode = None
def init():       
        """
        Initialize the simulation.
        """
       
        global level, myTrackers, displayMode
       
        # Add the kinect trackers and gestures.
        myTrackers = addKinectTrackers()
        myGestures = addKinectGestures()
       
  #hier scheinbar noch watt aufrufn
        if Config.KINECT_MODE:
                level = BalloonPop(myTrackers.getHead())
        else:
                level = BalloonPop(viz.MainView)

        # Check for the reset gesture.
        vizact.onevent( Gestures.GESTURE_ON_EVENT, lambda k:(k.button==Config.RESET_ID, None), reset )
       
       
        def handleUserChoice():
                """
                Based on the value of DISPLAY_MODE (in Config.py), select and establish display parameters for the user's view.
                """
               
                Curtain.load()
                if Config.DISPLAY_MODE is None:
                        DisplayMode.showGUI()
                        displayMode = DisplayMode.getDisplayMode()
                else:
                        displayMode = Config.DISPLAY_MODE
                        DisplayMode.setDisplayMode(displayMode)
               
                loadText = showLoadingPage()
                yield Curtain.fadeToBlack()
               
                # Add an instruction box to the simulation window ('F1' shows/hides the instruction box)
                Instruction.add( INSTRUCTION )
               
                # Apply display parameters.
                DisplayMode.setupDisplay()
               
                # If the SONY HMD display mode was chosen,
                if displayMode == DisplayMode.DISPLAY_HMD:       
                        # Add InertialLabs sensor, and set up 6D tracker by merging it with head tracker.
                        myILSensor = addInertialLabs()
                        head6DoFTracker = viz.mergeLinkable(myTrackers.getHead(), myILSensor)        #myTrackers
                        headLink = viz.link(head6DoFTracker, viz.MainView, srcFlag=viz.ABS_GLOBAL)
                        resetHeading(myILSensor, headLink, Config.INERTIAL_LABS_OFFSET + 90)
                       
                        # Reset head orientation
                        vizact.onevent( Gestures.GESTURE_ON_EVENT, lambda k:(k.button==Config.RESET_ID, None), resetHeading, myILSensor, headLink, Config.INERTIAL_LABS_OFFSET + 90 )
               
                # Otherwise,
                else:
               
                        # Set up user's default view.
                        viz.MainView.setPosition(0, Trackers.DEFAULT_HEAD_HEIGHT, -6)
                       
                loadText.remove()
                yield Curtain.fadeToWorld()
        viztask.schedule(handleUserChoice())


def reset():
        """
        Reset the simulation, and reset the user's view.
        """
       
        # If the senor height is None, use the default head height, 1.82m.
        if Config.SENSOR_HEIGHT is None:
                myTrackers.setDefaultHeadHeight()
       
        #if displayMode != DisplayMode.DISPLAY_HMD:
        #        viz.MainView.setPosition(0, myTrackers.getHead().getPosition(viz.ABS_GLOBAL)[1], -6)


def showLoadingPage():
        """
        Show the 'Loading...' message as the demo prepares to initialize.
        """
       
        loadText = viz.addText('Loading...', parent=viz.SCREEN, pos=[.5, .5, 0])
        loadText.draworder(101)
        loadText.alignment(viz.TEXT_CENTER_CENTER)
       
        return loadText

#####################################################


REFLECT_MASK = viz.addNodeMask()

def addMirror(mirror,mat=None,eye=viz.BOTH_EYE):

        #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_OVERRIDE)
        lens.setCullMask(REFLECT_MASK)
        if eye == viz.LEFT_EYE:
                lens.disable(viz.RENDER_RIGHT)
                mirror.setMask(REFLECT_MASK|viz.RIGHT_MASK,mode=viz.MASK_REMOVE)
        elif eye == viz.RIGHT_EYE:
                lens.disable(viz.RENDER_LEFT)
                mirror.setMask(REFLECT_MASK|viz.LEFT_MASK,mode=viz.MASK_REMOVE)
        else:
                mirror.setMask(REFLECT_MASK,mode=viz.MASK_REMOVE)

        #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.01])

        #Project reflection texture onto mirror
        mirror.texture(tex)
        mirror.texGen(viz.TEXGEN_PROJECT_EYE)

#Add environment
environment=viz.add('C:/Figuren/Buero_VR/room2/room2.wrl')
environment.setEuler(90,0,0)
environment.setPosition(1.5,0,-8)

#Add male avatar
avatarMale = viz.add('C:/Users/VR/Documents/Jenni_Dateien/Jenni_StudieII/Dateien zur Aufnahme/business02_m/business02_m_highpoly.cfg')
       
avatarMale.setEuler(270,0,0)
avatarMale.setPosition(-1,0,-5.5)

#Create a mirror
mirror = viz.addTexQuad()
mirror.scale(.8,1,1)
mirror.setPosition(0, 1.5, -4.1)
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('C:/Figuren/2012-05-09 - Uni Duisburg Avatars/F20_HairOpen_NoMakeup.cfg')



def mykeyboard(key):
  # Speech and Animations

        if key == ' ':
                avatar.state(1)
                #avatarMale.addAction(leer, pool=8)
                avatarMale.setPosition(1.5,0,-4.9)

viz.callback(viz.KEYBOARD_EVENT,mykeyboard)


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


#####################################################

init()
#vizact.onkeydown(' ', balloonPop.initializeGame)



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

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