How can I access a matrix which the current frame anchor has?


#1

I’m struggling with ofxARKit…
I guess the current frame anchors increase automatically and each of them has a matrix to transform.
Btw how can I access them to iterate the other objects.

example code is below.

for (int i = 0; i < session.currentFrame.anchors.count; i++){
    ARAnchor * anchor = session.currentFrame.anchors[i];
    
    // note - if you need to differentiate between different types of anchors, there is a 
    // "isKindOfClass" method in objective-c that could be used. For example, if you wanted to 
    // check for a Plane anchor, you could put this in an if statement.
    // if([anchor isKindOfClass:[ARPlaneAnchor class]]) { // do something if we find a plane anchor}
    // Not important for this example but something good to remember.
    
    ofPushMatrix();
    ofMatrix4x4 mat = ARCommon::convert<matrix_float4x4, ofMatrix4x4>(anchor.transform);
    ofMultMatrix(mat);
    
    ofSetColor(255);
    ofRotate(90,0,0,1);
    
    img.draw(-0.025 / 2, -0.025 / 2,0.025,0.025);
    
    
    ofPopMatrix();
}

I wanna do like below.
As I said above current frame anchors increase automatically so “out of index” error happens…

for (int i = 0; i < session.currentFrame.anchors.count; i++){
    img[i].draw();
}

Does anyone have an idea?


#2

I forgot to update my sources copied from example projects and I solved it.