[SOLVED] ofParameter update vector coordinates

Hello,

i have an ofVec3f as an ofParameter and i don’t know how to update just one coordinate value.

for example i have :

ofParameter<ofVec3f> position;

I am able to get separate values using

float distance = position.get().z;

But how can i just set the z coordinate ?

thanks a lot

in the same way

position.get().z = 50;

Hum… well… ok !
I love ofParameter :slight_smile:

thanks

Well, in fact i am facing this problem :

 Read-only variable is not assignable

mm.
ive never needed to do such but, anyways, as it doesn’t work for ofVec
try the following.

    ofVec3f v = position.get();
    v.x =  ofGetMouseX();
    position.set(v) ;

best

Yep, i will do like that as a turnaround.
thank you

If by any chance somebody knows a straighter solution…

there’s no way to update individual components of ofParameter, the cause is that ofParameter is meant to always notify it’s event when it changes but there’s no way for ofParameter to know which would be it’s value after a call to a mutable operation on the variable it holds.

You can call any const method or access any of it’s variables for read only on an ofParameter like:

ofParameter<ofVec3f> pos;
pos->getLength();
pos->z;

But you can’t access any of it’s mutable mehtods or change the value of it’s variables. The only way to mutate an ofParameter contents is to set it’s full value again, so you would need to do something like:

ofParameter<ofVec3f> pos;
pos = ofVec3f(pos->x, pos->y, 50);

ok. Thanks for the great explanation.
I will do like suggested.
thanks again