WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   collision with physics enabled (https://forum.worldviz.com/showthread.php?t=1449)

joeymax 04-16-2008 12:50 PM

collision with physics enabled
 
1 Attachment(s)
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. :o

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)


farshizzo 04-17-2008 02:33 PM

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.

joeymax 04-17-2008 02:49 PM

thankyou so much! thats really helped me out.
works perfect :)


All times are GMT -7. The time now is 11:51 AM.

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