Class ODE::Joint
In: ext/body.c  (CVS)
Parent: Object

Methods

Public Class methods

allocate() — Allocate a new ODE::Joint object.

[Source]

/*
 * allocate()
 * --
 * Allocate a new ODE::Joint object.
 */
static VALUE
ode_joint_s_alloc( klass )
{
	if ( klass == ode_cOdeJoint || klass == ode_cOdeParamJoint )
		rb_raise( rb_eScriptError, "Instantiation attempted of abstract class." );

	debugMsg(( "Wrapping an uninitialized ODE::Joint pointer." ));
	return Data_Wrap_Struct( klass, ode_joint_gc_mark, ode_joint_gc_free, 0 );
}

Public Instance methods

ODE::Joint#attach( body1, body2 ) — Attach the specified bodies (ODE::Body objects) with the receiving joint. If the joint is already attached, it will be detached from the old bodies first. To attach this joint to only one body, set body1 or body2 to nil - a nil body refers to the static environment. Setting both bodies to nil puts the joint into "limbo", i.e. it will have no effect on the simulation.

[Source]

/*
 * ODE::Joint#attach( body1, body2 )
 * --
 * Attach the specified bodies (ODE::Body objects) with the receiving joint. If
 * the joint is already attached, it will be detached from the old bodies
 * first. To attach this joint to only one body, set body1 or body2 to
 * <tt>nil</tt> - a <tt>nil</tt> body refers to the static environment. Setting
 * both bodies to <tt>nil</tt> puts the joint into "limbo", i.e. it will have no
 * effect on the simulation.
 */
static VALUE
ode_joint_attach( self, body1, body2 )
	 VALUE self, body1, body2;
{
	ode_JOINT	*ptr = get_joint( self );
	ode_BODY	*body1Ptr, *body2Ptr;
	dBodyID		body1Id, body2Id;

	if ( body1 == Qnil ) {
		body1Id = 0;
	} else {
		body1Ptr = ode_get_body( body1 );
		body1Id	 = body1Ptr->id;
	}

	if ( body2 == Qnil ) {
		body2Id = 0;
	} else {
		body2Ptr = ode_get_body( body2 );
		body2Id	 = body2Ptr->id;
	}

	/* :TODO: Perhaps add callbacks into any bodies being detached? */

	dJointAttach( ptr->id, body1Id, body2Id );
	ptr->body1 = body1;
	ptr->body2 = body2;

	return Qtrue;
}

ODE::Joint#attachedBodies() — Return an Array containing the two bodies which the recieving joint attaches, if any.

[Source]

/*
 * ODE::Joint#attachedBodies()
 * --
 * Return an Array containing the two bodies which the recieving joint attaches,
 * if any.
 */
static VALUE
ode_joint_attached_bodies( self )
	 VALUE self;
{
	ode_JOINT	*ptr = get_joint( self );

	if ( ptr->body1 )
		return rb_ary_new3( 2, ptr->body1, ptr->body2 );
	else
		return rb_ary_new2( 0 );
}

ODE::Joint#feedback — Get the feedback hash for the receiving joint. This hash will be updated every time step with the torque and force applied to the attached bodies if feedback is enabled for the receiving joint. If feedback is not enabled, the hash will be empty.

[Source]

/*
 * ODE::Joint#feedback
 * --
 * Get the feedback hash for the receiving joint. This hash will be updated
 * every time step with the torque and force applied to the attached bodies if
 * feedback is enabled for the receiving joint. If feedback is not enabled, the
 * hash will be empty.
 */
