![]() |
#1
|
|||
|
|||
collision with physics enabled
Hi there, I have created a simple scene with physics enabled. In my scene I have a few objects; ball.wrl, blueglass.osg, greenwalls.osg
What I want to do is apply some sort of collision to the scene, so that I am able to walk through ‘blueglass’, but not through ‘greenwall’. The ‘ball’ object translates with the viewpoint, so it goes wherever I go, that way, when I walk through the blueglass object in the scene, the ball collides with blueglass and triggers an event (in this case it simply prints a message). I have not been able to find a way to apply collision to ‘greenwall’ to stop me from walking through it – while physics are enabled. ![]() Any help would be much appreciated Code:
import viz viz.phys.enable() viz.go() theview = viz.get(viz.MAIN_VIEWPOINT) theview.translate(0,1.4,0) greenwall = viz.add('greenwall.osg') blueglass = viz.add('blueglass.osg') ball = viz.add('ball.wrl') ball.setScale(0.1,0.1,0.1) ball_Link = viz.link(theview,ball) ball_Link.preTrans([0,0,2]) greenwall.collideMesh() greenwall.disable(viz.DYNAMICS) greenwall.enable(viz.COLLIDE_NOTIFY) ball.collideMesh() ball.disable(viz.DYNAMICS) ball.enable(viz.COLLIDE_NOTIFY) blueglass.collideMesh() blueglass.disable(viz.DYNAMICS) blueglass.enable(viz.COLLIDE_NOTIFY) MOVE_SPEED = 5 TURN_SPEED = 70 def onCollideBegin(e): if e.obj1 == ball and e.obj2 == greenwall: print 'ball has hit greenwall' if e.obj1 == ball and e.obj2 == blueglass: print 'ball has hit blueglass' def mytimer(num): if viz.iskeydown(viz.KEY_UP): theview.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_ORI) elif viz.iskeydown(viz.KEY_DOWN): theview.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI) if viz.iskeydown(viz.KEY_RIGHT): theview.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD) elif viz.iskeydown(viz.KEY_LEFT): theview.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD) viz.callback(viz.TIMER_EVENT,mytimer) viz.starttimer(0,0.01,viz.FOREVER) viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin) viz.clearcolor(viz.WHITE) |
#2
|
|||
|
|||
You can enabled viewpoint collision detection by using the following code:
Code:
viz.collision(1) Code:
blueglass.disable(viz.INTERSECTION) |
#3
|
|||
|
|||
thankyou so much! thats really helped me out.
works perfect ![]() |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
physics engine exception | ad_astra | Vizard | 3 | 03-25-2009 11:31 AM |
Collision detection with haptic pen | mjabon | Vizard | 3 | 01-17-2008 06:35 PM |
Collision between two meshes? | v-Salik | Vizard | 1 | 12-07-2007 09:31 AM |
Collision with avatars and scene not working | JvdBosch | Vizard | 12 | 09-14-2006 06:01 PM |
collision events trigger | Eunice | Vizard | 1 | 01-03-2006 10:39 AM |