How can i make Interactive Floor Projection in openframework?


#1

Hi,

Using forum link

this link i found some reference for my project. But i don’t know how can I move object to detected blob.

Also i am not get any idea for how to come same position of image to its origin point after when user are walk to the surface.

https://www.youtube.com/watch?v=dOlExwZIHVo

Above link show what i like to do in my project with in openframework.

Can any guid me in this.

Thanks.


#2

Hi Saurabh,

I understand there are two main issues: detecting the blob, and moving the leafs when the blob is on top.

  1. Detecting the blob.

There are many ways to do this, i assume its done with a kinect or a real camera. In any case, you have to extract the position of the person/blob with reference to the image.

  1. Moving the leafs.

Each leaf has its poistion in the canvas, and when the blob is on top, you apply a repulsive force (move them away from the blob) temporarily, until the blob moves out of the way, and then you slowly move them back to their original position.

Problem 1) seems the harder to do, so I would recommend to start with 2) and use the mouse position as the blob position to test the 2) algorithm.

Cheers


#3

Hi Hennio,

Thanks for your great reply,

As per you reference i do 1 step, i am found blob with real camera.

But i am stuck with moving leaf to blob.So can u guide me with some code example to leaf move away to blob and after moving blob leaf are set its origin position.

Its very helpful to me.

Thanks.


#4

Lets assume you only have one leaf. You want the leaf to move away from the blob, so you will need to compute the distance between the blob and the leaf. There has to be at least a minumum distance between them, so if the distance between the leaf and the blob is smaller than the minimum distance, then the leaf will move away.

We can define a Leaf class:

class Leaf
{
private:
    ofVec2f m_position;
    ofVec2f m_currentPosition;
    double m_minDistance;
    bool bCanGoBack;
public:
    Leaf(const ofVec2f & position, double minDistance)
    {
        m_position = position;
        m_currentPosition = position;
        m_minDistance = minDistance;
        bCanGoBack = false;
    }