static VALUE
ode_joint_get_feedback( self )
	 VALUE	self;
{
	VALUE		fbhash;
	ode_JOINT	*ptr = get_joint( self );

	if ( ! ptr->feedback ) return Qnil;

	fbhash = ode_joint_get_feedback_hash( ptr );

	/* If the feedback struct is being populated, update the hash with its data. */
	if ( ptr->feedback ) {
		VALUE b1hash, b2hash;
		VALUE b1Force, b2Force, b1Torque, b2Torque;

		b1hash = rb_hash_aref( fbhash, body1Sym );
		b2hash = rb_hash_aref( fbhash, body2Sym );

		b1Force  = rb_hash_aref( b1hash, forceSym );
		b1Torque = rb_hash_aref( b1hash, torqueSym );
		b2Force  = rb_hash_aref( b2hash, forceSym );
		b2Torque = rb_hash_aref( b2hash, torqueSym );

		SetOdeVectorFromVec3( ptr->feedback->f1, b1Force );
		SetOdeVectorFromVec3( ptr->feedback->t1, b1Torque );
		SetOdeVectorFromVec3( ptr->feedback->f2, b2Force );
		SetOdeVectorFromVec3( ptr->feedback->t2, b2Torque );
	}

	return fbhash;
}

ODE::Joint#feedbackEnabled=( value ) — Enable/disable feedback for this joint. If value is true, feedback will be enabled for the next world step. Returns the status of feedback flag before the call.

[Source]

/*
 * ODE::Joint#feedbackEnabled=( value )
 * --
 * Enable/disable feedback for this joint. If <tt>value</tt> is true, feedback
 * will be enabled for the next world step. Returns the status of feedback flag
 * before the call.
 */
static VALUE
ode_joint_feedback_enabled( self, value )
	 VALUE self, value;
{
	ode_JOINT	*ptr = get_joint( self );
	VALUE		rval = Qfalse;

	/* If feedback is being turned on, allocate a new feedback struct and set it 
	   in the joint as well as our own struct. */
	if ( RTEST(value) ) {
		if ( ! ptr->feedback ) {
			ptr->feedback = ALLOC( dJointFeedback );
			dJointSetFeedback( ptr->id, ptr->feedback );
		} else {
			rval = Qtrue;
		}
	}

	/* Otherwise, unset the feedback struct and free it */
	else if ( ptr->feedback ) {
		dJointSetFeedback( ptr->id, 0 );
		xfree( ptr->feedback );
		ptr->feedback = 0;

		rval = Qtrue;
	}

	return rval;
}

ODE::Joint#feedbackEnabled? — Returns true if feedback is turned on for this joint.

[Source]

/*
 * ODE::Joint#feedbackEnabled?
 * --
 * Returns <tt>true</tt> if feedback is turned on for this joint.
 */
static VALUE
ode_joint_feedback_enabled_p( self )
	 VALUE self;
{
	ode_JOINT	*ptr = get_joint( self );

	if ( ptr->feedback )
		return Qtrue;
	else
		return Qfalse;
}

ODE::Joint#makeObsolete() — Mark the specified ODE::Joint as obsolete (ie., it was a member of an ODE::JointGroup that has been emptied). The object will be useless after this is done.

[Source]

/*
 * ODE::Joint#makeObsolete()
 * --
 * Mark the specified ODE::Joint as obsolete (ie., it was a member of an
 * ODE::JointGroup that has been emptied). The object will be useless after this
 * is done.
 */
static VALUE
ode_joint_make_obsolete( self )
	 VALUE	self;
{
	ode_JOINT *ptr = get_joint( self );

	ptr->obsolete = Qtrue;
	return Qtrue;
}

ODE::Joint#obsolete?() — Returns true if the joint was a member of a ODE::JointGroup that has been emptied. A joint cannot be used if it is marked as obsolete.

[Source]

/*
 * ODE::Joint#obsolete?() 
 * --
 * Returns +true+ if the joint was a member of a ODE::JointGroup that has been
 * emptied. A joint cannot be used if it is marked as obsolete.
 */
static VALUE
ode_joint_obsolete_p( self )
	 VALUE self;
{
	ode_JOINT *ptr = check_joint( self );
	if ( ptr )
		return ptr->obsolete;
	else
		return Qnil;
}

[Validate]