- Sort Posts
- 11 replies
- Last post
Re: Find Trackable (x,y) Position on Screen ?
Hi,
I'm trying to adapt it to iPhone, or find something similar. When I use this code, there is an offset.
Here is the function adapted :
- (CGPoint) cameraPointToScreenPoint:(QCAR::Vec2F)cameraPoint { QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT); QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig(); int xOffset = ((int) self.frame.size.width - config.mSize.data[0]) / 2.0f + config.mPosition.data[0]; int yOffset = ((int) self.frame.size.height - config.mSize.data[1]) / 2.0f - config.mPosition.data[1]; if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) { // camera image is rotated 90 degrees int rotatedX = videoMode.mHeight - cameraPoint.data[1]; int rotatedY = cameraPoint.data[0]; return CGPointMake(rotatedX * config.mSize.data[0] / (float) videoMode.mHeight + xOffset, rotatedY * config.mSize.data[1] / (float) videoMode.mWidth + yOffset); } else { return CGPointMake(cameraPoint.data[0] * config.mSize.data[0] / (float) videoMode.mWidth + xOffset, cameraPoint.data[1] * config.mSize.data[1] / (float) videoMode.mHeight + yOffset); } }
Is there something different on iPhone ?
Sorry if this is an Androïd restricted area ;)
Re: Find Trackable (x,y) Position on Screen ?
sure, the code I posted above works just fine.
xyPoint.data contains the coordinates. I think if you modify QCAR::Vec3F(0,0,0) you could somehow get the target's corners
I could post some more code that tranfers the data to java if you want.
So I'm guessing QCAR::Vec3F(0,0,0) means the center of the target. So the xyPoint would be the x,y coords for the target center?
To get the left corner would it be this?
QCAR::Vec2F target_size = target->getSize();
GLfloat x= target_size.data[0]/2;
GLfloat y = target_size.data[1]/2;
QCAR::Vec3F(-x,y,0); ???
Re: Find Trackable (x,y) Position on Screen ?
Re: Find Trackable (x,y) Position on Screen ?
thank you for your answer ksiva.
first, my knowledge in openGL is very limited, but I think the standart openGL transformations are not available in ES 2.0:
"OpenGL ES 2.0 does not support the fixed function transformation and fragment pipeline of OpenGL ES 1.x."
if I understand your second suggestions correctly, this code should get me the screen point.
[CODE" />
const QCAR::Tracker& tracker = QCAR::Tracker::getInstance();
const QCAR::CameraCalibration& cameraCalibration = tracker.getCameraCalibration();
QCAR::Vec2F cameraPoint = QCAR::Tool::projectPoint(cameraCalibration,trackable->getPose(), QCAR::Vec3F(0,0,0));
QCAR::Vec2F xyPoint = cameraPointToScreenPoint(cameraPoint);
[/CODE" />
*edit* found my error, code updated. coordinates look good, thanks !
Re: Find Trackable (x,y) Position on Screen ?
Re: Find Trackable (x,y) Position on Screen ?
Re: Find Trackable (x,y) Position on Screen ?
ok, maybe I should eloborate a bit...
when a frame is rendered and a trackable is detected I can its position using:
trackable->getPose());
which gets me an undocumented '3x4 QCAR pose matrix'.
and can transform it to an (also undocumented)' QCAR::Matrix44F':
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
So how can I derive the user space position from this ?
I solved my problem with this post, thanks.