Class ODE::Geometry::Box
In: ext/geometry.c  (CVS)
Parent: ODE::Geometry::Placeable

Methods

lengths   lengths=   lx   lx=   ly   ly=   lz   lz=   new  

Public Class methods

ODE::Geometry::Box::new( lx, ly, lz, space=nil ) — Create a new rectangular collision geometry with the specified side lengths, and insert it into the specified space, if given.

[Source]

/*
 * ODE::Geometry::Box::new( lx, ly, lz, space=nil )
 * --
 * Create a new rectangular collision geometry with the specified side lengths,
 * and insert it into the specified space, if given.
 */
static VALUE
ode_geometry_box_init( argc, argv, self )
	 int	argc;
	 VALUE	*argv, self;
{
	VALUE			lx, ly, lz, 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(( "Box::initialize: Geometry is <%p>", geometry ));
	
	debugMsg(( "Box::initialize: Scanning arguments." ));
	if ( rb_scan_args(argc, argv, "31", &lx, &ly, &lz, &spaceObj) == 4 ) {
		SetContainer( spaceObj, space, geometry );
	}

	CheckPositiveNonZeroNumber( NUM2DBL(lx), "X" );
	CheckPositiveNonZeroNumber( NUM2DBL(ly), "Y" );
	CheckPositiveNonZeroNumber( NUM2DBL(lz), "Z" );

	debugMsg(( "Creating new Box geometry." ));
	geometry->id = (dGeomID)dCreateBox( space,
										(dReal)NUM2DBL(lx),
										(dReal)NUM2DBL(ly),
										(dReal)NUM2DBL(lz) );

	/* Set the ode_GEOMETRY pointer as the data pointer of the dGeomID */
	dGeomSetData( geometry->id, geometry );

	return self;
}

Public Instance methods

ODE::Geometry::Box#lengths — Returns the box’s lengths as a 3-element array.

[Source]

/*
 * ODE::Geometry::Box#lengths
 * --
 * Returns the box's lengths as a 3-element array.
 */
static VALUE
ode_geometry_box_lengths( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		result;

	dGeomBoxGetLengths( geometry->id, result );

	return rb_ary_new3( 3,
						rb_float_new(result[0]),
						rb_float_new(result[1]),
						rb_float_new(result[2]) );
}

ODE::Geometry::Box#lengths=( lengths ) — Set the box’s radius to lengths, which can be any object which returns an array with 3 numeric values when to_ary is called on it, such a Math3d::Vector3 or an Array with 3 numeric values.

[Source]

/*
 * ODE::Geometry::Box#lengths=( lengths )
 * --
 * Set the box's radius to <tt>lengths</tt>, which can be any object which
 * returns an array with 3 numeric values when <tt>to_ary</tt> is called on it,
 * such a Math3d::Vector3 or an Array with 3 numeric values.
 */
static VALUE
ode_geometry_box_lengths_eq( self, lengths )
	 VALUE self, lengths;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	VALUE			lengthsArray;
	dVector3		result;

	debugMsg(( "Setting box lengths: Got %d argument/s.", RARRAY(lengths)->len ));

	/* Normalize the dimensions into an array */
	if ( RARRAY(lengths)->len == 1 ) 
		lengthsArray = ode_obj_to_ary3( *(RARRAY(lengths)->ptr), "lengths" );
	else
		lengthsArray = ode_obj_to_ary3( lengths, "lengths" );

	debugMsg(( "Arguments normalized. Setting box lengths." ));

	CheckPositiveNonZeroNumber( NUM2DBL(*(RARRAY(lengthsArray)->ptr  )), "lx" );
	CheckPositiveNonZeroNumber( NUM2DBL(*(RARRAY(lengthsArray)->ptr+1)), "ly" );
	CheckPositiveNonZeroNumber( NUM2DBL(*(RARRAY(lengthsArray)->ptr+2)), "lz" );

	dGeomBoxSetLengths( geometry->id,
						(dReal)NUM2DBL(*(RARRAY(lengthsArray)->ptr    )),
						(dReal)NUM2DBL(*(RARRAY(lengthsArray)->ptr + 1)),
						(dReal)NUM2DBL(*(RARRAY(lengthsArray)->ptr + 2)) );

	debugMsg(( "Lengths set." ));

	dGeomBoxGetLengths( geometry->id, result );
	return rb_ary_new3( 3,
						rb_float_new(result[0]),
						rb_float_new(result[1]),
						rb_float_new(result[2]) );
}

ODE::Geometry::Box#lx — Returns the box’s X-axis length.

[Source]

/*
 * ODE::Geometry::Box#lx
 * --
 * Returns the box's X-axis length.
 */
static VALUE
ode_geometry_box_length_x( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		result;

	dGeomBoxGetLengths( geometry->id, result );

	return rb_float_new(result[X]);
}

ODE::Geometry::Box#lx=( length ) — Sets the box’s X-axis length.

[Source]

/*
 * ODE::Geometry::Box#lx=( length )
 * --
 * Sets the box's X-axis length.
 */
static VALUE
ode_geometry_box_length_x_eq( self, newLength )
	 VALUE self, newLength;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		lengths;

	CheckPositiveNonZeroNumber( NUM2DBL(newLength), "length" );

	dGeomBoxGetLengths( geometry->id, lengths );

	lengths[X] = (dReal)NUM2DBL( newLength );
	dGeomBoxSetLengths( geometry->id, lengths[X], lengths[Y], lengths[Z] );

	return rb_float_new(lengths[X]);
}

ODE::Geometry::Box#ly — Returns the box’s Y-axis length.

[Source]

/*
 * ODE::Geometry::Box#ly
 * --
 * Returns the box's Y-axis length.
 */
static VALUE
ode_geometry_box_length_y( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		result;

	dGeomBoxGetLengths( geometry->id, result );

	return rb_float_new(result[Y]);
}

ODE::Geometry::Box#ly=( length ) — Sets the box’s Y-axis length.

[Source]

/*
 * ODE::Geometry::Box#ly=( length )
 * --
 * Sets the box's Y-axis length.
 */
static VALUE
ode_geometry_box_length_y_eq( self, newLength )
	 VALUE self, newLength;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		lengths;

	CheckPositiveNonZeroNumber( NUM2DBL(newLength), "length" );

	dGeomBoxGetLengths( geometry->id, lengths );

	lengths[Y] = (dReal)NUM2DBL( newLength );
	dGeomBoxSetLengths( geometry->id, lengths[X], lengths[Y], lengths[Z] );

	return rb_float_new(lengths[Y]);
}

ODE::Geometry::Box#lz — Returns the box’s Z-axis length.

[Source]

/*
 * ODE::Geometry::Box#lz
 * --
 * Returns the box's Z-axis length.
 */
static VALUE
ode_geometry_box_length_z( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		result;

	dGeomBoxGetLengths( geometry->id, result );

	return rb_float_new(result[Z]);
}

ODE::Geometry::Box#lz=( length ) — Sets the box’s Z-axis length.

[Source]

/*
 * ODE::Geometry::Box#lz=( length )
 * --
 * Sets the box's Z-axis length.
 */
static VALUE
ode_geometry_box_length_z_eq( self, newLength )
	 VALUE self, newLength;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		lengths;

	CheckPositiveNonZeroNumber( NUM2DBL(newLength), "length" );

	dGeomBoxGetLengths( geometry->id, lengths );

	lengths[Z] = (dReal)NUM2DBL( newLength );
	dGeomBoxSetLengths( geometry->id, lengths[X], lengths[Y], lengths[Z] );

	return rb_float_new(lengths[Z]);
}

[Validate]