PDA

View Full Version : Physics Problem


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)

Jeff
03-12-2009, 10:00 AM
Thanks for the post. You question has not been overlooked.

Sandro Holzer
03-20-2009, 12:53 AM
Thank you Jeff.

Just to make my thing a little bit clearer.
In the end I want to model something like a forklift, just with a different way to move the forks.
And I donīt want to use the physic engine to move the parts on the machine (no Physic Joints), just to model the interaction between the forks and the load.
So all parts that are attached to the machine should not be affected by forces, they should just act as collideable bodies, and are moved with setEuler() and so on, every 0,02 seconds, like in the small code I posted.
The only parts that should be affected by forces are the loads, which you can lift or shift around.

I hope this makes it easier for you to understand my purpose.

Sandro

Gladsomebeast
03-20-2009, 01:07 PM
Sound like you want to call forklift.disable(viz.DYNAMICS). With this function the forklift collide shapes will push/lift the boxes, but no dynamic forces will move the forklift.

Also, from your code I see that you are creating collide shapes on "bars" that are not children of viz.WORLD. This is a problem. The physics engine assumes collide shapes live on nodes that are children of viz.WORLD. If the collide shapes are not associated with direct children of viz.WORLD, then the collide shapes will not be properly positioned on the nodes if the nodes are not at position (0,0,0).

To fix, set up your forklift geometry, making sub-nodes children of some common parent node, we'll call ''forklift''. Then call forklift.collideMesh(), assuming "forklift" is a child of viz.WORLD. With the collideMesh command you can also forgo the disable(viz.DYNAMICS) command because the physics engine does not support dynamic forces on collideMesh shapes so they will not be applied anyway.

Sandro Holzer
03-29-2009, 10:51 PM
Thank You Gladsomebeast

I will try to work with the suggestions you made.

Sandro