PDA

View Full Version : HELP HELP in Collision of Boxes


ashish00
02-09-2015, 10:22 PM
### I use the collision with the mouse as it grabs the object. The problems ##comes when these two objects collide then mouse starts flying I control ###that part by repeatedly calling the mouse to the fixed position ## (coordinates). Serious prob come when object grab by the mouse hits the #other object then that object satrts flying. i see the documentation about the #density but it wont works here i put it around 1 million. So here in this #position I don not do anything PLEASE HELP pLEASE HELP
##


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]) ####### POSITION OF THE BALLOON
# Block1.setPosition([-7.5,1.1,-2.9]) ####### POSITION OF THE BALLOON
#
# #Block2.setPosition(xb33-1,yb33,zb33-1) ####### POSITION OF THE BALLOON

#abc()
fb()

############# code for blocks i put the collision with the blocks same ##i put with plane and tables while with ground plane thw gravity pulls the ##object downwards so i collision i used with the tables to put the blocks on #the 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---------- TABLE 1
global Block0

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


#crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-3.9], scale=[.22,.13,.22])
#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---------- TABLE 1

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

#crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-3], scale=[.22,.13,.22])
#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 1

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

#crate = viz.addChild('crate.osgb',pos=[-7.38,1.2,-2.1], scale=[.22,.13,.22])
#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
global Block11
Block11=viz.addChild('b7.osgb')
Block11.setPosition(-7.5,1.15,5)
Block11.setEuler(90,0,0)
Block11.setScale(.3,.01,.3)
b2.append(Block11)

########################################### BLOCK 3----------TABLE3
global Block22
Block22=viz.addChild('b9.osgb')
Block22.setPosition(-7.5,1.1,6)
Block22.setEuler(90,0,0)
Block22.setScale(.3,.01,.3)
b2.append(Block22)
#
#viz.phys.setGravity(0,-9) #Sets the Y plane gravity to -2


put_balloons(manager_b,b,b_y,b2)

Jeff
02-10-2015, 08:38 AM
Please follow the guidelines for posting Vizard code (http://forum.worldviz.com/faq.php?faq=vb3_reading_posting#faq_faq_vizard_cod e). This will make it easier for others to understand and help with the issue.