diff --git a/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java b/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java index dbe10e2..965bd65 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java +++ b/app/src/main/java/com/google/ar/core/examples/java/common/framework/RWT/RWTRenderer.java @@ -1,5 +1,6 @@ package com.google.ar.core.examples.java.common.framework.RWT; +import android.opengl.GLES20; import android.opengl.GLSurfaceView.Renderer; import com.google.ar.core.Camera; @@ -63,7 +64,7 @@ @Override public void onSurfaceChanged(GL10 gl, int width, int height) { - gl.glViewport(0, 0, width, height); + GLES20.glViewport(0, 0, width, height); if (viewer == null) { gc3D = new GraphicsContext3D(gl); diff --git a/app/src/main/java/com/google/ar/core/examples/java/common/framework/view3D/Viewer3D.java b/app/src/main/java/com/google/ar/core/examples/java/common/framework/view3D/Viewer3D.java index d25694f..73b1f40 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/common/framework/view3D/Viewer3D.java +++ b/app/src/main/java/com/google/ar/core/examples/java/common/framework/view3D/Viewer3D.java @@ -34,11 +34,13 @@ this.width =width; this.height = height; if (camera != null) { - float focalLength = camera.getImageIntrinsics().getFocalLength()[0]; + float xfocalLength = camera.getImageIntrinsics().getFocalLength()[0]; + float yfocalLength = camera.getImageIntrinsics().getFocalLength()[1]; // gc3D.update(width, height, (float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), false); float w = (float)camera.getImageIntrinsics().getImageDimensions()[1]; -// height = camera.getImageIntrinsics().getImageDimensions()[0]; - gc3D.update(this.width, this.height, (float) Math.atan(w / 2.0f / focalLength) * 2.0f, 0.1f, 100.0f, false); + float h = (float)camera.getImageIntrinsics().getImageDimensions()[0]; +// gc3D.update(this.width, this.height, (float) Math.atan(w / 2.0f / xfocalLength) * 2.0f, 0.1f, 100.0f, false); + gc3D.update(this.width, this.height, h, yfocalLength, 0.1f, 100.0f, false); } } @@ -56,12 +58,14 @@ float viewPoint[] = camera.getDisplayOrientedPose().getTranslation(); float viewLine[] = camera.getDisplayOrientedPose().getZAxis(); float viewUp[] = camera.getDisplayOrientedPose().getYAxis(); - float focalLength = camera.getImageIntrinsics().getFocalLength()[0]; + float xfocalLength = camera.getImageIntrinsics().getFocalLength()[0]; + float yfocalLength = camera.getImageIntrinsics().getFocalLength()[1]; Position3D eye = new Position3D(viewPoint[0], viewPoint[1], viewPoint[2]); Position3D center = eye.clone().add(new Vector3d(-viewLine[0], -viewLine[1], -viewLine[2])); Vector3d up = new Vector3d(viewUp[0], viewUp[1] * camera.getPose().qy(), viewUp[2]); float w = (float)camera.getImageIntrinsics().getImageDimensions()[1]; - gc3D.update(width, height, (float) Math.atan(w / 2.0f / focalLength) * 2.0f, 0.1f, 100.0f, eye, center, up, false); + float h = (float)camera.getImageIntrinsics().getImageDimensions()[0]; + gc3D.update(this.width, this.height, h, yfocalLength, 0.1f, 100.0f, eye, center, up, false); } } diff --git a/app/src/main/java/com/google/ar/core/examples/java/common/java3d/GraphicsContext3D.java b/app/src/main/java/com/google/ar/core/examples/java/common/java3d/GraphicsContext3D.java index 371b943..48ddffd 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/common/java3d/GraphicsContext3D.java +++ b/app/src/main/java/com/google/ar/core/examples/java/common/java3d/GraphicsContext3D.java @@ -53,7 +53,8 @@ gl.glClearDepthf(1.0f); } - public void update(int width, int height, float fovx, float zNear, float zFar,boolean fParallel) { +// public void update(int width, int height, float fovx, float zNear, float zFar,boolean fParallel) { + public void update(int width, int height, float h, float yfocalLength, float zNear, float zFar,boolean fParallel) { setGL10(gl); if (!bFixAspect) { aspect = (float)width / (float)height; @@ -66,7 +67,8 @@ gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 gl.glLoadIdentity(); // 座標の初期化 // 画角の設定 - float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); +// float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); + float fovy = (float) (Math.atan(h / 2.0f / yfocalLength) / Math.PI * 360.0f); if(!fParallel){ GLU.gluPerspective(gl, fovy, //Y方向の画角 @@ -98,14 +100,16 @@ gl.glLoadIdentity(); // 座標の初期化 } - public void update(int width, int height, float fovx, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { +// public void update(int width, int height, float fovx, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { + public void update(int width, int height, float h, float yfocalLength, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { aspect = (float)width / (float)height; // カメラの設定 gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 gl.glLoadIdentity(); // 座標の初期化 // 画角の設定 - float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); +// float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); + float fovy = (float) (Math.atan(h / 2.0f / yfocalLength) / Math.PI * 360.0f); if (!fParallel) { GLU.gluPerspective(gl, fovy, //Y方向の画角 diff --git a/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java b/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java index 9c57b18..80e10bd 100644 --- a/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java +++ b/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java @@ -266,8 +266,6 @@ // virtualObjectShadow.setBlendMode(BlendMode.Shadow); // virtualObjectShadow.setMaterialProperties(1.0f, 0.0f, 0.0f, 1.0f); // -//// renderer.onSurfaceCreated(gl, config); -// } catch (IOException e) { Log.e(TAG, "Failed to read an asset file", e); } @@ -409,7 +407,7 @@ // space. This anchor is created on the Plane to place the 3D model // in the correct position relative both to the world and to the plane. ColoredAnchor anchor = new ColoredAnchor(hit.createAnchor(), objColor); - anchors.add(anchor); + double px = anchor.anchor.getPose().tx(); double py = anchor.anchor.getPose().ty(); double pz = anchor.anchor.getPose().tz(); @@ -423,6 +421,7 @@ } catch (ModelFileFormatException e) { e.printStackTrace(); } + anchors.add(anchor); break; } }