1

I'm using wikitude and I need to get the screen coordinates of the recognized marker. I have converted the projectionViewMatrix to GLKMatrix4 and I've tried this code I've found on multiple sites:

let point = Point3D(x: m.m.12, y: m.m.13, z: m.m.14)//m is the matrix
let x = round(((CGFloat(point.x)+1)/2)*self.view.frame.width)
let y = round(((1-CGFloat(point.y))/2)*self.view.frame.height)

The thing is that if I center the marker than the view, I'm moving with those coordinates calculated, is centered too and when I move the marker the view moves in the right direction but it is moving "too fast" so it not stays on the marker but runs out of the screen in the direction I moved the marker.

Edit: This is the code I use to convert the pointer wikitude provides us to GLKMatrix4:

-(instancetype)initWithCArray:(const float *)pointer{
    self = [super init];
    if(self != nil){
        glkMatrix = GLKMatrix4Identity;
        memcpy(glkMatrix.m, pointer, 16*sizeof(float));
    }
    return self;
}
kemkriszt
  • 280
  • 3
  • 17
  • Please post some more code (creation of m) and some more information of whar you want to achiev (what marker; touch event?). – shallowThought Jan 11 '17 at 23:35
  • I have a class that handles the matrix. In the init method it takes an UnsafePointer and than it has a getMatrix() method that returns GLKMatrix4. I don't know where I found it becouse it was about I year ago. I've already used that class in seversl OpenGL/metal and wikitude project with success. The marker is just a simple image that wikitude recognizes. I would like to have the view follow my marker on the screen but this time I can't use OpenGL/metal becouse the view has to integrate later with my UI. (Animate and transform to a window, containing ios ui elements)No touchevents. – kemkriszt Jan 12 '17 at 08:59
  • Ok, I've just got to my computer. Added the code that converts that pointer wikitude provides us to GLKMatrix4 – kemkriszt Jan 12 '17 at 16:45

1 Answers1

0

Without testing, I do not understand why you want to round and suspect that is the root of the issue. Remove the rounding:

let x = CGFloat(((point.x + 1.0) / 2.0)) * self.view.frame.width
let y = CGFloat(((1.0 - point.y) / 2.0)) * self.view.frame.height

Also, I would think y should be handled like x(...point.y + 1.0), but as you are saying the direction is right, I am probably wrong.

shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • Well, I don't know what is going on.. I don't know what I've changed but now with or without round the axes got swapped (If I move it up-down it moves right-left and vica-versa).. – kemkriszt Jan 12 '17 at 17:55