两箱碰撞:VIZARD:PYTHON

时间:2015-02-10 10:05:24

标签: python c vizard

我使用了放置在有两个桌子的环境中的盒子的碰撞。我用鼠标光标抓取对象并放在另一个表中。但是,如果对象之间发生碰撞检测,我将遇到一个问题。当物体和鼠标相互碰撞(最小距离)然后鼠标拾取/链接时,我使用了接近传感器。我也使用相同的传感器进行碰撞,在vizard bt盒的文档中给出的一些物理概念相互碰撞但由于它们的重力飞行。我把密度放在文档中给出的bt我不起作用。然后认为从这个逻辑中移开并尝试其他的东西,我试图形成两个接近的一个用于boxex碰撞,一个用于盒子和鼠标之间但是盒子正在飞行。我使用了与vizard定义的类似的概念,它在那里工作,而不是在块中。请给出一些解决此问题的建议。这里我附加了thre函数 - 一个用于手动,另一个用于链接鼠标和块以及最后放置块。在环境中我已经使用碰撞palne和collission表。所以对于碰撞我应该采用什么方法,因为当我在相同的接近传感器上工作时它将无法工作。所有对象都放在vizard中的原点,然后手动设置在桌面上放置的位置。

global hand
hand = viz.addChild( 'marker.wrl' )
#hand.collidebox()
#xa,ya,za=hand.getPosition()
#hand.collideBox()
hand.enable(viz.COLLIDE_NOTIFY)
#hand.density=0.0000001
#viz.phys.setGravity([0,-1,0])
#vizact.onkeydown(' ', viz.phys.enable)
hand.setPosition( [-7.5, 1.2, -10] )
hand.setEuler(0,0,0)
hand.setScale(0.3,0.3,0.3)
ViewLink = viz.link(hand,viz.MainView)
viz.link(hand,device)
ViewLink.preEuler( [0,25 ,0] )
ViewLink.preTrans( [0,0.2,-0.5] )

    def p_ball(e):

    #    print 'hit'
    #   global sound1 
    #   sound1.play()
        global bn
    #    grab = 1
    #    ball.addAction(blast

    #    b[z].addAction(blast)

        for i in range(len(b)):
        #global xh,zh
        xh,yh,zh=hand.getPosition()
   #        zh= (zh)
   #        print 'abcd'
        xb,yb,zb=b[i].getPosition()
        zb= (abs(zb))
        zh= (abs(zh))
        xb= (abs(xb))
        xh= (abs(xh))
        #print zh,zb

        if (abs(zh-zb)<.4 and abs(xh-xb)<.4):
   #            b[i].addAction(blast)
   #            b[i].visible(viz.OFF)


   #            b[i].visible(viz.ON)

            global link
            if bn==100:
                link = None
                link = viz.grab( hand, b[i] )
                #tool.grabAndHold()
                if link == True:
                    global Block1
                    Pos=Block1.getPosition(MODE=VIZ.REL_GLOBAL)

    #               else:
    #                       print 'aaaaaa'



                bn=i
            #UpdateMovement()
            #UpdateMovement()

            global k
            k=k+1
            tbox2.message(str(k))

/我在这里试了一下,但它不会工作。在这里我使用接近传感器进行盒子碰撞。             xb11,yb11,zb11 = b [0] .getPosition() ####### proximity POSITION 1             print xb11,yb11,zb11

        xb1= (abs(xb11))
        zb1= (abs(zb11))
        print xb1,zb1   


        xb22,yb22,zb22=b[1].getPosition()                            `        `           #######   proximity POSITION   2
        print xb22,yb22,zb22    

        xb2= (abs(xb22))
        zb2= (abs(zb22))
        print xb2,zb2

        xb33,yb33,zb33=b[2].getPosition()                            `              `           #######   proximity POSITION   3
        print xb33,yb33,zb33        

        xb3= (abs(xb33))
        zb3= (abs(zb33))
        print xb3,zb3   

    #       
    #   if ((zb1-zb2)<1.5 or (zb1-zb3)<1.5  or (xb1-xb2)<1.5
        or (xb1-xb3)<1.5):
    #           
    #       print 'Ashish'
    #       global tbox22
    #       tbox22=viz.addTextbox()
    #       tbox22.setPosition(0.11,0.1,0.1)
    #       global touch11
    #       touch11='OBSTACLE-ERROR'
    #       tbox22.message(str(touch11))  
    #           
    #       Block1.setPosition([-7.5,1.1,-2.9])                            `       #######   POSITION OF THE BALLOON`
    #       Block2.setPosition([-7.5,1.1,-1.9])                            `       #######   POSITION OF THE BALLOON`           
    #           
    #           #Block0.setPosition(xb11-1,yb11,zb11-1)                            `        #######   POSITION OF THE BALLOON`
    #           
    #           
    #   elif ((zb2-zb1)<.5 or (zb2-zb3)<.5  or (xb2-xb1)<.5
   or (xb2-xb3)<.5):
    #           
    #       print 'Ashish'
    #       global tbox22           
    #       tbox22=viz.addTextbox()
    #
    #       tbox22.setPosition(0.11,0.1,0.1)
    #       global touch11
    #       touch11='OBSTACLE-ERROR'
    #       tbox22.message(str(touch11))  
    #           
    #       Block0.setPosition([-7.5,1.11,-3.7])                            `       #######   POSITION OF THE BALLOON`
    #       Block2.setPosition([-7.5,1.1,-1.9])                            `       #######   POSITION OF THE BALLOON`                   
    #           
    #           #Block1.setPosition(xb22-1,yb22,zb22-1)                               `       #######   POSITION OF THE BALLOON`            
    #           
    #       
    #   elif ((zb3-zb1)<.5 or (zb3-zb2)<.5  or (xb3-xb1)<.5
        or (xb3-xb2)<.5):`
    #           
    #       print 'Ashish'
    #       global tbox22           
    #       tbox22=viz.addTextbox()
    #
    #       tbox22.setPosition(0.11,0.03,0.1)
    #       global touch11
    #       touch11='OBSTACLE-ERROR'
    #       tbox22.message(str(touch11))  
    #


`#      Block0.setPosition([-7.5,1.11,-3.7])`                                `  
    `#      Block1.setPosition([-7.5,1.1,-2.9])`                                          `     

     #          #Block2.setPosition(xb33-1,yb33,zb33-1)                                         

    #abc()  
    fb()

/块的代码我把碰撞放在与平面/和平面相同的块上,然后用地平面然后重力拉动物体/向下,所以我碰撞了我用的表来输出/ table上的块

   def put_balloons(manager_b,b,b_y,b2):
   #    import vizshape
   #    aa=vizshape.addCube()
   #    aa.setPosition(-7.5,1.1,2.4)
   #    kk=aa.collideBox()
   #    kk.density=100000

/ BLOCK 1 ----------表1         全球Block0

    Block0=viz.addChild('b2.osgb')

    #crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-3.9]) 
    #crate.visible(viz.OFF)
    #crate.collideBox(density=50000000000)
    #crate.alpha(0.3)
    Block0.setPosition(-7.5,1.1,-3.7)
    Block0.setEuler(90,0,0)
    Block0.setScale(.3,.3,.3)
    bs=vizproximity.addBoundingBoxSensor(Block0)
    manager_b.addSensor(bs)
    b.append(Block0)
    #Block0.collideBox()
    Block0.disable(viz.DYNAMICS)
    #   global link 
    #   ss=viz.link(crate,Block0)
    #   ss.preTrans( [-0.17,-0.1,-.1 ])


    #   Block0.enable(viz.RENDERING)

/ BLOCK 2 ----------表1

    global Block1
    Block1=viz.addChild('b7.osgb')

    #crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-3]) 
    #crate.visible(viz.OFF)
    #crate.collideBox(density=50000000000)
    #crate.alpha(0.3)

    Block1.setPosition(-7.5,1.1,-2.9)
    Block1.setEuler(90,0,0)
    Block1.setScale(.3,.3,.3)
    bs=vizproximity.addBoundingBoxSensor(Block1)
    manager_b.addSensor(bs)
    b.append(Block1)
    #Block1.collideBox()
    Block1.disable(viz.DYNAMICS)
    #Block1.enable(viz.RENDERING)

/ BLOCK 3 --------- TABLE

    global Block2
    Block2=viz.addChild('b9.osgb')

    #crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-2.1])                  
    #crate.visible(viz.OFF)
    #crate.collideBox(density=50000000000)
    #crate.alpha(0.3)
    Block2.setPosition(-7.5,1.1,-1.9)
    Block2.setEuler(90,0,0)
    Block2.setScale(.3,.3,.3)
    bs=vizproximity.addBoundingBoxSensor(Block2)
    manager_b.addSensor(bs)
    b.append(Block2)
    Block2.collideBox()
    #Block2.density=0.0000001

    Block2.disable(viz.DYNAMICS)
    #Block2.enable(viz.RENDERING)

/ BLOCK 1 ---------- TABLE2

    global Block00
    Block00=viz.addChild('b2.osgb')
    Block00.setPosition(-7.5,1.15,4)
    Block00.setEuler(90,0,0)
    Block00.setScale(.3,.01,.3)    #.025,.0004,.02,
    b2.append(Block00)

/ BLOCK 2 ---------- TABLE2         全球Block11
        Block11 = viz.addChild( 'b7.osgb')         Block11.setPosition(-7.5,1.15,5)         Block11.setEuler(90,0,0)         Block11.setScale(0.3,.01,0.3)         b2.append(Block11)

/ BLOCK 3 ---------- TABLE3
        全球Block22         Block22 = viz.addChild( 'b9.osgb')         Block22.setPosition(-7.5,1.1,6)         Block22.setEuler(90,0,0)         Block22.setScale(0.3,.01,0.3)         b2.append(Block22)         #

    #viz.phys.setGravity(0,-9) #Sets the Y plane gravity to -2


    put_balloons(manager_b,b,b_y,b2)

0 个答案:

没有答案