| Path: | examples/worldCollision.rb (CVS) |
| Last Update: | Wed Jul 27 22:48:36 EDT 2005 |
worldCollision.rb
$Id: worldCollision.rb 96 2005-07-28 02:48:31Z ged $ Time-stamp: <04-Feb-2003 03:59:18 deveiant>
This is a little experiment to work out Ruby-idiomish names for the collision methods by implementing the example traversing ‘near’ callback in the docs. It’s not really meant to do anything useful, more just to work out the Ruby idiom for the collision system. It just drops a box onto a sphere.
Authors:
# Michael Granger <ged@FaerieMUD.org>
Copyright © 2002, 2003 The FaerieMUD Consortium.
This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit creativecommons.org/licenses/by/1.0 or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Define a callback method that will handle the 3 kinds of ODE collison: space vs space (intersect), space vs. geom (recursive adjacency), and geom vs. geom (collide).
# File examples/worldCollision.rb, line 52 def nearCallback( geom1, geom2, *args ) if geom1.isSpace? || geom2.isSpace? # Intersect the two geoms, recursing for each pair that could # potentially collide. geom1.intersectWith( geom2, &method(:nearCallback) ) # Collide all geoms internal to the space(s) geom1.eachAdjacentPair( &method(:nearCallback) ) if geom1.isSpace? geom2.eachAdjacentPair( &method(:nearCallback) ) if geom2.isSpace? else # Generate contact points between the two geoms (maximum of 3) geom1.collideWith( geom2, 3 ) {|contact| $stderr.puts "Got %s" % contact.to_s # Set the surface parameters for the contact surface = contact.surface surface.mode = (Contact::Slip1|Contact::Slip2| Contact::SoftERP|Contact::SoftCFM| Contact::Approx1) surface.mu = ODE::Infinity surface.slip1 = 0.1 surface.slip2 = 0.1 surface.soft_erp = 0.5 surface.soft_cfm = 0.3 # Create a new contact joint in the joint group and attach it to the # bodies involved. contactJoint = $contactJoints.createJoint( contact ) contactJoint.attach( contact.geom1.body, contact.geom2.body ) } end end