[ODE] attaching a ray to bodies

Shamyl Zakariya shamyl at zakariya.net
Wed Sep 29 14:14:52 MST 2004


I had bad luck with geom transforms, which I attribute only to my 
ignorance. I worked out an approach to keep rays attached as such:

"_attachedTo" is the object this ray's attached to
"_anchor" is where the ray is emitted from, in coordinates relative to 
_attachedTo
"_direction" is the direction the ray is emitted, in relative to 
_attachedTo's rotation

void RangeSensor::step( void )
{

	/*
		The anchor and the implied up-vector are in
		coordinates relative to _attachedTo, so we've got
		to convert them into world coordinates and update
		our ray accordingly.
	*/
		
	dVector3 anchor, direction;
	copyVector( _anchor, anchor );
	copyVector( _direction, direction );
		
	getRelPoint( _attachedTo, anchor );
	getRelAxis( _attachedTo, direction );
	
	dGeomRaySet( _rayGeom, anchor[0], anchor[1], anchor[2],
				 direction[0], direction[1], direction[2] );
}

And, the functions getRelPoint & getRelAxis:

void getRelAxis( Object *object, dVector3 a )
{
	dVector3 r;
	dBodyVectorToWorld( object->body(), a[0], a[1], a[2], r );
		
	a[0] = r[0];
	a[1] = r[1];
	a[2] = r[2];
}

void getRelPoint( Object *object, dVector3 a )
{
	dVector3 r;
	dBodyGetRelPointPos( object->body(), a[0], a[1], a[2], r );
	a[0] = r[0];
	a[1] = r[1];
	a[2] = r[2];	
}

While this isn't as nice as a proper geom transform, it works well 
enough for me!


On Sep 27, 2004, at 1:50 PM, De Souza, Gustavo wrote:

> Hi all!
>
>  
>
> I’m trying to simulate a sensor using the ray class and attach it to a 
> simulated robot.
>
>  The problem I’m facing is that I don’t know how to attach the sensor 
> to a particular coordinate in the mobile’s robot body and keep the 
> original orientation (relative to the robot) while the robot is 
> navigating through the environment.
>
> Is there an easy way to update ray’s position/orientation based in its 
> parent’s (robot) position/orientation?
>
>   
>
> Many thanks,
>
>  
>
> Gustavo
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode




More information about the ODE mailing list