WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   problem in updating text (https://forum.worldviz.com/showthread.php?t=5006)

SUJITH_KJ 04-06-2014 12:23 AM

problem in updating text
 
Hi,
I have given my code below. In my program when i press 'w', the avatar walks to the position (0,0,5) and collides with box and prints the text 'santhosh'. When i press 'c' the avatar proceeds to the next position (0,0,15) and collides with box1 and prints the text 'sujith'. but the problem is tat the first text 'santhosh' still remains. I want it to vanish wen the avatar collides with the second box. Pls help me. I am doing a project. Pls help me. Thanks a lot

code:
import viz
import vizact
viz.phys.enable()
viz.setMultiSample(4)
viz.fov(60)
viz.go()
male = viz.addAvatar('vcc_male.cfg')
male.scale(3,3,3)

ground = viz.add('tut_ground.wrl')
ground.collidePlane()

env=viz.add(viz.ENVIRONMENT_MAP,'sky.jpg')
dome = viz.add('skydome.dlc')
dome.texture(env)

box = viz.add('box.wrl',scale=[2,2,2],pos=(0,0,5),color = viz.BLUE)
box.collideBox()
box.disable(viz.DYNAMICS)

box1 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(0,0,15),color = viz.RED)
box1.collideBox()
box1.disable(viz.DYNAMICS)

box2 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(-10,0,0),color = viz.RED)
box2.collideBox()
box2.disable(viz.DYNAMICS)

box3 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(-20,0,0),color = viz.RED)
box3.collideBox()
box3.disable(viz.DYNAMICS)

#textScreen = viz.addText('Press a',parent=viz.ORTHO,pos=[400,500,0],fontSize=50)


rHandBox = viz.add('box.wrl',scale=[1,1,1])
rHandBox.collideBox()
rHandBox.disable(viz.DYNAMICS)
rHandBox.enable(viz.COLLIDE_NOTIFY)
rHandLink = viz.link( male.getBone('Bip01 R Foot') , rHandBox )
#tweak the position of the box to cover the hand
rHandLink.preTrans([0.05,-0.5,0])


def onCollideBegin(g):
textScreen = viz.addText('Press a',parent=viz.ORTHO,pos=[400,500,0],fontSize=50)
textScreen.visible(viz.OFF)
if g.obj1 == rHandBox:
if g.obj2 == box:
box.color(viz.RED)
textScreen.message('santhosh')
textScreen.visible(viz.ON)
#textScreen.visible(viz.OFF)
#new=textScreen.message('somethin new')
#textScreen = viz.addText('Press a',parent=viz.ORTHO,pos=[400,500,0],fontSize=50)
#fun=textScreen.removeParent(textScreen)
#viz.callback(viz.COLLIDE_END_EVENT,onCollideBegin )
if g.obj1 == rHandBox:
if g.obj2 == box1:
box1.color(viz.BLUE)
#textScreen.visible(viz.OFF)
textScreen.message('sujith')
textScreen.visible(viz.ON)
#textScreen1 = viz.addText('Press x',parent=viz.ORTHO,pos=[400,500,0],fontSize=50)
if g.obj1 == rHandBox:
if g.obj2 == box2:
box2.color(viz.BLUE)
textScreen = viz.addText('Press c',parent=viz.ORTHO,pos=[100,0,0],fontSize=50)
if g.obj1 == rHandBox:
if g.obj2 == box3:
box3.color(viz.BLUE)
textScreen = viz.addText('Press r',parent=viz.ORTHO,pos=[400,200,0],fontSize=50)
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegi n)


def wukavatar():
walk1 = vizact.walkTo([0,0,5])
male.addAction(walk1)
vizact.onkeydown('w',wukavatar)

def wakavatar():
walk2 = vizact.walkTo([0,0,15])
male.addAction(walk2)
vizact.onkeydown('c',wakavatar)

Frank Verberne 04-08-2014 07:05 AM

First of all, the next time you post your code, put code tags around your code so that indentation is preserved (which is essential for python code). You can do so by copy-pasting the code in the message field, selecting the code, and clicking the # symbol in the message tools. This way, other people can just take the code and run it, without having to figure out the indentation themselves. The chance that you get a timely response increases by doing so.

Second, I noticed that you posted the same question in a different (unrelated) thread. As bad as you would like to get help, there is no need to re-post the same question in a different thread, and especially not in an unrelated thread.

Third, your problem was that with every collision, a new textScreen variable was added, so they got layered instead of changed. I made a global variable for the collision function to solve the problem. Have a look at the manual of Vizard at http://s3.worldviz.com/pdf/Vizard%20...0Book%20R4.pdf. It describes very fundamental parts of Vizard, like the ones you're struggling with.

Code:

import viz
import vizact
viz.phys.enable()
viz.setMultiSample(4)
viz.fov(60)
viz.go()
male = viz.addAvatar('vcc_male.cfg')
male.scale(3,3,3)
ground = viz.add('tut_ground.wrl')
ground.collidePlane()
box = viz.add('box.wrl',scale=[2,2,2],pos=(0,0,5),color = viz.BLUE)
box.collideBox()
box.disable(viz.DYNAMICS)

env=viz.add(viz.ENVIRONMENT_MAP,'sky.jpg')
dome = viz.add('skydome.dlc')
dome.texture(env)
box1 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(0,0,15),color = viz.RED)
box1.collideBox()
box1.disable(viz.DYNAMICS)

box2 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(-10,0,0),color = viz.RED)
box2.collideBox()
box2.disable(viz.DYNAMICS)

box3 = viz.add('box.wrl',scale=[1.5,1.5,1.5],pos=(-20,0,0),color = viz.RED)
box3.collideBox()
box3.disable(viz.DYNAMICS)

rHandBox = viz.add('box.wrl',scale=[1,1,1])
rHandBox.collideBox()
rHandBox.disable(viz.DYNAMICS)
rHandBox.enable(viz.COLLIDE_NOTIFY)
rHandLink = viz.link( male.getBone('Bip01 R Foot') , rHandBox )
#tweak the position of the box to cover the hand
rHandLink.preTrans([0.05,-0.5,0])

global textScreen
textScreen = viz.addText('Press a',parent=viz.ORTHO,pos=[400,500,0],fontSize=50)
textScreen.visible(viz.OFF)

def onCollideBegin(g):
        global textScreen
        if g.obj1 == rHandBox:
                print 'collided'
        if g.obj2 == box:
                box.color(viz.RED)
                textScreen.message('santhosh')
                textScreen.visible(viz.ON)
        if g.obj2 == box1:
                box1.color(viz.BLUE)
                textScreen.message('sujith')
                textScreen.message
        if g.obj2 == box2:
                box2.color(viz.BLUE)
                textScreen = viz.addText('Press c',parent=viz.ORTHO,pos=[100,0,0],fontSize=50)
        if g.obj2 == box3:
                box3.color(viz.BLUE)
                textScreen = viz.addText('Press r',parent=viz.ORTHO,pos=[400,200,0],fontSize=50)
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)

def wukavatar():
        walk1 = vizact.walkTo([0,0,5])
        male.addAction(walk1)

vizact.onkeydown('w',wukavatar)

def walkAvatars():
        walk2 = vizact.walkTo([0,0,15])
        male.addAction(walk2)

vizact.onkeydown('c',walkAvatars)



All times are GMT -7. The time now is 07:52 AM.

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