Polyline.getvertices() gives output in what form?

When I equate the above to a ofVec3f or a vector <ofVec3f> “name” array it says cannot assign this value to them.

can you paste the lines of code you have issues?

Its a vector glm::vec3

You can do:

vector <glm::vec3> & verts = polyline.getVertices();

or

auto & verts = polyline.getVertices();

Remove the & if you want a copy of the verts and not a reference.

1 Like

Hi Theo!

Thank you for the reply. What does glm::vec3 mean. I’m sorry but new to C++. I thought ofVec3f is also a vector and vector “name” is an array of vectors.

Found the below code in ofbook. When I paste it, doesnt assign polyline.getVertices(); to vector vertices

vector<ofVec3f>* vertices* = polyline.getVertices();
float tangentLength = 80;
for (int vertexIndex=0; vertexIndex<vertices.size(); ++vertexIndex)
{
ofVec3f vertex = vertices[vertexIndex];
ofVec3f tangent = polyline.getTangentAtIndex(vertexIndex) * tangentLength;
ofLine(vertex-tangent/2, vertex+tangent/2);
}

Found the below code in ofbook. When I paste it, doesnt assign polyline.getVertices(); to vector vertices

vector<ofVec3f>* vertices* = polyline.getVertices();
float tangentLength = 80;
for (int vertexIndex=0; vertexIndex<vertices.size(); ++vertexIndex)
{
ofVec3f vertex = vertices[vertexIndex];
ofVec3f tangent = polyline.getTangentAtIndex(vertexIndex) * tangentLength;
ofLine(vertex-tangent/2, vertex+tangent/2);
}

hi @Apoorva_Singal ,

ofVec3f and glm::vec3 are both data types that represent vectors. ofVec3f is a native openFrameworks type and glm::vec3 comes from the GLM math library.

oF has recently transitioned to using GLM for math, including vector and matrix operations. getVertices() returns a vector of glm::vec3 rather than ofVec3f, which is why you’re seeing the error. you’ll have to create a vector of glm::vec3 in order to get the vertices. this howto may be of use to you!

cheers

1 Like

I think you have some more asterisks in your code in the first line.
Maybe it is misformatted here on the forum too.

You can use this icon to format code correctly here

48%20PM

OMG! thank you so much for this. The code has started working. It would be very difficult to learn openframeworks if not for helpful community members like you.

Thank You!

Agreed !

Tips for later:

  • Think about searching the forum. Your question make me remember this one :wink:

  • You can look at OF code. This is great, even if it can be hard to read without enough C++ knowledge (it still bother me, but it become easier as I learn). In your case, here’s what you can find for the declaration of getVertices() (you can easily find it by using your IDE, I use QtCreator and I just had to place the cursor above getVertices then press F2):

std::vector<T> & getVertices();

But what is T ?
This is the template parameter of the class

template<class T>
class ofPolyline_ {

The definition of ofPolyline is:

using ofPolyline = ofPolyline_<ofDefaultVertexType>;

(cursor abose ofPolyline and F2)
This means that

std::vector<T> & getVertices();

can be read

std::vector<ofDefaultVertexType> & getVertices();

for ofPolyline.
But what is ofDefaultVertexType ?
F2 over it lead to

using ofDefaultVertexType = ofDefaultVec3;

and F2 over ofDefaultVec3 lead to:

using ofDefaultVec3 = glm::vec3;

At last ! We’ve got the answer: for ofPolyline, which is an instance of the templated class ofPolyline<T>, the function getVertices return a vector<ofDefaultVertexType>, meaning a vector<ofDefaultVec3>, meaning a vector<glm::vec3>

I think I just prove my 2 points with this demonstration:

  • read the OF code may help us
  • better to learn enough C++ before !
    :smiley:

Happy OF learning and coding to you.

I totally agree. I’m starting out and so far I had to come up with solutions to my problems almost 100% on my own and the solutions were rather basic stuff, which could be easily included in the documentation, so it gets more transparent how a method etc. is actually used and applied. I wonder if I had already given up long time ago, wasn’t it for my basic understanding of maths and programming I already had.
It’s a shame that the documentation is so poor and that there is almost no book about openframeworks - instead for Processing there is abundance of study material.
I guess, one would have to contribute documentation oneself, but I really dont feel authorized and good enough to do such things. I find it rather surprising that the instructions and documentation are so poor or non existing after all the years this framework has already been around.

Hi @thomasprade1 ,

There are some really wonderful things that can help when learning oF. I find that reading older forum posts can be really helpful when trying to solve a particular problem. OpenFramework has really fantastic examples, where the various classes are used in basic ways. These are fun to consult, study, play around with, modify, and even extend in your own way. You can learn a lot by going thru the /examples folder. There are also a lot of chapters in ofBook that again cover various oF classes and concepts. Lewis Lepton and Dan Buzzo (and maybe some others) have created wonderful video tutorials. And there have been a couple/few books published over the years too; the ones published by Packt come to mind. Hope this is helpful and that you get a chance to find and use some of these resources as you continue learning oF.

Hi, well I will have to disagree with your idea that the documentation is poor. Although it is not the most straightforwards to find. All the classes are documented, and there are several books to learn from, including the ofBook.

The thing is that openFrameworks gives you a bunch of really useful tools that are very atomic, allowing you to do what ever you want with these. In this sense, you can not expect to get instructions to do every possible thing with these. As an analogy, lets take a knife. It is a really simple tool, yet incredibly useful and versitile, yet these dont come with instructions. If there were any, probably those would be very basic, as the ammount of things you can do with a knife are so many that you would need like several books to cover all these posibilities. At the same time, everyone has at least a very basic understandig on how to use a knife, yet at the same time you can find people incredibly skilled with it doing incredible stuff.
What I mean is, openFrameworks is similar. you can not expect to just install it and type 2 lines and get some awesome visual stuff, for example. You need to practice and get to know your tools (OF, C++, maths, GLSL, etc). There is where its power lies, otherwise, everything would look just the same.

This is an open source project and documentation comes just from any user, just like you. Don’t feel unauthorized, on the contrary, you are very welcome to contribute. If you find that there is something wrong in the documentation please fix it and submit a pull request in github.

Tip: instead of looking online what a class does, what are its methods and properties, just look at the .h files of the openframeworks library. It shows up in your IDE. And you will find in these an incredible amount of documentation, instructions and explanations.

https://openframeworks.cc/documentation/
https://openframeworks.cc/ofBook/chapters/foreword.html

1 Like