Several simple questions (HELP)

Hello, and happy new… ho wait, it’s too late now >__<

I’m trying to build a little 3D drawing software with LeapMotion, with a lot of functions, but i don’t understand several things to finnish it (they are not in my books and i’m not that good in english and OF to understand it in english), so i have tree questions:

1/ When i’m drawing, i’m using some vertx, like the leapMotion example. Problem: I want to draw several DIFFERENT 3D, so i’m asking: is there is anything to do it like in processing, like saying “new 3Dmesh” and keep the older one ? I can’t find it in my books :frowning:

2/ The other one is about the number of fingers that i want to use in the leapMotion software, for the moment, i’m using this code :

for(int a = 0; a < simpleHands.size(); a++){

    for(int q = 0; q < simpleHands[a].fingers.size(); q++){
        int id = simpleHands[a].fingers[q].id;
        ofPoint pt = simpleHands[a].fingers[q].pos;

}

3/ And the last question is: what is the code for "if this specific finger in the leap motion toutch this 3D, do this (like turn int e =0 , to int e = 1).

This 3 questions are my only problem in my code, actually, i’m using ofxSpeech, i’m drawing mesh, moving, and loading a 3D, change the materials, but… I just need this 3 little thing to finish my program, only this 3 little things !

Can you help me about it, you will give me a really happy new year :smiley:

Thank to all af you, and for your amazing work !

Vincent

Hey Vincent,

  1. what do you want to do. Do you want to draw multiple hands, or do you want to draw multiple meshes of other objects?

  2. please help me what exactly do you want to achieve… in your code you go through all fingers, but you don’t do anything with it. by the way, you’re not closing the second for()-loop, i guess that you do that in your code.
    anyway, there are several thing you can do: for example you can collect the positions of your fingertips as polylines in your update(), this is what i believe is also done in the example

    simpleHands = leap.getSimpleHands();

     if( leap.isFrameNew() && simpleHands.size() ){
     
         for(int i = 0; i < simpleHands.size(); i++){
         
             for(int j = 0; j < simpleHands[i].fingers.size(); j++){
                 int id = simpleHands[i].fingers[j].id;
             
                 ofPolyline & polyline = fingerTrails[id]; 
                 ofPoint pt = simpleHands[i].fingers[j].pos;
                 
                 //if the distance between the last point and the current point is too big - lets clear the line 
                 //this stops us connecting to an old drawing
                 if( polyline.size() && (pt-polyline[polyline.size()-1] ).length() > 50 ){
                     polyline.clear(); 
                 }
                 
                 //add our point to our trail
                 polyline.addVertex(pt); 
                 
                 //store fingers seen this frame for drawing
                 fingersFound.push_back(id);
             }
         }
     }
    

and then draw the lines in draw() e.g. like this

for (int i = 0; i < fingerTrails.size(); i++){
    ofPushStyle();
    ofNoFill();
    ofSetLineWidth(10);
    fingerTrails[i].draw();
    ofPopStyle();
}

if you want to use the amount of fingers as control you can make a switch…case or an

if( simpleHands[i].fingers.size() == 0){
//... do one thing
} else if ( simpleHands[i].fingers.size() == 1) {
//.. do something else
}

but… what exactly do you what you want to do?

  1. you would have to make a hit test for fingertip/mesh. this is quite complex, but check this: https://github.com/elliotwoods/ofxRay or https://github.com/NickHardeman/ofxBullet these should help you to do that.
    otherwise you maybe also could hit test for an imaginary box around your mesh. it’s a little clumsy but then you just have to look if the fingertip is in a certain x,y,z area, like this.

    if (fingertip.x > xMin && fingertip.x < xMax && fingertip.y > yMin && fingertip.y < yMax && fingertip.z > zMin && fingertip.z < zMax) {
    e = 0;
    } else {
    e = 1;
    }

So, I hope I could help a little. I think I could do more for you if you could explain exactly what you want to do in 1 & 2… didn’t totally understand that.

good luck!

Jakob

Thank you Jakob for this quick respond! It’s a pleasure to meet you.

1/ I’m trying to draw multiple mesh; like when you are drawing with a pencil, but with mesh, and a leap motion.

2/ I think that what you write :

if( simpleHands[i].fingers.size() == 0){
//… do one thing
} else if ( simpleHands[i].fingers.size() == 1) {
//… do something else
}

Is exactly what i need so i will try it.
My goal is to limitate the number of fingers that the leapMotion can detect.

3/I try ofxBullet, and i try the solution with some bullet-sphere on the fingers, but it crash, i will try your solution and ofxRay, you help me so much thank you !

For the software, here is what i’m trying to build: http://yourevoelution.com/
I’m trying to build an open-source community with it, and some factory are interested about it (i told them, it is like arduino, open-source community).
These are the tree question i need to know to do it by myself for the moment (or with people, when they will be interested by the project, i hope)

I hope it will work :slight_smile:
These solutions are the only things i need to build what i call « the ARK project ».

thank you Jakob :slight_smile:

Thank you !

Your solution about the amount of finger is perfect !
I’m still trying to work with ofxRay, but trust me, i will do it !

And if you have a solution about how i can draw multiple mesh, i take it too :slight_smile:

And an other one that i totally forgot: how i can export my model in .3ds or something like this ?

Anyone ?

there’s an addon which exports stl files, https://github.com/obviousjim/ofxSTL

i think the reason why no one answers, is that you easily could have found that yourself. all i did was to go on ofxaddons.com and searched for “export” and then i got the ofxSTL :wink:
to know which formats you want to use, you could for example go to “import” in your 3d programm, and then you will see which formats your program can easily import. stl is probably one of them.

for the other thing, if you want to have multiple meshes, then this is a question that has been answered already. you can find a nice tutorial on this site for example: http://openframeworks.cc/tutorials/graphics/generativemesh.html

for the hit-test, if you run into too many problems with the ofxRay/Bullet … have you tried the imaginary box? It might be easier to start with and work convincingly enough.
look, if you have a mesh, you can get its center position with .getCentroid(). This you can use as a reference point to create a simple box around it. To check if the finger is inside the box you can use my code from above with the xMin, xMax, etc. tip: if you do this in the update()-void, then you have it always at the correct position.
check this for example, not super-elegant but should work:

float xMin = mesh.getCentroid()-200;
float xMax = mesh.getCentroid()+200;
float yMin = mesh.getCentroid()-200;
float yMax = mesh.getCentroid()+200;
float zMin = mesh.getCentroid()-200;
float zMax = mesh.getCentroid()+200;

bool isFingerInsideBox = false;

if (fingertip.x > xMin && fingertip.x < xMax && fingertip.y > yMin && fingertip.y < yMax && fingertip.z > zMin && fingertip.z < zMax) {
isFingerInsideBox = true;
} else {
// ... 
}

I hope that i could give you a kick-start. have fun figuring it out! great to see you had use for the fingers :wink:

1 Like

Thank you for everything, i will try the hit test first, and, worok to understand for the mesh.

About my questions about how to export/save my 3D the thing is, i already find the addon, but i thougth someone have an other solution? something i didn’t find.

Now, working time ! I come back when i will succed :slight_smile:

Thank you again, really !

Vincent

I was trying to build an example of this code… but sorry, i need to ask you : how do you have the X, Y, and Z Leap position?
I can have the ofpoints, but how can you extract it from the point, or, just find it… I’m a little bit confuse about it ?

I think tomorrow, i will finish the part with the trail (i was building the menu), thank you again for your help :slight_smile:

Vincent

you remember that line from above?
there there you get the point with x, y and z coordinates for the finger. so all you have to do now, is this:

pt.x

to get the x-coordinate. and same for the others. i just called my point “fingertip”.
so if you take this and throw it in the function you should be able to check if the finger is inside the box or not. :wink:

Hello, thank you for all of your help, i do so much things with it, it’s really amazing!

But, i don’t know how you can transform mesh.GetCentroid() to a float ? like a Vector to a float ?
OF tell me, it is impossible… :frowning:

How did you do it ?

Thank you very much, and have a nice day !

Vincent

aah, my bad. i forgot a something, but it’s important for your understanding. well, the centroid is a vector of three floats ( ofVec3f ). it stores the x, y and z position. these floats you need to access, not the vector itself. so you don’t need to convert anything, you just have to access the floats inside the vector. you should be able to do it like this:

float xMin = mesh.getCentroid().x-200;
float xMax = mesh.getCentroid().x+200;
float yMin = mesh.getCentroid().y-200;
float yMax = mesh.getCentroid().y+200;
float zMin = mesh.getCentroid().z-200;
float zMax = mesh.getCentroid().z+200;

here, introduction to vectors http://openframeworks.cc/tutorials/maths/001_vector_maths.html