WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   VizTouch Help! (https://forum.worldviz.com/showthread.php?t=5135)

Majestic12 08-14-2014 04:10 AM

VizTouch Help!
 
Hello!

First of all I would like to say thank you for a wonderful software. I have had hours of fun creating various virtual environments. :)

I have just recently purchased a touch-screen and started exploring the VizTouch module and I have a little issue, maybe you can help!

I have a cube that I want to look around using setEuler. I disabled the regular mouse navigation but I can't seem to figure out how to determine which way I want to rotate. In terms of touch I want this:

Code:

def begin(e):
#Begin touch

def move(e):
#On move, determine which direction it is moving and rotate the around the
cube appropriately. As long as the touch persists, keep rotating slowly.

def end(e):
#End touch

viztouch.onTouchDown(begin)

viztouch.onTouchMove(move)

viztouch.onTouchUp(end)

I tried to do a similar thing with the gestures, but it turned out fairly clunky. I had to do flicks repeatedly and each time would move the view a fixed distance:

Code:

def gesturemethod(typen):
       
if (typen == 'left'):
    #cube.setEuler...
elif (typen == 'right'):
    #cube.setEuler...
elif (typen == 'up'):
    #cube.serEuler...
elif (typen == 'down'):
    #cube.setEuler...

viztouch.onGestureFlick(viztouch.FLICK_UP,gesturemethod, 'up')

viztouch.onGestureFlick(viztouch.FLICK_DOWN,gesturemethod, 'down')

viztouch.onGestureFlick(viztouch.FLICK_RIGHT,gesturemethod, 'right')

viztouch.onGestureFlick(viztouch.FLICK_LEFT,gesturemethod, 'left')

I would like to do a smooth solution with the touch one but I can't seem to figure out how to do it smoothly. I would be appreciative of any help I can get in this! How do I determine which way a touch is moving and then set the euler accordingly?

Thanks!!
M12

Majestic12 08-14-2014 05:39 AM

Oh, and to add, Flicks Up or Down don't seem to trigger for me. I only got them to trigger twice (I used prints to test this). Left and Right work just fine.

Jeff 08-15-2014 02:02 PM

The following example rotates different cubes using viztouch move events. In order to activate move on a cube the first touch event must intersect with it's geometry:

Code:

import viz
import vizshape
import viztouch

viz.go()

dojo = viz.addChild('dojo.osgb')
redCube = vizshape.addCube(pos=[-1,1.8,6],color=viz.RED)
blueCube = vizshape.addCube(pos=[1,1.8,6],color=viz.BLUE)

viztouch.setMode(viztouch.MODE_TOUCH)

class ShapeSpinner(object):

        def __init__(self, model):
               
                self.model = model
                self.last_pos = []
               
                self.touchDown_event = viztouch.onTouchDown(self.beginTouch)       
                self.touchMove_event = viztouch.onTouchMove(self.moveTouch)
                self.touchUp_event = viztouch.onTouchUp(self.endTouch)
                self.touchMove_event.setEnabled(viz.OFF)

        def beginTouch(self, e):
               
                pos = e.pos.normalized
               
                #If begin touch intersects model enable movement
                if  viz.pick(pos=pos) == self.model:
                        self.touchMove_event.setEnabled(viz.ON)
                        self.last_pos = pos
               
        def moveTouch(self,e):

                pos = e.pos.normalized
               
                if pos[0] > self.last_pos[0]:
                        self.model.setEuler([-0.4,0.0,0],viz.REL_LOCAL)
                elif pos[0] < self.last_pos[0]:
                        self.model.setEuler([0.4,0.0,0],viz.REL_LOCAL)
                       
                self.last_pos = pos
               
        def endTouch(self,e):
               
                self.touchMove_event.setEnabled(viz.OFF)
               
               
ShapeSpinner(redCube)
ShapeSpinner(blueCube)
       
viz.mouse(viz.OFF)



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

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