Class ODE::Mass::CappedCylinder
In: ext/mass.c  (CVS)
Parent: ODE::Mass

Methods

new  

Public Class methods

ODE::Mass::CappedCylinder#initialize( density, direction, radius, length[, totalmass] ) — Create and return a capped cylinder Mass object of the given radius and length with the specified density, with the center of mass at (0,0,0) relative to the body. The cylinder’s long axis is oriented along the body’s x, y or z axis according to the value of direction (1=x, 2=y, 3=z). If the optional totalmass parameter is given, adjust the values so the total mass is totalmass before returning.

[Source]

/*
 * ODE::Mass::CappedCylinder#initialize( density, direction, radius, length[, totalmass] )
 * --
 * Create and return a capped cylinder Mass object of the given <tt>radius</tt>
 * and <tt>length</tt> with the specified density, with the center of mass at
 * (0,0,0) relative to the body. The cylinder's long axis is oriented along the
 * body's x, y or z axis according to the value of <tt>direction</tt> (1=x, 2=y,
 * 3=z). If the optional <tt>totalmass</tt> parameter is given, adjust the
 * values so the total mass is <tt>totalmass</tt> before returning.
 */
static VALUE
ode_mass_ccyl_init( argc, argv, self )
	 int	argc;
	 VALUE	*argv, self;
{
	ode_MASS	*ptr;
	VALUE		density, direction, radius, length, totalmass;

	rb_scan_args( argc, argv, "41", &density, &direction, &radius, &length, &totalmass );

	if ( NUM2INT(direction) < 1 || NUM2INT(direction) > 3 )
		rb_raise( rb_eArgError,
				  "Direction argument '%d' out of bounds. Must be between 1 and 3.",
				  NUM2INT(direction) );

	CheckPositiveNonZeroNumber( NUM2DBL(density), "density" );
	CheckPositiveNonZeroNumber( NUM2DBL(radius), "radius" );
	CheckPositiveNonZeroNumber( NUM2DBL(length), "length" );

	rb_call_super( 0, 0 );
	ptr = get_mass( self );

	dMassSetCappedCylinder( ptr->massptr,
							(dReal)NUM2DBL(density),
							NUM2INT(direction),
							(dReal)NUM2DBL(radius),
							(dReal)NUM2DBL(length) );

	/* If a totalmass argument was given, check and set it */
	if ( RTEST(totalmass) ) {
		CheckPositiveNonZeroNumber( NUM2DBL(totalmass), "totalmass" );
		dMassAdjust( ptr->massptr, (dReal)NUM2DBL(totalmass) );
	}

	return self;
}

[Validate]