Pass ofParameter<glm::vec2> as an argument


I have an
ofParameter<glm::vec2> corners[4];

and I want to create a function that can accept it like :

myMatrix = myFunction(corners.get());

	template <class T>
    static glm::mat4 myFunction(const T &dst){

Is it possible ?

what you have there is an array of ofParameters, and as such you can pass it as a pointer and its size. a vector would be much more convenient for this, and just pass as reference. or actually much better would be to use an ofParametersGroup and pass that as a reference.

Right now I have to make a copy and I’d like to know if I can avoid it:

glm::vec2 cvdst[4];
for(int i = 0; i < 4; i++){
    cvdst[i] = corners[i];
myMatrix = myFunction(cvsrc, cvdst);

The function is like this:

template <class T>
    static glm::mat4 myFunction(T &src, T &dst){

I don’t know how to write the call of myFunction to pass it directly

the best option I think is to have an ofParameterGroup object at which you add all these ofParameters. You need to add the parameters just once, probably in the setup, then you pass to this function the ofParameterGroup object.
it should look something like.

In the .h file:

ofParameterGroup cornersGroup;
ofParameter<glm::vec2> corners[4];
//in the setup or wherever you setup the ofParameters.

for(int i = 0; i < 4; i++){

//then your function can simply be
glm::mat4 myFunction(ofParameterGroup& group){
//assuming that there's nothing else in the group you can simply get each corner by their index, which is the same by which these were added.   
 group.get( int indexofeachcorner);
//or find these by their name passing a string instead of an int


The other way is to pass a pointer to the corners array like this

glm::mat4 myFunction(ofParameter<glm::vec2> * crns, size_t crns_size){
// you know before hand that the array is 4 in size but it is much better to make sure to pass its size


//and simply call it 
myFunction(corners, 4);