|
Post by davy on Aug 8, 2006 8:32:48 GMT -5
I am a little shaky on the dll's processes to get and return an array from a command. I think this could be useful for things like taking a vertex array of a model, and returning a normal's array. Also for creating a smoothing function that lets you put in an array, and will return the array after undergoing a smooth function (for images/terrains). I've read through the "Basic4GLDLLInterfaceH" file and have found what is needed to do it... But Im not sure how it is structured and how you would go about creating a c++ array from the input array. Thanks!
|
|
|
Post by Supermonkey on Aug 8, 2006 12:39:07 GMT -5
Ok my answer is based on what I can remember of the IDLL interface and it is untested so I don't know if its correct but its worth trying (also some of the function names may be incorrect, its off the top of my head : you would create a pointer like so: int *ptr_to_array; and pass it to the array parameter of the Get or Set Array functions i.e. void some_array_function(IDLL_Basic4gl_Runtime &basic4gl){ int* array; // I'm not 100% about what the last parameter dimension0size does and the dimensions variable may be the third parameter not the fourth, I can't remember! int dimensions = basic4gl.GetArrayParamDimensions(1,0); basic4gl.GetIntArrayParam(1,array,0,dimensions); // Acces the C++ array to modify some data array[2] = 5; // Return the modified array basic4gl.SetIntArrayResult(array,0,dimensions); }
|
|
|
Post by davy on Aug 8, 2006 12:45:02 GMT -5
How do I tell how many elements are there to use in a for/next loop or anything? And how would I be able to find the elements for different dimensions?
Example... To make a smoothing routine for an image array or terrain array, I would need to know both the width and the height...
Picture(128)(256)
|
|
|
Post by Supermonkey on Aug 8, 2006 12:48:41 GMT -5
Ah yeh, I don't know if there is a function returning that in the interface, There is one to return the number of dimensions in an array but not the size. However to find the size of an array dimension do this:
#include <iostream>
int main() { int t[100]; cout<<"Size of t = "<<sizeof(t)/sizeof(int)<<endl; return 0; }
|
|
|
Post by davy on Aug 8, 2006 13:12:51 GMT -5
So once I got the number of dimensions, I could find the number of elements in each dimension like this?...
width=sizeof(Picture)/sizeof(int)... height=sizeof(Picture[0])/sizeof(int)...
Or something along those lines?
|
|
|
Post by Supermonkey on Aug 8, 2006 14:44:45 GMT -5
Well with a multi-dimensional array to get the correct number of elements for the first dimension you would also have to divide by the second dimension also:
int t[100][10]; int sd = sizeof(t[0])/sizeof(int); int fd = (sizeof(t)/sizeof(int))/sd; cout<<"Size of t = "<<fd<<endl; cout<<"Size of secnd dimension = "<<sd<<endl;
|
|
|
Post by davy on Aug 8, 2006 15:10:38 GMT -5
Ok, that makes sense. Thanks supermonkey!
|
|