Combine jMonkeyEngine and Vuforia: Geometry doesn't remain at the center of the target -
i trying combine vuforia sdk , jmonkeyengine. cube placed on target (imagetarget) far. when move camera cube moves little bit too. want cube remains @ center of target (like teapot in vuforiasamples imagetarget). have idea how can solve problem?
i think relevant code:
public void initforegroundcamera() { foregroundcamera = new camera(settings.getwidth(), settings.getheight()); foregroundcamera.setlocation(new vector3f(0.0f, 0.0f, 0.0f)); // perspective transformation cameracalibration cameracalibration = cameradevice.getinstance().getcameracalibration(); videobackgroundconfig config = renderer.getinstance().getvideobackgroundconfig(); float viewportwidth = config.getsize().getdata()[0]; float viewportheight = config.getsize().getdata()[1]; float camerawidth = cameracalibration.getsize().getdata()[0]; float cameraheight = cameracalibration.getsize().getdata()[1]; float screenwidth = settings.getwidth(); float screenheight = settings.getheight(); vec2f size = new vec2f(camerawidth, cameraheight); vec2f focallength = cameracalibration.getfocallength(); float fovradians = 2 * (float) math.atan(0.5f * (size.getdata()[1] / focallength.getdata()[1])); float fovdegrees = fovradians * 180.0f / (float) math.pi; float aspectratio = (size.getdata()[0] / size.getdata()[1]); // adjust screen / camera size distortion float viewportdistort = 1.0f; if (viewportwidth != screenwidth) { viewportdistort = viewportwidth / screenwidth; fovdegrees = fovdegrees * viewportdistort; aspectratio = aspectratio / viewportdistort; log.v(tag, "viewportdistort: " + viewportdistort + " fovdegreed: " + fovdegrees + " aspectratio: " + aspectratio); } if (viewportheight != screenheight) { viewportdistort = viewportheight / screenheight; fovdegrees = fovdegrees / viewportdistort; aspectratio = aspectratio * viewportdistort; log.v(tag, "viewportdistort: " + viewportdistort + " fovdegreed: " + fovdegrees + " aspectratio: " + aspectratio); } setcameraperspectivefromvuforia(fovdegrees, aspectratio); setcameraviewportfromvuforia(viewportwidth, viewportheight, camerawidth, cameraheight); viewport foregroundviewport = rendermanager.createmainview("foregroundview", foregroundcamera); foregroundviewport.attachscene(rootnode); foregroundviewport.setclearflags(false, true, false); foregroundviewport.setbackgroundcolor(colorrgba.blue); sceneinitialized = true; } private void processtrackable(trackableresult result, int i) { // show 3d object corresponding on found trackable spatial model = rootnode.getchild(0); model.setcullhint(cullhint.dynamic); matrix44f modelviewmatrix_vuforia = tool.convertpose2glmatrix(result.getpose()); matrix44f inversematrix_vuforia = mathhelpers.matrix44finverse(modelviewmatrix_vuforia); matrix44f inversetransposedmatrix_vuforia = mathhelpers.matrix44ftranspose(inversematrix_vuforia); float[] modelviewmatrix = inversetransposedmatrix_vuforia.getdata(); // camera position float cam_x = modelviewmatrix[12]; float cam_y = modelviewmatrix[13]; float cam_z = modelviewmatrix[14]; // camera rotation float cam_right_x = modelviewmatrix[0]; float cam_right_y = modelviewmatrix[1]; float cam_right_z = modelviewmatrix[2]; float cam_up_x = modelviewmatrix[4]; float cam_up_y = modelviewmatrix[5]; float cam_up_z = modelviewmatrix[6]; float cam_dir_x = modelviewmatrix[8]; float cam_dir_y = modelviewmatrix[9]; float cam_dir_z = modelviewmatrix[10]; setcameraposefromvuforia(cam_x, cam_y, cam_z); setcameraorientationfromvuforia(cam_right_x, cam_right_y, cam_right_z, cam_up_x, cam_up_y, cam_up_z, cam_dir_x, cam_dir_y, cam_dir_z); } //we modify left axis of jme camera match coodindate system used vuforia private void setcameraperspectivefromvuforia(float fovy, float aspectratio) { foregroundcamera.setfrustumperspective(fovy, aspectratio, 1.0f, 1000.0f); foregroundcamera.update(); } private void setcameraposefromvuforia(float camx, float camy, float camz) { foregroundcamera.setlocation(new vector3f(camx, camy, camz)); foregroundcamera.update(); } private void setcameraorientationfromvuforia(float camrightx, float camrighty, float camrightz, float camupx, float camupy, float camupz, float camdirx, float camdiry, float camdirz) { foregroundcamera.setaxes(new vector3f(-camrightx, -camrighty, -camrightz), new vector3f(-camupx, -camupy, -camupz), new vector3f( camdirx, camdiry, camdirz)); foregroundcamera.update(); }
i have implemented vuforia jmonkey engine. must admit shaky movement of 3d models noticeable when hold phone still, whereas using opengl rendering engine vuforia alone doesn't produce such results.
reason might being rendered on screen quad texture being output camera, , takes while change every frame. while running app phone gets hot guess heavy load processor well.
Comments
Post a Comment