Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine ofxTweenzor and ofParameter for ofxGui #8

Open
eloimaduell opened this issue Mar 22, 2015 · 3 comments
Open

combine ofxTweenzor and ofParameter for ofxGui #8

eloimaduell opened this issue Mar 22, 2015 · 3 comments

Comments

@eloimaduell
Copy link

Hi Nick !

Not really and issue at all, just asking for some problem ...

I'm facing a trouble i posted on the OF forum (http://forum.openframeworks.cc/t/combine-tweezor-with-ofparameter-in-ofxgui/18987).

What I'm trying to achieve is that an ofxGui slider is tight to ofParameter and this float is being driven by a Tweenzor.

As far as i understand what is going on this should make it 👍

.h
ofParameter_x2;

.cpp
gui.add(_x2.set( "x2", 0, 0, ofGetWidth() ));
Tweenzor::add((float *)&_x2.get(), 0, ofGetWidth(), 0, 4,EASE_IN_OUT_EXPO);

what i get is that when the Tweenzor is acting, the value is being driven by Tweenzor (as expected), but my problem is that the ofxGui slider is not updated with the values being driven by the Tweenzor ... when the Tweensor ends, then i do can play with the slider and i see the resulting linked value correctly... so something is broken while the Tweenzor is driving the value ...

Maybe i'm confused about it ...
Does my question make sense ? Is it possible to link an ofParameter to a Tweenzor and see the gui widgets updated with Tweensor values ?

@NickHardeman
Copy link
Owner

That is a good question. I don't have a lot of experience using ofxGui. But it sounds like the gui does not know that the ofParameter is changing it's value. Being able to pass an ofParameter to ofxTweenzor directly would be a nice feature. I will look into implementing this functionality into the addon.
For now, can you call update on the ofParameter while the tween is running?

@eloimaduell
Copy link
Author

Hi Nick !

Well ... finally i could solve it with something that i can't understand but I tried when reading twice your answer about "call update on the ofParameter while the tween is running".

So I add on update :

_x1 = _x1;

I would have said that this instruction was not going to change anything. But it did ?
Probably you have an answer of why it works ?

I put here my code in case you want to add it as an ofParameter example (needs ofxGui).

testApp.h

#pragma once

#include "ofMain.h"
#include "ofxTweenzor.h"
#include "ofxGui.h"

class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();

void exit();

void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

//void onUpdate(float args);
void onComplete(float* arg);

TweenParams params;

ofxPanel                 gui;
ofParameter<float>      _x1;
ofParameter<float>      _x2;

};

testApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofBackground(40);

// must call this before adding any tweens //
Tweenzor::init();

// GUI
gui.setup("panel"); // most of the time you don't need a name but don't forget to call setup
gui.add(_x1.set( "x1", 0, 0, ofGetWidth() ));
gui.add(_x2.set( "x2", 0, 0, ofGetWidth() ));

_x1 = ofGetWidth()/2;
_x2 = ofGetWidth()/2;


/// _X1 as a param
params.setup((float*)&_x1.get(), 0,ofGetWidth(),0,2,EASE_IN_OUT_EXPO);
Tweenzor::add(params);

Tweenzor::addCompleteListener( Tweenzor::getTween((float*)&_x1.get()), this, &testApp::onComplete);

}

//--------------------------------------------------------------
void testApp::update(){

Tweenzor::update( ofGetElapsedTimeMillis() );

_x1 = _x1;
_x2 = _x2;

}

//--------------------------------------------------------------
void testApp::draw(){

ofBackground((_x2/ofGetWidth())*255,(_x1/ofGetWidth())*255,0);
ofFill();
ofSetColor(255);
ofRect(_x1, 150., 5.f, 15.f);
ofRect(_x2, 185., 5.f, 15.f);

ofFill();
gui.draw();

}

//--------------------------------------------------------------
void testApp::exit() {
Tweenzor::destroy();
}

