Libs that return a pointer
BlitzMax Forums/BlitzMax Programming/Libs that return a pointer
| ||
This ODE function returns a pointer to a 3D vector: const dReal * dBodyGetPosition (dBodyID); How do you retrieve the data once you get the byte ptr? I just need to read the memory at the returned value, the returned value + 4, and the returned value + 8. Here's my code: position:Byte Ptr=dBodyGetPosition(box) Now what? |
| ||
OK. Guess yes If all object names are just pointers to the object, cannot you just allocate the returned pointer to an object of the type the pointer is pointing to? |
| ||
How do I do that? I tried setting up a vector type and making the function return that. It actually worked, though mem offsets are off: This code displayed "3", meaning that there are two hidden "fields" from the type pointer. I think this is probably a terribly unstable method: dBodySetPosition box,1,2,3 Type TVector3 Field x#,y#,z# EndType Local position:tvector3'Byte Ptr position=dBodyGetPosition(box) Notify position.x -- EDIT -- This seems to work: Type TVector3 Field x#,y#,z# EndType world=dWorldCreate() geom=dCreateBox(0,100,100,100) box=dbodycreate(world) dgeomsetbody geom,body dBodySetPosition box,1,2,3 Local hposition:Byte Ptr hposition=dBodyGetPosition(box) Local position:tvector3 (Byte Ptr Ptr Varptr position) [ 0 ]=hposition-8 |
| ||
I was going to suggest this:Local fp:Float Ptr fp = Float Ptr dBodyGetPosition(box) ' now x is fp[0] y is fp[1] z is fp[2] Totally untested, of course. |
| ||
It seem a bit strange to me, are you sure that its a pointer to JUST a vector? It doesnt contain its magnitude or the like? And I aways thought that the pointers pointed to the begining of the object, not the end of it. |
| ||
If it's meant to be returning 32-bit floats then just turn the byte pointer into a float pointer, as Floyd suggested. |
| ||
If it returns a pointer to a struct of numerics, use arrays, thats the far easier way. If something for example returns a float* vec[3] then define the return as float[] Your Ptr Ptr hack might look "usefull" but it is highly critical and can break at any point. |
| ||
Nevermind, it works. |