| Class | ODE::Geometry::Plane |
| In: |
ext/geometry.c
(CVS)
|
| Parent: | ODE::Geometry |
ODE::Geometry::Plane::new( a, b, c, d, space=nil ) — Create a new planar collision geometry with the specified parameters, and insert it into the specified space, if given. The plane equation is
a*x + b*y + c*z = d
The plane’s normal vector is (a,b,c), and it must have length 1. Planes are non-placeable geoms. This means that, unlike placeable geoms, planes do not have an assigned position and rotation. This means that the parameters (a,b,c,d) are always in global coordinates. In other words it is assumed that the plane is always part of the static environment and not tied to any movable object.
/*
* ODE::Geometry::Plane::new( a, b, c, d, space=nil )
* --
* Create a new planar collision geometry with the specified parameters, and
* insert it into the specified space, if given. The plane equation is
*
* a*x + b*y + c*z = d
*
* The plane's normal vector is (a,b,c), and it must have length 1. Planes are
* non-placeable geoms. This means that, unlike placeable geoms, planes do not
* have an assigned position and rotation. This means that the parameters
* (a,b,c,d) are always in global coordinates. In other words it is assumed that
* the plane is always part of the static environment and not tied to any
* movable object.
*/
static VALUE
ode_geometry_plane_init( argc, argv, self )
int argc;
VALUE *argv, self;
{
VALUE a, b, c, d, 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(( "Plane::initialize: Geometry is <%p>", geometry ));
debugMsg(( "Plane::initialize: Scanning arguments." ));
if ( rb_scan_args(argc, argv, "41", &a, &b, &c, &d, &spaceObj) == 5 ) {
SetContainer( spaceObj, space, geometry );
}
debugMsg(( "Creating new Plane geometry." ));
geometry->id = (dGeomID)dCreatePlane( space,
(dReal)NUM2DBL(a),
(dReal)NUM2DBL(b),
(dReal)NUM2DBL(c),
(dReal)NUM2DBL(d) );
/* Set the ode_GEOMETRY pointer as the data pointer of the dGeomID */
debugMsg(( "Setting geom data for plane <%p> to <%p>",
geometry->id, geometry ));
dGeomSetData( geometry->id, geometry );
return self;
}
ODE::Geometry::Plane#params — Returns the plane’s params as a 4-element array (a,b,c,d).
/*
* ODE::Geometry::Plane#params
* --
* Returns the plane's params as a 4-element array (a,b,c,d).
*/
static VALUE
ode_geometry_plane_params( self )
VALUE self;
{
ode_GEOMETRY *geometry = get_geom( self );
dVector4 result;
dGeomPlaneGetParams( geometry->id, result );
return rb_ary_new3( 4,
rb_float_new(result[0]),
rb_float_new(result[1]),
rb_float_new(result[2]),
rb_float_new(result[3]) );
}
ODE::Geometry::Plane#params=( params ) — Set the plane’s radius to params, 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.
/*
* ODE::Geometry::Plane#params=( params )
* --
* Set the plane's radius to <tt>params</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_plane_params_eq( self, params )
VALUE self, params;
{
ode_GEOMETRY *geometry = get_geom( self );
VALUE paramsArray;
dVector4 result;
debugMsg(( "Setting plane params: Got %d argument/s.", RARRAY(params)->len ));
/* Normalize the dimensions into an array */
if ( RARRAY(params)->len == 1 )
paramsArray = ode_obj_to_ary4( *(RARRAY(params)->ptr), "params" );
else
paramsArray = ode_obj_to_ary4( params, "params" );
debugMsg(( "Arguments normalized. Setting plane params." ));
dGeomPlaneSetParams( geometry->id,
(dReal)NUM2DBL(*(RARRAY(paramsArray)->ptr )),
(dReal)NUM2DBL(*(RARRAY(paramsArray)->ptr + 1)),
(dReal)NUM2DBL(*(RARRAY(paramsArray)->ptr + 2)),
(dReal)NUM2DBL(*(RARRAY(paramsArray)->ptr + 3)) );
debugMsg(( "Params set." ));
dGeomPlaneGetParams( geometry->id, result );
return rb_ary_new3( 4,
rb_float_new(result[0]),
rb_float_new(result[1]),
rb_float_new(result[2]),
rb_float_new(result[3]) );
}