Class ODE::Geometry::Ray
In: ext/geometry.c  (CVS)
Parent: ode_cOdeRay

Methods

Public Class methods

ODE::Geometry::Ray#initialize( length[, space[, start, direction]] ) — Create a new Ray object of the specified length and insert it into the specified space, if non-nil. If the optional start and direction arguments are given, use them to set the ray’s start position and direction.

[Source]

/*
 * ODE::Geometry::Ray#initialize( length[, space[, start, direction]] )
 * --
 * Create a new Ray object of the specified +length+ and insert it into the
 * specified +space+, if non-nil. If the optional +start+ and +direction+
 * arguments are given, use them to set the ray's start position and direction.
 */
static VALUE
ode_geometry_ray_init( argc, argv, self )
	 int argc;
	 VALUE *argv, self;
{
	VALUE			length, start, direction, 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(( "Ray::initialize: Geometry is <%p>", geometry ));
	
	debugMsg(( "Ray::initialize: Scanning arguments." ));
	rb_scan_args( argc, argv, "13", &length, &spaceObj, &start, &direction );

	/* If a container space was specified get the dSpaceID for it */
	if ( RTEST(spaceObj) ) {
		SetContainer( spaceObj, space, geometry );
	}

	/* Make sure the length is a positive non-zero number */
	CheckPositiveNonZeroNumber( NUM2DBL(length), "length" );

	/* Create the ray */
	debugMsg(( "Creating new Ray geometry." ));
	geometry->id = (dGeomID)dCreateRay( space,
										(dReal)NUM2DBL(length) );

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

	/* Set start point and/or direction if they are non-nil */
	if (RTEST( start )) ode_geometry_ray_start_point_eq( self, start );
	if (RTEST( direction )) ode_geometry_ray_direction_point_eq( self, direction );

	return self;
}

Public Instance methods

ODE::Geometry::Ray#directionPoint

[Source]

/*
 * ODE::Geometry::Ray#directionPoint
 * --
 * 
 */
static VALUE
ode_geometry_ray_direction_point( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		start, dir;
	VALUE			pos;

	dGeomRayGet( geometry->id, start, dir );
	Vec3ToOdePosition( dir, pos );
	
	return pos;
}

ODE::Geometry::Ray#directionPoint= —

[Source]

/*
 * ODE::Geometry::Ray#directionPoint=
 * --
 * 
 */
static VALUE
ode_geometry_ray_direction_point_eq( self, point )
	 VALUE self, point;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	VALUE			pointAry;
	dVector3		start, dir;

	pointAry = ode_obj_to_ary3( point, "direction point" );

	dGeomRayGet( geometry->id, start, dir );
	dGeomRaySet( geometry->id,
				 start[0],
				 start[1],
				 start[2],
				 (dReal)NUM2DBL( *(RARRAY(pointAry)->ptr) ),
				 (dReal)NUM2DBL( *(RARRAY(pointAry)->ptr + 1) ),
				 (dReal)NUM2DBL( *(RARRAY(pointAry)->ptr + 2) ) );

	/* It no longer matters (as of the latest Ruby-1.8) what gets returned here,
	   so just return nil */
	return Qnil;
}

ODE::Geometry::Ray#length

[Source]

/*
 * ODE::Geometry::Ray#length
 * --
 * 
 */
static VALUE
ode_geometry_ray_length( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	return rb_float_new( dGeomRayGetLength(geometry->id) );
}

ODE::Geometry::Ray#length= —

[Source]

/*
 * ODE::Geometry::Ray#length=
 * --
 * 
 */
static VALUE
ode_geometry_ray_length_eq( self, length )
	 VALUE self, length;
{
	ode_GEOMETRY	*geometry = get_geom( self );

	CheckPositiveNonZeroNumber( NUM2DBL(length), "length" );
	dGeomRaySetLength( geometry->id, (dReal)NUM2DBL(length) );

	return ode_geometry_ray_length( self );
}

ODE::Geometry::Ray#startPoint

[Source]

/*
 * ODE::Geometry::Ray#startPoint
 * --
 * 
 */
static VALUE
ode_geometry_ray_start_point( self )
	 VALUE self;
{
	ode_GEOMETRY	*geometry = get_geom( self );
	dVector3		start, dir;
	VALUE			pos;

	dGeomRayGet( geometry->id, start, dir );
	Vec3ToOdePosition( start, pos );
	
	return pos;
}

ODE::Geometry::Ray ——————————

[Source]

/* --- ODE::Geometry::Ray ------------------------------ */

static VALUE ode_geometry_ray_start_point_eq( VALUE, VALUE );

[Validate]