//--------------------------------------------------------------
// this function is called on when the tween is complete //
void testApp::onComplete(float* arg)
{

cout << "testApp :: onComplete : arg = " << *arg << endl;

if(arg == &_x1.get())
{
    Tweenzor::add((float *)&_x2.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
    Tweenzor::addCompleteListener( Tweenzor::getTween((float*)&_x2.get()), this, &testApp::onComplete);
}
if(arg == &_x2.get())
{
    Tweenzor::add((float *)&_x1.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
    Tweenzor::addCompleteListener( Tweenzor::getTween((float*)&_x1.get()), this, &testApp::onComplete);
}

}

//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
// add a ofParamter into the Tweenzor
Tweenzor::add((float _)&x1.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
Tweenzor::addCompleteListener( Tweenzor::getTween((float
)&_x1.get()), this, &testApp::onComplete);

}

@NickHardeman
Copy link
Owner

The need for calling _x1 = _x1 is that ofxTweenzor is directly modifying the pointer value of the float passed in. The ofParameter has no way of knowing this is happening. OfParameter overrides operator functions like =, *= +=, etc. when these functions are called, it knows that it has been updated and can be displayed accordingly. Hope this helps

Nick

Typed on a tiny keyboard

On Mar 24, 2015, at 8:21 PM, eloimaduell notifications@github.com wrote:

Hi Nick !

Well ... finally i could solve it with something that i can't understand but I tried when reading twice your answer about "call update on the ofParameter while the tween is running".

So I add on update :

_x1 = _x1;
I would have said that this instruction was not going to change anything. But it did ?
Probably you have an answer of why it works ?

I put here my code in case you want to add it as an ofParameter example (needs ofxGui).

testApp.h

#pragma once

#include "ofMain.h"
#include "ofxTweenzor.h"
#include "ofxGui.h"

class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();

void exit();

void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y);
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

//void onUpdate(float args);
void onComplete(float* arg);

TweenParams params;

ofxPanel gui;
ofParameter _x1;
ofParameter _x2;
};

testApp.cpp

#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofBackground(40);

// must call this before adding any tweens //
Tweenzor::init();

// GUI
gui.setup("panel"); // most of the time you don't need a name but don't forget to call setup
gui.add(_x1.set( "x1", 0, 0, ofGetWidth() ));
gui.add(_x2.set( "x2", 0, 0, ofGetWidth() ));

_x1 = ofGetWidth()/2;
_x2 = ofGetWidth()/2;

/// _X1 as a param
params.setup((float*)&_x1.get(), 0,ofGetWidth(),0,2,EASE_IN_OUT_EXPO);
Tweenzor::add(params);

Tweenzor::addCompleteListener( Tweenzor::getTween((float*)&_x1.get()), this, &testApp::onComplete);
}

//--------------------------------------------------------------
void testApp::update(){

Tweenzor::update( ofGetElapsedTimeMillis() );

_x1 = _x1;
_x2 = _x2;
}

//--------------------------------------------------------------
void testApp::draw(){

ofBackground((_x2/ofGetWidth())_255,(_x1/ofGetWidth())_255,0);
ofFill();
ofSetColor(255);
ofRect(_x1, 150., 5.f, 15.f);
ofRect(_x2, 185., 5.f, 15.f);

ofFill();
gui.draw();
}

//--------------------------------------------------------------
void testApp::exit() {
Tweenzor::destroy();
}

//--------------------------------------------------------------
// this function is called on when the tween is complete //
void testApp::onComplete(float* arg)
{

cout << "testApp :: onComplete : arg = " << *arg << endl;

if(arg == &_x1.get())
{
Tweenzor::add((float _)&x2.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
Tweenzor::addCompleteListener( Tweenzor::getTween((float
)&_x2.get()), this, &testApp::onComplete);
}
if(arg == &_x2.get())
{
Tweenzor::add((float _)&x1.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
Tweenzor::addCompleteListener( Tweenzor::getTween((float
)&_x1.get()), this, &testApp::onComplete);
}
}

//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
// add a ofParamter into the Tweenzor
Tweenzor::add((float )&_x1.get(), 0, ofGetWidth(), 0, 2,EASE_IN_OUT_EXPO);
Tweenzor::addCompleteListener( Tweenzor::getTween((float)&_x1.get()), this, &testApp::onComplete);

}

Sorry i can't find how to quote here


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants