WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-16-2008, 01:50 PM
joeymax joeymax is offline
Member
 
Join Date: Apr 2007
Location: England
Posts: 11
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)
Attached Files
File Type: zip joey_scene.zip (3.5 KB, 490 views)
Reply With Quote
  #2  
Old 04-17-2008, 03:33 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You can enabled viewpoint collision detection by using the following code:
Code:
viz.collision(1)
If you don't want the viewpoint to collide with the blueglass, then add the following line as well:
Code:
blueglass.disable(viz.INTERSECTION)
Also, I noticed that you set the eyeheight to 10000 in the script stage settings. You should set it to a smaller value like 1.8.
Reply With Quote
  #3  
Old 04-17-2008, 03:49 PM
joeymax joeymax is offline
Member
 
Join Date: Apr 2007
Location: England
Posts: 11
thankyou so much! thats really helped me out.
works perfect
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
physics engine exception ad_astra Vizard 3 03-25-2009 12:31 PM
Collision detection with haptic pen mjabon Vizard 3 01-17-2008 07:35 PM
Collision between two meshes? v-Salik Vizard 1 12-07-2007 10:31 AM
Collision with avatars and scene not working JvdBosch Vizard 12 09-14-2006 07:01 PM
collision events trigger Eunice Vizard 1 01-03-2006 11:39 AM


All times are GMT -7. The time now is 04:24 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC