Class ODE::Contact
In: ext/body.c  (CVS)
lib/ode/contact.rb  (CVS)
Parent: Object

The contact class.

Methods

allocate   depth   depth=   fdir1   fdir1=   geom1   geom1=   geom2   geom2=   geometries   geometries=   inspect   new   normal   normal=   pos   pos=   surface   surface=   to_s  

Public Class methods

allocate() — Create a contact (collision) object.

[Source]

/*
 * allocate()
 * --
 * Create a contact (collision) object.
 */
static VALUE
ode_contact_s_alloc( klass )
	 VALUE klass;
{
	debugMsg(( "Wrapping an uninitialized ODE::Contact pointer." ));
	return Data_Wrap_Struct( klass, ode_contact_gc_mark, ode_contact_gc_free, 0 );
}

initialize( pos=nil, normal=nil, depth=nil, geom1=nil, geom2=nil ) — Instantiate and return a new ODE::Contact object, optionally filling in the specified parts of the contact geometry.

[Source]

/*
 * initialize( pos=nil, normal=nil, depth=nil, geom1=nil, geom2=nil )
 * --
 * Instantiate and return a new ODE::Contact object, optionally filling in the
 * specified parts of the contact geometry.
 */
static VALUE
ode_contact_init( argc, argv, self )
	 int	argc;
	 VALUE	*argv, self;
{
	int		argCount;
	VALUE	pos, normal, depth, g1, g2;

	debugMsg(( "ODE::Contact init." ));

	if ( !check_contact(self) ) {
		ode_CONTACT *ptr;

		DATA_PTR(self) = ptr = ode_contact_alloc();
		ptr->object = self;

		/* Create a new surface object and add that to the new object's surface
		   member. */
		ptr->surface = rb_class_new_instance( 0, 0, ode_cOdeSurface );

		/* Allocate and fill the mid-level struct */
		ptr->contact = ALLOC( dContact );
		ptr->contact->surface = *(ode_get_surface( ptr->surface ));
		ptr->contact->fdir1[0] = 0.f;
		ptr->contact->fdir1[1] = 0.f;
		ptr->contact->fdir1[2] = 0.f;

		/* Set the pointer to the bottom struct to NULL, as it should be filled
		   in by a geometry later. */
		MEMZERO( &ptr->contact->geom, dContactGeom, 1 );

		return self;
	}

	/* If there are initializer arguments, call the accessors to set the ones provided. */
	if (( argCount = rb_scan_args(argc, argv, "05", &pos, &normal, &depth, &g1, &g2) )) {
		if ( pos )		rb_funcall( self, rb_intern("pos="), 1, &pos );
		if ( normal )	rb_funcall( self, rb_intern("normal="), 1, &normal );
		if ( depth )	rb_funcall( self, rb_intern("depth="), 1, &depth );
		if ( g1 )		rb_funcall( self, rb_intern("geom1="), 1, &g1 );
		if ( g2 )		rb_funcall( self, rb_intern("geom2="), 1, &g2 );
	}


	debugMsg(( "Calling super()" ));
	rb_call_super( 0, 0 );
	debugMsg(( "Back from super()" ));

	return self;
}

Public Instance methods

depth — Return the depth to which the two bodies inter-penetrate each other. If the depth is zero then the two bodies have a grazing contact, i.e. they "only just" touch. However, this is rare - the simulation is not perfectly accurate and will often step the bodies too far so that the depth is nonzero.

[Source]

/*
 * depth
 * --
 * Return the depth to which the two bodies inter-penetrate each other. If the
 * depth is zero then the two bodies have a grazing contact, i.e. they "only
 * just" touch. However, this is rare - the simulation is not perfectly accurate
 * and will often step the bodies too far so that the depth is nonzero.
 */
static VALUE
ode_contact_depth( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	return rb_float_new( ptr->contact->geom.depth );
}

depth=( depth ) — Set the penetration depth of the contact.

[Source]

/*
 * depth=( depth )
 * --
 * Set the penetration depth of the contact.
 */
static VALUE
ode_contact_depth_eq( self, depth )
	 VALUE self, depth;
{
	ode_CONTACT *ptr = get_contact( self );
	ptr->contact->geom.depth = (dReal)NUM2DBL( depth );
	return rb_float_new( ptr->contact->geom.depth );
}

fdir1 — Returns the "first friction direction" vector that defines a direction along which frictional force is applied if the contact’s surfaceuseFrictionDirection? flag is true. If useFrictionDirection? is false, this setting is unused, though it can still be set.

[Source]

/*
 * fdir1
 * --
 * Returns the "first friction direction" vector that defines a direction along
 * which frictional force is applied if the contact's
 * surface#useFrictionDirection? flag is true. If useFrictionDirection? is
 * false, this setting is unused, though it can still be set.
 */
static VALUE
ode_contact_fdir1( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE		fdir1;

	check_contact_geom( ptr );
	Vec3ToOdeVector( ptr->contact->fdir1, fdir1 );

	return fdir1;
}

fdir1=( vector ) — Sets the "first friction direction" vector that defines a direction along which frictional force is applied if the contact’s surfaceuseFrictionDirection? flag is true. If useFrictionDirection? is false, this setting is unused, though it can still be set.

[Source]

/*
 * fdir1=( vector )
 * --
 * Sets the "first friction direction" vector that defines a direction along
 * which frictional force is applied if the contact's
 * surface#useFrictionDirection? flag is true. If useFrictionDirection? is
 * false, this setting is unused, though it can still be set.
 */
static VALUE
ode_contact_fdir1_eq( self, direction )
	 VALUE	self, direction;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE		fdirAry = ode_obj_to_ary3( direction, "direction" );
	
	SetVec3FromArray( ptr->contact->fdir1, fdirAry );
	
	return fdirAry;
}

geom1 — Returns one of the pair of geometry objects (a deriviative of ODE::Geometry)involved in the collision.

[Source]

/*
 * geom1
 * --
 * Returns one of the pair of geometry objects (a deriviative of
 * ODE::Geometry)involved in the collision.
 */
static VALUE
ode_contact_geom1( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	ode_GEOMETRY *geom;

	geom = (ode_GEOMETRY *)dGeomGetData( ptr->contact->geom.g1 );
	return geom->object;
}

geom1=( geometry ) — Sets one of the pair of geometry objects involved in the collision to the specified geometry (a deriviative of ODE::Geometry).

[Source]

/*
 * geom1=( geometry )
 * --
 * Sets one of the pair of geometry objects involved in the collision to the
 * specified <tt>geometry</tt> (a deriviative of ODE::Geometry).
 */
static VALUE
ode_contact_geom1_eq( self, geometry )
	 VALUE	self, geometry;
{
	ode_CONTACT		*ptr = get_contact( self );
	ode_GEOMETRY	*geom = ode_get_geom( geometry );

	ptr->contact->geom.g1 = geom->id;
	return geom->object;
}

geom2 — Returns one of the pair of geometry objects (a deriviative of ODE::Geometry)involved in the collision.

[Source]

/*
 * geom2
 * --
 * Returns one of the pair of geometry objects (a deriviative of
 * ODE::Geometry)involved in the collision.
 */
static VALUE
ode_contact_geom2( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	ode_GEOMETRY *geom;

	geom = (ode_GEOMETRY *)dGeomGetData( ptr->contact->geom.g2 );
	return geom->object;
}

geom2=( geometry ) — Sets one of the pair of geometry objects involved in the collision to the specified geometry (a deriviative of ODE::Geometry).

[Source]

/*
 * geom2=( geometry )
 * --
 * Sets one of the pair of geometry objects involved in the collision to the
 * specified <tt>geometry</tt> (a deriviative of ODE::Geometry).
 */
static VALUE
ode_contact_geom2_eq( self, geometry )
	 VALUE	self, geometry;
{
	ode_CONTACT		*ptr = get_contact( self );
	ode_GEOMETRY	*geom = ode_get_geom( geometry );

	ptr->contact->geom.g2 = geom->id;
	return geom->object;
}

geometries — Returns both geometry objects (ODE::Geometry deriviatives) involved in the collision as an Array.

[Source]

/*
 * geometries
 * --
 * Returns both geometry objects (ODE::Geometry deriviatives) involved in the
 * collision as an Array.
 */
static VALUE
ode_contact_geom_ary( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	ode_GEOMETRY *geom1, *geom2;

	geom1 = (ode_GEOMETRY *)dGeomGetData( ptr->contact->geom.g1 );
	geom2 = (ode_GEOMETRY *)dGeomGetData( ptr->contact->geom.g2 );

	return rb_ary_new3( 2, geom1->object, geom2->object );
}

geometries=( g1, g2 ) — Sets both geometry objects (ODE::Geometry deriviatives) involved in the collision.

[Source]

/*
 * geometries=( g1, g2 )
 * --
 * Sets both geometry objects (ODE::Geometry deriviatives) involved in the
 * collision.
 */
static VALUE
ode_contact_geom_ary_eq( self, args )
	 VALUE	self, args;
{
	ode_CONTACT		*ptr = get_contact( self );
	VALUE			geom1, geom2;
	ode_GEOMETRY	*g1, *g2;

	/* Check to be sure 2 args were given */
	if ( RARRAY(args)->len != 2 )
		rb_raise( rb_eArgError, "wrong number of arguments (%d for 2)",
				  RARRAY(args)->len );

	/* Fetch what is needed from the arguments */
	geom1 = *(RARRAY(args)->ptr);
	g1 = ode_get_geom( geom1 );
	geom2 = *(RARRAY(args)->ptr+1);
	g2 = ode_get_geom( geom2 );

	/* Set the geometries in the inner structs */
	ptr->contact->geom.g1 = g1->id;
	ptr->contact->geom.g2 = g2->id;

	return rb_ary_new3( 2, geom1, geom2 );
}

Returns a string containing a human-readable representation of the contact, oriented towards debugging or tracing.

[Source]

# File lib/ode/contact.rb, line 44
        def inspect
            "<%s 0x%x: surface=%s, geom1=%s, geom2=%s>" % [
                self.class.name,
                self.object_id * 2,
                self.surface.inspect,
                self.geom1.inspect,
                self.geom2.inspect
            ]
        end

normal — Get the normal vector (as an ODE::Vector), which is a unit length vector that is, generally speaking, perpendicular to the contact surface.

[Source]

/*
 * normal
 * --
 * Get the normal vector (as an ODE::Vector), which is a unit length vector that
 * is, generally speaking, perpendicular to the contact surface.
 */
static VALUE
ode_contact_normal( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE		normal;

	check_contact_geom( ptr );
	Vec3ToOdeVector( ptr->contact->geom.normal, normal );

	return normal;
}

normal=( normal ) — Set the contact’s normal vector to normal which can be any object which returns three numbers when to_ary is called on it (eg., an ODE::Vector, an Array of three numbers, etc.).

[Source]

/*
 * normal=( normal )
 * --
 * Set the contact's normal vector to <tt>normal</tt> which can be any object
 * which returns three numbers when #to_ary is called on it (eg., an
 * ODE::Vector, an Array of three numbers, etc.).
 */
static VALUE
ode_contact_normal_eq( self, normal )
	 VALUE	self, normal;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE		normalAry = ode_obj_to_ary3( normal, "contact normal" );
	
	SetVec3FromArray( ptr->contact->geom.normal, normalAry );
	
	return normalAry;
}

pos — Returns the position of the contact in global coordinates as an ODE::Position object.

[Source]

/*
 * pos
 * --
 * Returns the position of the contact in global coordinates as an ODE::Position
 * object.
 */
static VALUE
ode_contact_pos( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE		pos;

	check_contact_geom( ptr );
	Vec3ToOdePosition( ptr->contact->geom.pos, pos );

	return pos;
}

pos=( position ) — Set the position of the contact in global coordinates to the specified position, which can be any object which returns an Array of three numbers when to_ary is called on it (eg., Array, ODE::Vector, ODE::Position, etc.).

[Source]

/*
 * pos=( position )
 * --
 * Set the position of the contact in global coordinates to the specified
 * <tt>position</tt>, which can be any object which returns an Array of three
 * numbers when #to_ary is called on it (eg., Array, ODE::Vector, ODE::Position,
 * etc.).
 */
static VALUE
ode_contact_pos_eq( self, newPos )
	 VALUE	self, newPos;
{
	ode_CONTACT *ptr = get_contact( self );
	VALUE posAry = ode_obj_to_ary3( newPos, "position" );

	SetVec3FromArray( ptr->contact->geom.pos, posAry );

	return posAry;
}

surface — Fetch the object that describes the properties of the colliding surfaces (an ODE::Surface object).

[Source]

/*
 * surface
 * --
 * Fetch the object that describes the properties of the colliding surfaces (an
 * ODE::Surface object).
 */
static VALUE
ode_contact_surface( self )
	 VALUE	self;
{
	ode_CONTACT *ptr = get_contact( self );
	return ptr->surface;
}

surface=( newSurface ) — Set the surface parameters of the collision to the specified newSurface (an ODE::Surface object).

[Source]

/*
 * surface=( newSurface )
 * --
 * Set the surface parameters of the collision to the specified
 * <tt>newSurface</tt> (an ODE::Surface object).
 */
static VALUE
ode_contact_surface_eq( self, surface )
	 VALUE	self, surface;
{
	ode_CONTACT			*ptr = get_contact( self );
	dSurfaceParameters	*surfacePtr = ode_get_surface( surface );

	ptr->surface = surface;
	ptr->contact->surface = *surfacePtr;

	return surface;
}

Return a human-readable string oriented towards english descriptions.

[Source]

# File lib/ode/contact.rb, line 57
        def to_s
            "contact between a %s and a %s at %s (depth = %0.2f)" % [
                self.geom1.to_s,
                self.geom2.to_s,
                self.pos.to_s,
                self.depth,
            ]
        end

[Validate]