    void onBlobMove(const ofVec2f & blob)
    {
        ofVec2f leafToBlob = blob - m_currentPosition;
        double distance = leafToBlob.length();
        // if the blob is too close, then move away
    if(distance < m_minDistance)
    {
        m_currentPosition += (leafToBlob.getNormalized() * m_minDistance);
        bCanGoBack = false;
    }
    // if its far away, then we can go back to our position
    else
    {
        bCanGoBack = true;
    }

    void update()
    {
        if(bCanGoBack)
        {
            ofVec2f currentToOriginal = m_currentPosition - m_position;
            m_currentPosition += (currentToOriginal * 0.1);
        }
    }
}

Note I have not tested nor compiled this code, it only serves as a quick implementation example. I hope it helps you to start!!


#5

Hi Hennio,

Thanks for your reply,

can you guide me to my camera feed images are convert to particles like show in this video
https://www.youtube.com/watch?v=XOe1J7HJ2GE

How can i do this type of things in openframework.I have make some particle but how can I convert to my ofWidth in particle.

Above video are show my more what i can do in my project.

Thanks.


#6

You should distribute your particles uniformly along the screen, and assign the corresponding width to each so that the screen fills up.


#7

Hi Hennio,

Thank for reply,

but i don’t know which addon use for this project. And "[quote=“Hennio, post:6, topic:24682”]
You should distribute your particles uniformly along the screen,
[/quote]

how can i do that.

Please guide me here.


#8

Which addon to use is really up to you! The one which you find more useful for each task.

I can guide you if you have specific questions, not general questions. I recommend you to start up with the project, try to build some code, try minimal examples of what you want to achieve, and when you get stuck in the project come back to the forums to ask about the specific problems you’ve been having that dont allow you to advance.

Cheers!


#9

Hi Hennio,

Below is my code and all files in zip. When i run this code it show me error.
Interactive_Floor_3.zip (822.0 KB)

main.cpp (341 Bytes)
ofApp.cpp (10.1 KB)
ofApp.h (2.8 KB)

Using this i can make particle of my width.

So what i can do wrong here or missing something.

Thanks.


#10

Can you post the error?


#11

Hi Hennio,

this error i got show in below screen shot


#12

You are probably accessing “particles[a]” with “a” being greater than the size of the array. Debug and check that the index is never greater than the size of the array


#13

Hi Hennio,

Thanks for d reply,

Here is screenshot for size.


#14

Seems that you are not allocating space for the “particles” vector.

Change

particles[numPixelsSmall];
particles1[numPixelsSmall];
particles2[numPixelsSmall];

for

particles.resize(numPixelsSmall);
particles1.resize(numPixelsSmall);
particles2.resize(numPixelsSmall);

#15

Hi hennio,

Thanks for your reply,

thats works great.Now I am add more code in my project but this tie it give me this error.


#16

As you are working with ofxTraerPhysics, you can’t use the traer syntax position().x(), you have to use OF syntax

Change

position().x()

to

position.x

#17

Hi Hennio,

Thnaks for your reply,

now I have no error in my code and i make multi replicate image.This is my code below,

#include “ofApp.h”

//--------------------------------------------------------------
void ofApp::setup(){
img1.load(“3.png”);
leaf.load(“1.png”);
leaf1.load(“2.png”);
leaf2.load(“ninjatune.jpg”);
leaf3.load(“3.png”);
leaf4.load(“3.png”);

numPixels = leaf2.getWidth() * leaf2.getHeight();
widthSmall = leaf2.getWidth()/NTHPIXEL;
heightSmall = leaf2.getHeight()/NTHPIXEL;
numPixelsSmall = (widthSmall) * (heightSmall);

physics = *new ParticleSystem(0, 0.05);
p_mouse = physics.makeParticle();
p_mouse->makeFixed();
particles.resize(numPixelsSmall);
particles1.resize(numPixelsSmall);
particles2.resize(numPixelsSmall);
orgParticles.resize(numPixelsSmall);
colors[numPixelsSmall];

int a, z;
for (int x=0; x<widthSmall; x++) {           // go through all rows
    for (int y=0; y<heightSmall; y++) {        // go through all columns
        a = y*widthSmall+x;
        //  colors[a] = img.pixels[y*NTHPIXEL*img.width+x*NTHPIXEL];
        
        particles[a] = physics.makeParticle(ofRandom(MIN_MASS, MAX_MASS), x*NTHPIXEL, y*NTHPIXEL, 0);
        
        
        orgParticles[a] = physics.makeParticle( x*NTHPIXEL, y*NTHPIXEL, 0, ofRandom(MIN_MASS, MAX_MASS));
        
        orgParticles[a]->makeFixed();
        
        physics.makeSpring(particles[a], orgParticles[a], 0.002, 0.001, ofRandom(30) );
        
        
        
        // make the moving particles get away from the mouse
        physics.makeAttraction(particles[a], p_mouse, -500, 0.01 );
        
    }
}

}

//--------------------------------------------------------------
void ofApp::update(){
p_mouse->position.set(mouseX, mouseY, 0);
physics.tick();
for (int x=0; x<widthSmall; x++) {
for (int y=0; y<heightSmall; y++) {
unsigned a = y*widthSmall+x;
posx1 = particles[a]->position.x/10;
posy1 = particles[a]->position.y/10;

        cout << "in if";
        leaf1.draw( posx1*(9*10), posy1*(9*10), 90, 90);
        
        
    }
}

}

//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(100);
ofNoFill();
p_mouse->position.set(mouseX, mouseY, 0);
for (int x=0; x<widthSmall; x++) {
for (int y=0; y<heightSmall; y++) {
unsigned a = y*widthSmall+x;
posx1 = particles[a]->position.x/10;
posy1 = particles[a]->position.y/10;

        cout << "in if";
        leaf1.draw( posx1*(9*10), posy1*(9*10), 90, 90);
        
    }
}

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

Now this works great but leaf not move when i move my mouse position.

So what I am missing here.

Thanks.


#18

Hi saurabh,

I cant help you program the complete project. That is your job. This forum is intended to solve specific issues with code.

You should try to debug the code, invest time of your own to solve the issue instead of asking each time you get stuck, as that is the only way to learn.

There are plenty of resources online to learn c++, and plenty of books too (would recommend “Essential c++” from Stanley B. Lippman)

Cheers


#19

Hi Hennio,

Thanks for your helping me to solve this.

I am used Traer lib before in processing and using that I made to this project in java, I followed reference and make this in C++. Now [quote=“saurabh, post:17, topic:24682”]
physics.makeSpring(particles[a], orgParticles[a], 0.002, 0.001, ofRandom(30) );

    // make the moving particles get away from the mouse
    physics.makeAttraction(particles[a], p_mouse, -500, 0.01 );

[/quote]

this line is not work.Its not move my leaf to move my mouse movement.

So can you guide me for i am doing correct?

Thanks.


#20

Hi saurabh,

You should work on the project and deduce why it is not moving the leaf. Debug the application and check that the variable values are what you are expecting them to be.