Sandro Holzer
03-09-2009, 08:07 AM
Hello Everybody
I have a problem with the Physic Engine.
In the following code I want to push away the red box (seesaw from tutorial) with the last of the 3 bars, which are moveable by pressing the keys.
Is this possible with the moving of the bars controlled by their angles?
import viz
viz.go()
viz.phys.enable()
viz.clearcolor(0.1,0.1,1)
ground = viz.add('tut_ground.wrl')
ground.collidePlane()
ANCHOR_POS= (0.6,1.8005,6)
bar1 = viz.add('bar2.obj',pos=ANCHOR_POS)
bar2 = bar1.add('bar2.obj')
bar2.translate([0.0,0.0,-1])
bar3 = bar2.add('bar2.obj')
bar3.translate([0.0,0.0,-1])
bar3.collideBox()
bar3.disable(viz.DYNAMICS)
seesaw = viz.add( 'box.wrl' )
seesaw.scale( 1, 1, 1 )#
seesaw.translate(0,3,5)
seesaw.collideBox(bounce=0.8)
a = 0
b = 0
c = 0
def mytimer(num):
global a,b,c
if viz.iskeydown('t'):
a = a + 1
if a > 89:
a = 89
move()
if viz.iskeydown('b'):
a = a - 1
if a < -89:
a = -89
move()
if viz.iskeydown('f'):
b = b + 1
if b > 89:
b = 89
move()
if viz.iskeydown('h'):
b = b - 1
if b < -89:
b = -89
move()
if viz.iskeydown('z'):
c = c + 1
if c > 89:
c = 89
move()
if viz.iskeydown('n'):
c = c - 1
if c < -89:
c = -89
move()
def move():
euler = bar1.getEuler(viz.ABS_GLOBAL)
euler[0] = a
bar1.setEuler(euler,viz.ABS_GLOBAL)
euler = bar2.getEuler(viz.ABS_GLOBAL)
euler[1] = b
bar2.setEuler(euler,viz.ABS_GLOBAL)
euler = bar3.getEuler(viz.ABS_GLOBAL)
euler[1] = c
bar3.setEuler(euler,viz.ABS_GLOBAL)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)
I have a problem with the Physic Engine.
In the following code I want to push away the red box (seesaw from tutorial) with the last of the 3 bars, which are moveable by pressing the keys.
Is this possible with the moving of the bars controlled by their angles?
import viz
viz.go()
viz.phys.enable()
viz.clearcolor(0.1,0.1,1)
ground = viz.add('tut_ground.wrl')
ground.collidePlane()
ANCHOR_POS= (0.6,1.8005,6)
bar1 = viz.add('bar2.obj',pos=ANCHOR_POS)
bar2 = bar1.add('bar2.obj')
bar2.translate([0.0,0.0,-1])
bar3 = bar2.add('bar2.obj')
bar3.translate([0.0,0.0,-1])
bar3.collideBox()
bar3.disable(viz.DYNAMICS)
seesaw = viz.add( 'box.wrl' )
seesaw.scale( 1, 1, 1 )#
seesaw.translate(0,3,5)
seesaw.collideBox(bounce=0.8)
a = 0
b = 0
c = 0
def mytimer(num):
global a,b,c
if viz.iskeydown('t'):
a = a + 1
if a > 89:
a = 89
move()
if viz.iskeydown('b'):
a = a - 1
if a < -89:
a = -89
move()
if viz.iskeydown('f'):
b = b + 1
if b > 89:
b = 89
move()
if viz.iskeydown('h'):
b = b - 1
if b < -89:
b = -89
move()
if viz.iskeydown('z'):
c = c + 1
if c > 89:
c = 89
move()
if viz.iskeydown('n'):
c = c - 1
if c < -89:
c = -89
move()
def move():
euler = bar1.getEuler(viz.ABS_GLOBAL)
euler[0] = a
bar1.setEuler(euler,viz.ABS_GLOBAL)
euler = bar2.getEuler(viz.ABS_GLOBAL)
euler[1] = b
bar2.setEuler(euler,viz.ABS_GLOBAL)
euler = bar3.getEuler(viz.ABS_GLOBAL)
euler[1] = c
bar3.setEuler(euler,viz.ABS_GLOBAL)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.02,viz.FOREVER)