Vizard 7 » Reference » Vizconnect » Viewpoint Collision
7.7

Viewpoint Collision

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.

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.

Example

The following example adds the maze model and enables vizconnect's viewpoint collision. Before running the script, create a configuration file with a head and hands avatar:

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 tracker
Use the WASD keys to control the walking transport
'''

import viz
import vizinfo
import vizconnect
from 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

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, only the avatar head has been used for collisions:

ac.setCollideList([vizconnect.AVATAR_HEAD])

Add the following lines of code to the end of the script. This adds a cube that can be moved up and down using the '1' and '2' keys. Run the script and navigate over the cube. Turn around so the cube is in view, then lift the cube to head height by pressing '1' a few times. At this height the viewpoint will collide with the cube:

# Add a cube to test collisions
import vizshape
cube = vizshape.addCube(pos=[0,0.5,4])
# Move the cube up and down by pressing keys 1 and 2
import vizact
vizact.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 at the top of the scenegraph 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 frame
groupTracker = 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 spacebar
vizact.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.