By Sceada
on Wed, 06/20/2012 - 17:09
Hi,
I want to get the 2D-Screen-Coordinate for an 3D-Object to place a tap-event (Tap Event works fine only the 2D-Screen-Coordinate for an 3D-Object is needed).
My first step was to calculate the 2D-Screen-Coordinate for the tracking image.
[QUOTE]
QCAR::Matrix44F modelViewMatrix =
QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
const QCAR::CameraCalibration& cameraCalibration = QCAR::CameraDevice::getInstance().getCameraCalibration();
QCAR::Vec2F screenPoint = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(0, 0, 0));
//LOG("camera point: %f, %f", screenPoint.data[0], screenPoint.data[1]);
QCAR::VideoMode videoMode = QCAR::CameraDevice::getInstance().getVideoMode(QCAR::CameraDevice::MODE_DEFAULT);
QCAR::VideoBackgroundConfig config = QCAR::Renderer::getInstance().getVideoBackgroundConfig();
float xOffset = ((float) screenWidth - config.mSize.data[0]) / 2.0f + config.mPosition.data[0];
float yOffset = ((float) screenHeight - config.mSize.data[1]) / 2.0f - config.mPosition.data[1];
[B]float x[/B] = (screenPoint.data[0] * config.mSize.data[0]) / ((float) videoMode.mWidth + xOffset);
[B]float y[/B] = (screenPoint.data[1] * config.mSize.data[1]) / ((float) videoMode.mHeight + yOffset);
[/QUOTE]
My next step was to insert a 3D-Object which I translated a little bit:
[QUOTE]
SampleUtils::translatePoseMatrix(50, -50, 50,
&modelViewMatrix.data[0]);
[/QUOTE]
I know that every Object has it's origin at 0,0,0 and that's the center from the tracking image which I already got. My suggestion was it to use the translate parameter as an offset. The result was very confusing.
After this fail, I searched inside of the QCAR/Include Folder for some help and found the Tool.h file with a method called projectPoint. What I have done now is to paste the values, which i used to translate my 3D-Object (50,-50,50), instead of 0,0,0:
[QUOTE]
QCAR::Vec2F object = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(50, -60, 50)); ("-60" works better for me)[/QUOTE]
I'm not quite convinced about the result. It seems to work but i'm not sure. Any comment on this case, is my last attempt right?
Robert
Re: 3D Object Position
Re: 3D Object Position