| Class | ODE::Geometry::CappedCylinder |
| In: |
ext/geometry.c
(CVS)
|
| Parent: | ODE::Geometry::Placeable |
ODE::Geometry::CappedCylinder::new( radius, length, space=nil ) — Create a new capped-cylinder collision geometry with the specified parameters, and insert it into the specified space, if given.
A capped cylinder is like a normal cylinder except it has half-sphere caps at its ends. This feature makes the internal collision detection code particularly fast and accurate. The cylinder’s length, not counting the caps, is given by length. The cylinder is aligned along the geom’s local Z axis. The radius of the caps, and of the cylinder itself, is given by radius.
/*
* ODE::Geometry::CappedCylinder::new( radius, length, space=nil )
* --
* Create a new capped-cylinder collision geometry with the specified
* parameters, and insert it into the specified space, if given.
*
* A capped cylinder is like a normal cylinder except it has half-sphere caps at
* its ends. This feature makes the internal collision detection code
* particularly fast and accurate. The cylinder's length, not counting the caps,
* is given by length. The cylinder is aligned along the geom's local Z
* axis. The radius of the caps, and of the cylinder itself, is given by radius.
*/
static VALUE
ode_geometry_capcyl_init( argc, argv, self )
int argc;
VALUE *argv, self;
{
VALUE radius, length, spaceObj;
dSpaceID space = 0;
ode_GEOMETRY *geometry = 0;
debugMsg(( "Calling super()" ));
rb_call_super( 0, 0 );
debugMsg(( "Back from super()" ));
/* Fetch the ode_GEOMETRY pointer */
geometry = get_geom(self);
if ( !geometry ) rb_bug( "Superclass's initialize didn't return a valid Geometry." );
debugMsg(( "CappedCylinder::initialize: Geometry is <%p>", geometry ));
debugMsg(( "CappedCylinder::initialize: Scanning arguments." ));
if ( rb_scan_args(argc, argv, "21", &radius, &length, &spaceObj) == 3 ) {
SetContainer( spaceObj, space, geometry );
}
CheckPositiveNonZeroNumber( NUM2DBL(radius), "radius" );
CheckPositiveNonZeroNumber( NUM2DBL(length), "length" );
debugMsg(( "Creating new CappedCylinder geometry." ));
geometry->id = (dGeomID)dCreateCCylinder( space,
(dReal)NUM2DBL(radius),
(dReal)NUM2DBL(length) );
/* Set the ode_GEOMETRY pointer as the data pointer of the dGeomID */
dGeomSetData( geometry->id, geometry );
return self;
}
ODE::Geometry::CappedCylinder#length — Get the cylinder’s length.
/*
* ODE::Geometry::CappedCylinder#length
* --
* Get the cylinder's length.
*/
static VALUE
ode_geometry_capcyl_length( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
dGeomCCylinderGetParams( geometry->id, params, params+1 );
return rb_float_new( params[1] );
}
ODE::Geometry::Capcyl#length=( newValue ) — Set the capcyl’s length.
/*
* ODE::Geometry::Capcyl#length=( newValue )
* --
* Set the capcyl's length.
*/
static VALUE
ode_geometry_capcyl_length_eq( self, newLength )
VALUE self, newLength;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
CheckPositiveNonZeroNumber( NUM2DBL(newLength), "length" );
dGeomCCylinderGetParams( geometry->id, params, params+1 );
params[1] = (dReal)NUM2DBL( newLength );
dGeomCCylinderSetParams( geometry->id, params[0], params[1] );
return rb_float_new( params[1] );
}
ODE::Geometry::CappedCylinder#params — Returns the capped cylinder’s params as a 2-element array (radius,length).
/*
* ODE::Geometry::CappedCylinder#params
* --
* Returns the capped cylinder's params as a 2-element array (radius,length).
*/
static VALUE
ode_geometry_capcyl_params( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal radius, length;
dGeomCCylinderGetParams( geometry->id, &radius, &length );
return rb_ary_new3( 2,
rb_float_new(radius),
rb_float_new(length) );
}
ODE::Geometry::CappedCylinder#params=( radius, length ) — Set the capped cylinder’s radius and length to the specified values.
/*
* ODE::Geometry::CappedCylinder#params=( radius, length )
* --
* Set the capped cylinder's <tt>radius</tt> and <tt>length</tt> to the
* specified values.
*/
static VALUE
ode_geometry_capcyl_params_eq( self, args )
VALUE self, args;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal results[2];
/* Unwrap inner array (when called like #params = 1, 2) */
if ( RARRAY(args)->len == 1 ) args = *(RARRAY(args)->ptr);
/* If the args VALUE isn't an array, or is an array with more or less than 2
elements, raise an ArgumentError. */
if ( TYPE(args) != T_ARRAY )
rb_raise( rb_eArgError, "wrong number of arguments (1 for 2)" );
else if ( RARRAY(args)->len != 2 )
rb_raise( rb_eArgError, "wrong number of arguments (%d for 2)",
RARRAY(args)->len );
CheckPositiveNonZeroNumber( NUM2DBL(*(RARRAY(args)->ptr )), "radius" );
CheckPositiveNonZeroNumber( NUM2DBL(*(RARRAY(args)->ptr + 1)), "length" );
dGeomCCylinderSetParams( geometry->id,
(dReal)NUM2DBL(*(RARRAY(args)->ptr )),
(dReal)NUM2DBL(*(RARRAY(args)->ptr + 1)) );
dGeomCCylinderGetParams( geometry->id, results, results+1 );
return rb_ary_new3( 2,
rb_float_new(results[0]),
rb_float_new(results[1]) );
}
ODE::Geometry::CappedCylinder#radius — Get the cylinder’s radius.
/*
* ODE::Geometry::CappedCylinder#radius
* --
* Get the cylinder's radius.
*/
static VALUE
ode_geometry_capcyl_radius( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
dGeomCCylinderGetParams( geometry->id, params, params+1 );
return rb_float_new( params[0] );
}
ODE::Geometry::Capcyl#radius=( newValue ) — Set the capcyl’s radius.
/*
* ODE::Geometry::Capcyl#radius=( newValue )
* --
* Set the capcyl's radius.
*/
static VALUE
ode_geometry_capcyl_radius_eq( self, newRadius )
VALUE self, newRadius;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
CheckPositiveNonZeroNumber( NUM2DBL(newRadius), "radius" );
dGeomCCylinderGetParams( geometry->id, params, params+1 );
params[0] = (dReal)NUM2DBL( newRadius );
dGeomCCylinderSetParams( geometry->id, params[0], params[1] );
return rb_float_new( params[0] );
}