Complexe structure with pointer using FFI
Ivo Roessling
ivo at wettinet.de
Mon May 26 17:54:43 UTC 2003
jpruvot wrote:
> typedef double dReal;
> typedef dReal dVector3[4];
> typedef dReal dVector4[4];
>
> struct dxGeom; /* geometry (collision object) */
> typedef struct dxGeom *dGeomID;
> typedef struct dContactGeom {
> dVector3 pos;
> dVector3 normal;
> dReal depth;
> dGeomID g1,g2;
> } dContactGeom;
create a class "DContactGeom" with the field definition:
fields
^ #(#(#pos 'DVector3')
#(#normal 'DVector3')
#(#length 'double')
#(#g1 'DGeomID')
#(#g2 'DGeomID'))
create a class "DVector3" and a class "DVector4" (what's the difference
there?!) with the field definition:
fields
^ #(#(#element1 'double')
#(#element2 'double')
#(#element3 'double')
#(#element4 'double'))
you could also say (- as i learned recently! ;-) -)
fields
^ #(#(#data 'double' 32))
(which will create a structure that is 32byte = 4*double sized, but
unfortunately data only refers to the first double - so if you want
to access the rest, you'd have to take use of "#getHandle")
create a class "dGeomID" with the field definition:
fields
^ #(#(#geometry 'dxGeom*'))
you'll have to declare a class "dxGeom", too - i didn't find one in your
message... (only a forward declaration or so...)
> typedef struct dGeomClass {
> int bytes;
> dGetColliderFnFn *collider;
> dGetAABBFn *aabb;
> dAABBTestFn *aabb_test;
> dGeomDtorFn *dtor;
> } dGeomClass;
create a class "DGeomClass" with the field definition:
fields
^ #(#(#bytes 'long')
#(#collider 'DGetColliderFnFn*')
#(#aabb 'DBetAABBFn*')
#(#aabb_test 'DAABBTestFn*')
#(#dtor 'DGeomDtorFn'))
hope that helps...
however - it seems to me that you are handling with function pointers.
probably by means of callback-functions. i'm not sure if there's any way
to define those functions in squeak and pass a handle on through ffi -
but i think, there is no such thing...
cheers,
ivo
More information about the Squeak-dev
mailing list
|