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 3eb9d61..2bd5d1d 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,22 +1,17 @@ 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; import com.google.ar.core.Frame; import com.google.ar.core.Session; import com.google.ar.core.examples.java.common.framework.model3D.Universe; -import com.google.ar.core.examples.java.common.framework.view3D.Camera3D; import com.google.ar.core.examples.java.common.framework.view3D.Viewer3D; import com.google.ar.core.examples.java.common.java3d.GraphicsContext3D; -import com.google.ar.core.examples.java.common.java3d.Light; import com.google.ar.core.examples.java.common.rendering.BackgroundRenderer; import com.google.ar.core.examples.java.helloar.HelloArActivity; import com.google.ar.core.exceptions.CameraNotAvailableException; -import java.util.ArrayList; - import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; @@ -36,8 +31,8 @@ } public void setSession(Session session) { - this.session = session; - } + this.session = session; + } // public void setBackgroundRenderer(BackgroundRenderer backgroundRenderer) { // this.backgroundRenderer = backgroundRenderer; @@ -51,27 +46,32 @@ @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { -// gc3D = new GraphicsContext3D(gl); + if (viewer == null) { + gc3D = new GraphicsContext3D(gl); + viewer = new Viewer3D(gc3D); + } else { + gc3D.setGL10(gl); + } // ArrayList lights = universe.getLights(); // for (int i = 0; i < lights.size(); i++){ // Light l = lights.get(i); // gc3D.setLight(l,i); // } -// viewer.setGraphicsContext3D(gc3D); helloArActivity.onSurfaceCreated(gl, config); } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { -// GLES20.glViewport(0, 0, width, height); -// if (gc3D == null) { -// gc3D = new GraphicsContext3D(gl); -// viewer.setGraphicsContext3D(gc3D); -// } else { -// viewer.setGraphicsContext3D(gc3D.setGL10(gl)); -// } -// viewer.surfaceChanged(width, height); + gl.glViewport(0, 0, width, height); + + if (viewer == null) { + gc3D = new GraphicsContext3D(gl); + viewer = new Viewer3D(gc3D); + } else { + gc3D.setGL10(gl); + } + viewer.surfaceChanged(width, height); helloArActivity.onSurfaceChanged(gl, width, height); } @@ -81,36 +81,35 @@ // GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); - if(session == null) { - return; - } - try { + if(session == null) { + return; + } + try { + // Viewerの更新 + if (viewer == null) { + gc3D = new GraphicsContext3D(gl); + viewer = new Viewer3D(gc3D); + } else { + gc3D.setGL10(gl); + } + viewer.onDrawFrame(); + + // Frameの取得 session.setCameraTextureName(backgroundRenderer.getTextureId()); + Frame frame = session.update(); - Frame frame = session.update(); - Camera camera = frame.getCamera(); - - if (viewer == null) { - viewer = new Viewer3D(camera); - } - - if (gc3D == null) { - gc3D = new GraphicsContext3D(gl); - viewer.setGraphicsContext3D(gc3D); - } else { - viewer.setGraphicsContext3D(gc3D.setGL10(gl)); - } - viewer.onDrawFrame(); - + // 背景(カメラ映像)の描画 backgroundRenderer.draw(gl, frame); - // 3Dモデルのレンダリング - gc3D.pushMatrix(); - universe.render(viewer); - gc3D.popMatrix(); + // 3Dモデルのレンダリング + gc3D.pushMatrix(); + Camera camera = frame.getCamera(); + viewer.updateCamera(camera); + universe.render(viewer); + gc3D.popMatrix(); helloArActivity.onDrawFrame(gl, frame, camera); - } catch (CameraNotAvailableException e) { - e.printStackTrace(); - } + } catch (CameraNotAvailableException e) { + e.printStackTrace(); + } } }