Vizconnect Viewpoint Collision

February 24, 2016

Sandra Bergmeir

Vizconnect’s viewpoint collision is used to stop the user’s avatar and viewpoint from moving through other objects in the scene. It is designed to create a seamless collision effect when combining trackers, transports, custom navigation nodes, and an avatar to drive the viewpoint.

Vizard includes another viewpoint collision method that works well with standard desktop navigation (e.g. mouse, keyboard). However, during a collision, the avatar, transport, or custom navigation node that is a parent of the viewpoint may keep moving after the viewpoint stops.

Viewpoint collision works best with virtual trackers (e.g. mouse, keyboard) and virtual navigation techniques (e.g. transport). If a physical tracker is used, the user can potentially walk past a virtual boundary but the viewpoint will stop. The result is a mismatch between the user’s physical and virtual positions.

Tutorial Folder Setup

First create a folder (e.g. Viewpoint collision tutorial) on your desktop to save the files that will be used in this tutorial

Vizconnect file

From the Tools tab in Vizard, select the Vizconnect option. From the Vizconnect Startup page, select option 1 to open the Vizconnect Preset Configurations page. Select the Desktop Walking option and then press the Apply Preset button. Press the Save As button in the lower left corner of the GUI, navigate to your tutorial folder on the desktop, and save the configuration as vizconnect_config.py.

Avatar and Collision Checks

Vizconnect’s collision method requires that an avatar is added to the configuration. It checks for collisions against an avatar object and moves up the scenegraph chain to modify any node that’s driving it. The desktop preset option adds a head and hand avatar.

Enable Collision

Copy and paste the following code into a new Vizard file and save the file in the tutorial folder. This code adds the maze model and enables viewpoint collision. Run the script and test collisions with the maze walls using both tracker and transport navigation:

”’Use the mouse and arrow keys to move the head trackerUse the WASD keys to control the walking transport”’import vizimport vizinfoimport vizconnectfrom vizconnect.util import view_collision

vizconnect.go(‘vizconnect_config.py’)vizinfo.InfoPanel()maze = viz.addChild(‘maze.osgb’)

ac = view_collision.AvatarCollision()ac.setCollideList([vizconnect.AVATAR_HEAD])ac.setTransport(vizconnect.getTransport().getNode3d())

Vertical collisions

Run the example code from the previous section and press the x and z keys to move the transport up and down. Notice how the viewpoint moves through the ceiling and floor. The avatar collision constructor accepts an argument to enable vertical collisions. Change:

ac = view_collision.AvatarCollision()

To:

ac = view_collision.AvatarCollision(collideVertical=True)

Run the script again and see how the viewpoint stops at the ceiling and floor.

Collide List

The collide list specifies whether the avatar head, avatar base, or both cause collisions with the environment. So far, we’ve been using only the avatar head to test for collisions:

ac.setCollideList([vizconnect.AVATAR_HEAD])

Add the following lines of code to the end of the script. This code adds a cube that can be moved up and down using the 1 and 2 keys. Run the script and navigate over the cube, then lift the cube to head height to generate a collision:

# Add a cube to test collisionsimport vizshapecube = vizshape.addCube(pos=[0,0.5,4])# Move the cube up and down by pressing keys 1 and 2import vizactvizact.onkeydown(‘1’,cube.setPosition,[0,0.5,0],viz.REL_LOCAL)vizact.onkeydown(‘2’,cube.setPosition,[0,-0.5,0],viz.REL_LOCAL)

Next, modify the collide list to include collisions with the avatar base:

ac.setCollideList([vizconnect.AVATAR_HEAD,vizconnect.AVATAR_BASE])

Run the script again and notice how collisions occur with the cube at ground level.

Custom Navigation Node

A group node can be used for custom navigation by placing it in the scenegraph above an avatar and updating it’s transform every frame. The collision detection will take into account any node that is above the avatar.

Run the vizconnect file and go to the Trackers tab. Press the Add a New Tracker button, select the Group tracker option, and press Apply & Exit. Then parent the transport to the group node in the scenegraph.

Next, updates are applied to the group tracker’s position every frame. Add the following code to the end of the script:

# Get a handle to the group tracker and update it’s position every framegroupTracker = vizconnect.getTracker(‘group’).getRaw()def updateGroup():    groupTracker.setPosition([0,0,0.01],viz.REL_LOCAL)

event_handle = vizact.onupdate(0,updateGroup)# Toggle update event with spacebarvizact.onkeydown(‘ ’, event_handle.setEnabled, viz.TOGGLE )

Run the script and see how the collision detection works with the group node’s movements. Toggle the automatic position updates on and off by pressing the spacebar.

Stay Updated
Subscribe to our monthly Newsletter
CONTACT US 
Phone +1 (888) 841-3416
Fax +1 (866) 226-7529
813 Reddick St
Santa Barbara, CA 93103