[ODE] Problems with user defined geom class

Arto Nykanen arpany at utu.fi
Sun Mar 5 08:10:26 MST 2006


Hello all

I have made a simple spline surface class and now I'm trying to 
implement collision detection with ODE C API. The spline surface is 
defined as c++ class (MyClass) with member variable dGeomID my_geom. The 
geom class' custom data field contains pointer to corresponding c++ object.

// These two fuctions are in global scope
int GetMyGeomClass( )
{
	static int my_geom_class = -1;
	
	if( my_geom_class == -1 )
	{
		dGeomClass c;
		c.bytes = sizeof( MyClass* );
		c.collider = &GetColliderFn;
		c.aabb = &GetAABB;
		c.aabb_test = 0;
		c.dtor = 0;
		my_geom_class = dCreateGeomClass( &c );
	}
	return my_geom_class;
}

dColliderFn * GetColliderFn( int num )
{
	std::cout << "GetColliderFn called with argument ";
	if( num == dSphereClass ) std::cout << "dSphereClass\n";
	if( num == dPlaneClass ) std::cout << "dPlaneClass\n";
	
	return 0;
}

In MyClass constructor:
	my_geom = dCreateGeom( GetMyGeomClass( ) );
	void* data = dGeomGetClassData( my_geom );
	data = this;
	dSpaceAdd( coll_space, my_geom );

In my test program I have a plane and above that (but not touching) is 
an instance of MyClass and above that is a falling sphere. All geoms are 
in same space and collisions are checked with dSpaceCollide.

When I run the test program, it prints "GetColliderFn called with 
argument dPlaneClass" and nothing else. Is there any reason why ODE 
doesn't call GetColliderFn with argument dSphereClass?

-- 
    Arto Nykänen


More information about the ODE mailing list