| Class | ODE::Geometry::Cylinder |
| In: |
ext/geometry.c
(CVS)
|
| Parent: | ODE::Geometry::Placeable |
ODE::Geometry::Cylinder::new( radius, length, space=nil ) — Create a new regular cylinder collision geometry with the specified parameters, and insert it into the specified space, if given. This requires the ‘dCylinder’ extension to ODE. Note that this type of cylinder is aligned along the geom’s local Y axis, instead of the Z axis as CappedCylinder is.
/*
* ODE::Geometry::Cylinder::new( radius, length, space=nil )
* --
* Create a new regular cylinder collision geometry with the specified
* parameters, and insert it into the specified space, if given. This requires
* the 'dCylinder' extension to ODE. Note that this type of cylinder is aligned
* along the geom's local *Y* axis, instead of the Z axis as CappedCylinder is.
*/
static VALUE
ode_geometry_cylinder_init( argc, argv, self )
int argc;
VALUE *argv, self;
{
#ifdef HAVE_ODE_DCYLINDER_H
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(( "Cylinder::initialize: Geometry is <%p>", geometry ));
debugMsg(( "Cylinder::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 Cylinder geometry." ));
geometry->id = (dGeomID)dCreateCylinder( 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;
#else
rb_notimplement();
#endif
}
ODE::Geometry::Cylinder#length — Get the cylinder’s length.
/*
* ODE::Geometry::Cylinder#length
* --
* Get the cylinder's length.
*/
static VALUE
ode_geometry_cylinder_length( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
dGeomCylinderGetParams( geometry->id, params, params+1 );
return rb_float_new( params[1] );
}
ODE::Geometry::Cylinder#length=( newValue ) — Set the cylinder’s length.
/*
* ODE::Geometry::Cylinder#length=( newValue )
* --
* Set the cylinder's length.
*/
static VALUE
ode_geometry_cylinder_length_eq( self, newLength )
VALUE self, newLength;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
CheckPositiveNonZeroNumber( NUM2DBL(newLength), "length" );
dGeomCylinderGetParams( geometry->id, params, params+1 );
params[1] = (dReal)NUM2DBL( newLength );
dGeomCylinderSetParams( geometry->id, params[0], params[1] );
return rb_float_new( params[1] );
}
ODE::Geometry::Cylinder#params — Returns the cylinder’s params as a 2-element array (radius,length).
/*
* ODE::Geometry::Cylinder#params
* --
* Returns the cylinder's params as a 2-element array (radius,length).
*/
static VALUE
ode_geometry_cylinder_params( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal radius, length;
dGeomCylinderGetParams( geometry->id, &radius, &length );
return rb_ary_new3( 2,
rb_float_new(radius),
rb_float_new(length) );
}
ODE::Geometry::Cylinder#params=( radius, length ) — Set the cylinder’s radius and length to the specified values.
/*
* ODE::Geometry::Cylinder#params=( radius, length )
* --
* Set the cylinder's <tt>radius</tt> and <tt>length</tt> to the specified
* values.
*/
static VALUE
ode_geometry_cylinder_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" );
dGeomCylinderSetParams( geometry->id,
(dReal)NUM2DBL(*(RARRAY(args)->ptr )),
(dReal)NUM2DBL(*(RARRAY(args)->ptr + 1)) );
dGeomCylinderGetParams( geometry->id, results, results+1 );
return rb_ary_new3( 2,
rb_float_new(results[0]),
rb_float_new(results[1]) );
}
ODE::Geometry::Cylinder#radius — Get the cylinder’s radius.
/*
* ODE::Geometry::Cylinder#radius
* --
* Get the cylinder's radius.
*/
static VALUE
ode_geometry_cylinder_radius( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
dGeomCylinderGetParams( geometry->id, params, params+1 );
return rb_float_new( params[0] );
}
ODE::Geometry::Cylinder#radius=( newValue ) — Set the cylinder’s radius.
/*
* ODE::Geometry::Cylinder#radius=( newValue )
* --
* Set the cylinder's radius.
*/
static VALUE
ode_geometry_cylinder_radius_eq( self, newRadius )
VALUE self, newRadius;
{
ode_GEOMETRY *geometry = get_geom( self );
dReal params[2];
CheckPositiveNonZeroNumber( NUM2DBL(newRadius), "radius" );
dGeomCylinderGetParams( geometry->id, params, params+1 );
params[0] = (dReal)NUM2DBL( newRadius );
dGeomCylinderSetParams( geometry->id, params[0], params[1] );
return rb_float_new( params[0] );
}