Hi,
here is a small script that implements some teleportation in VRED:
controller0 = None
class Teleporter:
def __init__( self ):
self._nodeTelePoint = findNode("TelePoint")
self.setLocation( 0, 0 )
self.setLookat( 0,100000 )
def setLocation( self, x, y ):
self._loc = Pnt2f( x, y )
def location( self ):
return self._loc
def setLookat( self, x, y ):
self._lookAt = Pnt2f( x, y )
def lookat( self ):
return self._lookAt
def activate( self ):
self._nodeTelePoint.setActive(True)
def deactivate( self ):
self._nodeTelePoint.setActive(False)
def updateTeleportLocation( self, pick ):
self._nodeTelePoint.setTranslation(pick.x(),pick.y(),100)
def teleport( self, pick, pickNode ):
nodeHMD = getCamNode(-1).getWorldTransform()
pos = self.location()
newOriginX = pick.x()-nodeHMD[3]+pos.x() # calculate new X
newOriginY = pick.y()-nodeHMD[7]+pos.y() # calculate new Y
newOriginZ = 0
setFromAtUp( -1, newOriginX, newOriginY, newOriginZ,
self._lookAt.x() - newOriginX,
self._lookAt.y() - newOriginY,
newOriginZ, 0, 0, 1 )
self.setLocation( newOriginX, newOriginY )
theTeleporter = Teleporter()
def trigger0Pressed():
global theTeleporter
controller0.setPickingAxis(1)
controller0.showPickingAxis(true)
theTeleporter.activate()
def trigger0Released():
global theTeleporter
controller0.showPickingAxis(false)
theTeleporter.deactivate()
cmat = controller0.getWorldMatrix()
rayOri = Pnt3f(cmat[3], cmat[7], cmat[11])
rayDir = Vec3f(-cmat[2], -cmat[6], -cmat[10])
pickResult = getSceneIntersection(-1,rayOri, rayDir)
theTeleporter.teleport( pickResult[1], pickResult[0] )
def controller0Moved():
global controller0
global theTeleporter
if controller0.isTriggerPressed():
cmat = controller0.getWorldMatrix()
rayOri = Pnt3f(cmat[3], cmat[7], cmat[11])
rayDir = Vec3f(-cmat[2], -cmat[6], -cmat[10])
theTeleporter.deactivate()
pickResult = getSceneIntersection(-1,rayOri, rayDir)
theTeleporter.activate()
theTeleporter.updateTeleportLocation(pickResult[1])
def prepareScene( controllerInit = False ):
global controller0
global theTeleporter
if controllerInit:
initControllers = True
if initControllers:
controller0 = vrOpenVRController("Controller0")
controller0.connectSignal("controllerMoved", controller0Moved)
controller0.connectSignal("triggerPressed", trigger0Pressed)
controller0.connectSignal("triggerReleased", trigger0Released)
controller0.setVisible(1)
look = theTeleporter.lookat()
setFromAtUp(-1, 0.0, 0.0, 0.0, look.x(), look.y(), 0.0, 0.0, 0.0, 1.0)
setOpenVRTrackingOrigin( Pnt3f(0.0, 0.0, 0.0))
prepareScene( controllerInit = True )
There should be a Matrix-Transform called "TelePoint" in the scene below which you can put some visualization for where you are going to be teleported.
Hope this is helpful for you.
Kind regards
Michael
Michael Nikelsky
Sr. Principal Engineer