Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Pass kinect as argument to class method?

$
0
0

@kflak1 wrote:

Hi guys,

I’m trying to pass a kinect object in my ofApp.* to a method in a custom class MinDistance, but it doesn’t compile. My class header looks like this:

#ifndef _MINDISTANCE
#define _MINDISTANCE
#include "ofMain.h"

class MinDistance {
    public: 
        void setup();
        void update();
        void draw();

        int minDistX;
        int minDistY;

        MinDistance();

        ofxKinect kinect;

    private:
};
#endif

My implementation file looks like this:

#include "MinDistance.h"

MinDistance::MinDistance(){
}

void MinDistance::setup(ofxKinect _kinect){
    kinect = _kinect;
}

void MinDistance::update(){
    int w = 640;
    int h = 480;
    int step = 2;
    int minDistance = 3000;
    for(int x = 0; x < w; x+=step){
        for (int y = 0; y < h; y+=step){
            int kd = kinect.getDistanceAt(x, y);
            if (kd>0 && kd<minDistance) {
                minDistance = kd;
                minDistX = x;
                minDistY = y;
            } 
        }
    }
}

void MinDistance::draw(){
    ofNoFill;
    ofDrawCircle(
            ofMap(minDistX, 0, 640, 0, ofGetWidth()),
            ofMap(minDistY, 0, 480, 0, ofGetHeight()),
            24);
}

Which produces the following compiler error:

In file included from /home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.cpp:1:
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.h: At global scope:
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.h:16:9: error: ‘ofxKinect’ does not name a type
   16 |         ofxKinect kinect;
      |         ^~~~~~~~~
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.cpp:6:25: error: variable or field ‘setup’ declared void
    6 | void MinDistance::setup(ofxKinect _kinect){
      |                         ^~~~~~~~~
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.cpp:6:25: error: ‘ofxKinect’ was not declared in this scope
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.cpp: In member function ‘void MinDistance::update()’:
/home/kf/of/of_v0.11.0_linux64gcc6_release/apps/myApps/kinect/src/MinDistance.cpp:17:22: error: ‘kinect’ was not declared in this scope
   17 |             int kd = kinect.getDistanceAt(x, y);
      |                      ^~~~~~

The kinect and custom class is defined in the ofApp.h like this:

ofxKinect kinect;
MinDistance minDistance;       

… and I would like to be able to call it like this:

minDistance.setup(kinect);

Any and all help much appreciated!

K

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles