Deforming by formula at Openframeworks Essential tutorial

ofSpherePrimitive sphere;
ofEasyCam cam;
ofxPanel gui;
ofxIntSlider countX;
ofLight light;
ofMaterial material;

ofxFloatSlider rad, deform, deformFreq, extrude;

vector<ofPoint> vertices0;

//--------------------------------------------------------------
void ofApp::setup(){

gui.setup( "MixerGroup", "setting.xml" );
gui.add( rad.setup("rad", 250, 0, 500) ) ;
gui.add( deform.setup("deform", 0.3, 0, 1.5) ) ;
gui.add( deformFreq.setup("deformFreq", 3, 0, 10) ) ;
gui.add( extrude.setup("extrude", 1, 0, 1) ) ;

sphere.set(250,20);
vertices0 = sphere.getMesh().getVertices();     /* No viable overloaded '=' */

}

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

vector<ofPoint> &vertices = sphere.getMesh().getVertices();
/* Non-const lvalue reference to type ‘vector’ cannot bind to a value of unrelated type ‘vector<glm::tvec3<float, glm::packed_highp>>’ */

for (int i=0; i<vertices.size(); i++) {
    ofPoint v = vertices0[i];
    v.normalize();
    float sx = sin (v.x * deformFreq);
    float sy = sin (v.y * deformFreq);
    float sz = sin (v.z * deformFreq);
    v.x += sy * sz * deform;
    v.y += sx * sz * deform;
    v.z += sx * sy * deform;
    v *= rad;
    vertices[i] = v;
    
}

}

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

light.setPosition ( ofGetWidth()/2, ofGetHeight()/2, 600);
light.enable();
material.begin();
ofEnableDepthTest();

cam.begin();
ofSetColor ( ofColor::white ) ;
sphere.draw() ;
sphere.setGlobalPosition( ofGetWidth()/2, ofGetHeight()/2, 0 ) ;
cam.end();

}
//--------------------------------------------------------------

I’m beginner of OF. When I followed the description of books to deform sphere, the error comes up. I make wrong code bold. please check it out. Thank you.

That book is old, copy and paste code from there is not working most of the time. Here the error is that sphere.getMesh().getVertices(); is returning, since OF 0.98 (more or less), a vector<glm::vec3>, not a vector<ofPoint>. That’s why the compiler is telling you

Non-const lvalue reference to type vector cannot bind to a value of unrelated type vector<glm::tvec3<float, glm::packed_highp>>

Try to change the update method to something like:

void ofApp::update(){
  vector<glm::vec3> &vertices = sphere.getMesh().getVertices();
  for (int i=0; i<vertices.size(); i++) {
    auto v = glm::normalize(vertices0[i]);
    float sx = sin (v.x * deformFreq);
    float sy = sin (v.y * deformFreq);
    float sz = sin (v.z * deformFreq);
    v.x += sy * sz * deform;
    v.y += sx * sz * deform;
    v.z += sx * sy * deform;
    v *= rad;
    vertices[i] = v;
  }
}

And change:

vector<ofPoint> vertices0;

to:

vector<glm::vec3> vertices0;

In your header file.

It works!! really thank you!! and I have to throw away this book (I bought this last month…:<)

Hi, I hope you don’t mind this thread necromancy, but I have a problem with your solution. I too am following the book, I have made the modifications you specified, but I get an error:

vector<glm::vec3> &vertices = sphere.getMesh().getVertices();
for (int i = 0; i < vertices.size(); i++)
{
    auto v = glm::normalize( vertices0[i]);       
    float sx = sin( v.x * deformFreq );
    float sy = sin( v.y * deformFreq );
    float sz = sin( v.z * deformFreq );
    v.x += sy * sz * deform;
    v.y += sx * sz * deform;
    v.z += sx * sy * deform;
    v *= rad;                             // call to implicitly-deleted copy constructor of ofxSlider<float>
    vertices[i] = v;
}

Any help would be much appreciated!

Hi, can you please post the error you get? Otherwise is quite hard to provide help.
cheers

The error i get:

call to implicitly-deleted copy constructor of ofxSlider<float>

/home/eamoc/CODE/OpenFrameWorks_Examples/VideoSynth/src/ofApp.cpp:97: error: use of deleted function ‘ofxSlider::ofxSlider(const ofxSlider&)’
v *= rad;
^~~
/home/eamoc/MyStuff/openFrameworks/addons/ofxGui/src/ofxSlider.h:8: error: use of deleted function ‘ofxInputField::ofxInputField(const ofxInputField&)’
/home/eamoc/MyStuff/openFrameworks/addons/ofxGui/src/ofxInputField.h:14: error: use of deleted function ‘ofEventListeners::ofEventListeners(const ofEventListeners&)’
/home/eamoc/MyStuff/openFrameworks/addons/ofxGui/src/ofxSlider.h:8: error: use of deleted function ‘ofEventListener::ofEventListener(const ofEventListener&)’
class ofxSlider : public ofxBaseGui{
:-1: error: Process failed with exit code 1.
:-1: error: The following products could not be built for configuration qtc_Test123_Debug:
:-1: error: VideoSynth
/home/eamoc/CODE/OpenFrameWorks_Examples/VideoSynth/src/ofApp.cpp:97: error: call to implicitly-deleted copy constructor of ‘ofxSlider’
^~~~~~~~~

well I would guess that rad is an ofxSlider object.
does it work if you try changing

v *= rad;

for

v = v * rad;

its an ofxFloatSlider object, which is ofxSlider.
when I replace
v = rad;
for
v = v * rad;
as you suggest, I get a different error:
/home/eamoc/CODE/OpenFrameWorks_Examples/VideoSynth/src/ofApp.cpp:97: error: no match for 'operator
’ (operand types are ‘glm::tvec3<float, (glm::precision)0>’ and ‘ofxFloatSlider’ {aka ‘ofxSlider’})
v = v * rad;
^~~

???

Hi,
I really dont like using ofxFloatSlider instead I use ofParameters which are more flexible. It is just a different approach on using ofxGui.
does it work if you use instead
v = v * float(rad);

1 Like

Hi,
That worked!!
Im following the code in “openFramework essentials” but it seems to be out of date.
Thanks for your help. I never would have tried that

E.

Glad to know.

The error you posted was suggesting it. stuff you learn along the way :slight_smile:

Actually the "openFramework essentials” book is quite outdated and there are a lot of questions here in the forum regarding it. It would be great if the author, or maybe someone else, made an update to that code.

Well,
if I ever get tot he end of it, I’ll post mine
:slight_smile: