Cardboard
Android 를 위한 저렴한 VR
Youngbin Han
<sukso96100@gmail.com>
VR(Virtual Reality)?
http://blogs-images.forbes.com/danielnyegriffiths/files/2014/05/OculusRift1.jpg
https://s3.amazonaws.com/ksr/projects/476061/photo-main.jpg?1397812032
http://www.realareal.com/wp-content/uploads/2013/08/Oculus_VR_Immeractive_Haeva.jpg
$$$$$$$$
https://www.oculusvr.com/order/
g.co/cardboard
g.co/cardboard
http://www.dodocase.com/products/google-cardboard-vr-goggle-toolkit
Cardboard : Android 를 위한 저렴한 VR
Cardboard : Android 를 위한 저렴한 VR
Cardboard : Android 를 위한 저렴한 VR
Cardboard : Android 를 위한 저렴한 VR
Cardboard VR Toolkit
https://developers.google.com/cardboard/overview
Toolkit을 이용하면 다음을 포함한
많은 공통된 VR 개발을 단순화 할 수 있습니다.
● 렌즈 왜곡 보정
● 머리 추적
● 3D 교정
● 양쪽에 나란히 렌더링
● 입체 형상 구성
● 사용자 입력 이벤트 처리
간단한 Cardboard 앱 만들기.
만들기 어려운 건 함정
https://developers.google.com/cardboard/get-started
준비할 것들...
...
프로젝트에 라이브러리 추가
https://github.com/googlesamples/cardboard/blob/master/CardboardSample/libs/cardboard.jar
권장되는 Manifest.xml 설정
<manifest ...
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />
...
<uses-sdk android:minSdkVersion="16"/>
<uses-feature android:glEsVersion="0x00020000"
android:required="true" />
<application
...
<activity
android:screenOrientation="landscape"
...
</activity>
</application>
</manifest>
가로 모드
Open GL ES 사용
NFC 및
진동 권한
Android 4.1 +
CardboardActivity 상속받기
public class CardboardActivityExample
extends CardboardActivity {
…
}
CardboardView.StereoRenderer 구현하기
public class CardboardActivityExample
extends CardboardActivity implements
CardboardView.StereoRenderer {
…
}
CardboardView 초기화
private float[] mModelCube;
private float[] mCamera;
private float[] mView;
private float[] mHeadView;
private float[] mModelViewProjection;
private float[] mModelView;
private float[] mModelFloor;
private Vibrator mVibrator;
…
*
*
* Sets the view to our CardboardView and
initializes the transformation matrices we
will use
* to render our scene.
* @param savedInstanceState
*/
…
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.common_ui);
CardboardView cardboardView =
(CardboardView) findViewById(R.id.
common_paperscope_view);
// Associate a CardboardView.StereoRenderer
with cardboardView.
cardboardView.setRenderer(this);
// Associate the cardboardView with this
activity.
setCardboardView(cardboardView);
mModelCube = new float[16];
mCamera = new float[16];
mView = new float[16];
mModelViewProjection = new float[16];
mModelView = new float[16];
mModelFloor = new float[16];
mHeadView = new float[16];
mVibrator = (Vibrator) getSystemService
(Context.VIBRATOR_SERVICE);
…
}
뷰 렌더링 하기
CardboardView.StereoRenderer 를 통해 구현한,
onNewFrame(), onDrawEye() 사용.
onNewFrame() 구현하기
private int mGlProgram = GLES20.glCreateProgram();
private int mPositionParam;
private int mNormalParam;
private int mColorParam;
private int mModelViewProjectionParam;
private int mLightPosParam;
private int mModelViewParam;
private int mModelParam;
private int mIsFloorParam;
private float[] mHeadView;
...
/**
* Prepares OpenGL ES before we draw a frame.
* @param headTransform The head transformation in
the new frame.
*/
…
…
@Override
public void onNewFrame(HeadTransform headTransform) {
GLES20.glUseProgram(mGlProgram);
mModelViewProjectionParam = GLES20.
glGetUniformLocation(mGlProgram, "u_MVP");
mLightPosParam = GLES20.glGetUniformLocation
(mGlProgram, "u_LightPos");
mModelViewParam = GLES20.glGetUniformLocation
(mGlProgram, "u_MVMatrix");
mModelParam = GLES20.glGetUniformLocation
(mGlProgram, "u_Model");
mIsFloorParam = GLES20.glGetUniformLocation
(mGlProgram, "u_IsFloor");
// Build the Model part of the ModelView matrix.
Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5
f, 1.0f);
// Build the camera matrix and apply it to the
ModelView.
Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
headTransform.getHeadView(mHeadView, 0);
checkGLError("onReadyToDraw");
}
onDrawEye() 구현하기
private int mPositionParam;
private int mNormalParam;
private int mColorParam;
// We keep the light always position
just above the user.
private final float[]
mLightPosInEyeSpace = new float[] {0.0f,
2.0f, 0.0f, 1.0f};
...
/**
* Draws a frame for an eye. The
transformation for that eye (from the
camera) is passed in as
* a parameter.
* @param transform The transformations
to apply to render this eye.
*/
…
@Override
public void onDrawEye(EyeTransform transform) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.
GL_DEPTH_BUFFER_BIT);
mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
GLES20.glEnableVertexAttribArray(mPositionParam);
GLES20.glEnableVertexAttribArray(mNormalParam);
GLES20.glEnableVertexAttribArray(mColorParam);
checkGLError("mColorParam");
// Apply the eye transformation to the camera.
Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
// Set the position of the light
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0,
mLightPosInWorldSpace, 0);
GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0],
mLightPosInEyeSpace[1],
mLightPosInEyeSpace[2]);
// Build the ModelView and ModelViewProjection matrices
// for calculating cube position and light.
Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0);
Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(),
0, mModelView, 0);
drawCube();
// Set mModelView for the floor, so we draw floor in the correct
location
Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(),
0,
mModelView, 0);
...
}
자석 버튼 누름 감지하기
MagnetSensor.OnCardboardTriggerListener 사용
private Vibrator mVibrator;
private CardboardOverlayView mOverlayView;
...
/**
* Increment the score, hide the object,
and give feedback if the user pulls the
magnet while
* looking at the object. Otherwise,
remind the user what to do.
*/
@Override
public void onCardboardTrigger() {
if (isLookingAtObject()) {
mScore++;
mOverlayView.show3DToast("Found
it! Look around for another one.nScore =
" + mScore);
...
} else {
mOverlayView.show3DToast("Look
around to find the object!");
}
// Always give user feedback
mVibrator.vibrate(50);
}
/**
* Check if user is looking at object by
calculating where the object is in eye-
space.
* @return
*/
private boolean isLookingAtObject() {
float[] initVec = {0, 0, 0, 1.0f};
float[] objPositionVec = new float[4];
// Convert object space to camera
space. Use the headView from onNewFrame.
Matrix.multiplyMM(mModelView, 0,
mHeadView, 0, mModelCube, 0);
Matrix.multiplyMV(objPositionVec, 0,
mModelView, 0, initVec, 0);
float pitch = (float)Math.atan2
(objPositionVec[1], -objPositionVec[2]);
float yaw = (float)Math.atan2
(objPositionVec[0], -objPositionVec[2]);
...
return (Math.abs(pitch) < PITCH_LIMIT)
&& (Math.abs(yaw) < YAW_LIMIT);
}
Cardboard 앱 시연
(예제 앱) Treasure Hunt
Cardboard Demo 앱
참고자료
● https://developers.google.com/cardboard/get-started
● g.co/cardboard
● http://www.khronos.org/opengles/sdk/docs/man/
Thank You!

More Related Content

PDF
WebVR - MobileTechCon Berlin 2016
PDF
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
PPTX
WebGL: The Next Generation
PPTX
WebGL - It's GO Time
PDF
Gdg san diego android 11 meetups what's new in android - ui and dev tools
PDF
루팅(Rooting)에 관해
PDF
컴피즈로 화려한 효과내기
PDF
데스크탑 환경 구성요소
WebVR - MobileTechCon Berlin 2016
Портируем существующее Web-приложение в виртуальную реальность / Денис Радин ...
WebGL: The Next Generation
WebGL - It's GO Time
Gdg san diego android 11 meetups what's new in android - ui and dev tools
루팅(Rooting)에 관해
컴피즈로 화려한 효과내기
데스크탑 환경 구성요소

Viewers also liked (20)

PDF
Git&GitHub 를 이용한 버전관리와 협업 - 4.협업과 지속적 통합
PDF
[NDC10] Unity Build 로 빌드타임 반토막내기 - 송창규
PDF
2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디
PDF
0.Before Get Started - 시온고등학교 안드로이드 스터디
PDF
우분투 12.04 편법으로 외장하드에 설치해보기
PDF
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
PDF
제2회 SSSCON - 웹해킹 스터디 현황
PDF
02.모의해킹전문가되기
PDF
4년치 컨닝페이퍼
PDF
2016 D.LAB Recruit 160713
PDF
한글시계웍샵_SW
PDF
[NDC2014] 반응적 라이브 개발
PDF
[NDC13] 70명이 커밋하는 라이브 개발하기 (해외 진출 라이브 프로젝트의 개발 관리) - 송창규
PPTX
Windows system - memory개념잡기
PDF
What is agile
PPTX
개발자들 오리엔테이션
PDF
모바일앱 개발에서 개발자가 알아야할 팁
PDF
린 소프트웨어 개발(Lean software development)
PDF
칸반(Kanban)
PDF
JSP 빠르게 시작하기
Git&GitHub 를 이용한 버전관리와 협업 - 4.협업과 지속적 통합
[NDC10] Unity Build 로 빌드타임 반토막내기 - 송창규
2.Connect Sunshine to the Cloud - 시온고 안드로이드 스터디
0.Before Get Started - 시온고등학교 안드로이드 스터디
우분투 12.04 편법으로 외장하드에 설치해보기
1.Create Project Sunshine - 시온고등학교 안드로이드 스터디
제2회 SSSCON - 웹해킹 스터디 현황
02.모의해킹전문가되기
4년치 컨닝페이퍼
2016 D.LAB Recruit 160713
한글시계웍샵_SW
[NDC2014] 반응적 라이브 개발
[NDC13] 70명이 커밋하는 라이브 개발하기 (해외 진출 라이브 프로젝트의 개발 관리) - 송창규
Windows system - memory개념잡기
What is agile
개발자들 오리엔테이션
모바일앱 개발에서 개발자가 알아야할 팁
린 소프트웨어 개발(Lean software development)
칸반(Kanban)
JSP 빠르게 시작하기
Ad

Similar to Cardboard : Android 를 위한 저렴한 VR (20)

PDF
WebVR - JAX 2016
KEY
Leaving Flatland: getting started with WebGL
PPTX
Developing Web Graphics with WebGL
PDF
Ujug07presentation
KEY
FLAR Workflow
PPTX
OpenGL_summer2012.ccccccccccccccccccpptx
PDF
Webgl para JavaScripters
PPTX
Hacking Reality: Browser-Based VR with HTML5
PDF
Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
PDF
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
PDF
Virtual Reality in Android
PPT
Augmented Reality With FlarToolkit and Papervision3D
PPTX
WebGL, HTML5 and How the Mobile Web Was Won
PDF
Introduction to Grunt.js on Taiwan JavaScript Conference
PPTX
HTML5 and Other Modern Browser Game Tech
PDF
203 Is It Real or Is It Virtual? Augmented Reality on the iPhone
PDF
Introduction to WebGL and WebVR
PDF
Polymer, A Web Component Polyfill Library
PDF
Introduction to WebVR Autodesk Forge 2016
PDF
iOS OpenGL
WebVR - JAX 2016
Leaving Flatland: getting started with WebGL
Developing Web Graphics with WebGL
Ujug07presentation
FLAR Workflow
OpenGL_summer2012.ccccccccccccccccccpptx
Webgl para JavaScripters
Hacking Reality: Browser-Based VR with HTML5
Making Games in WebGL - Aro Wierzbowski & Tomasz Szepczyński
WT-4064, Build Rich Applications with HTML5 and WebGL, by Tony Parisi
Virtual Reality in Android
Augmented Reality With FlarToolkit and Papervision3D
WebGL, HTML5 and How the Mobile Web Was Won
Introduction to Grunt.js on Taiwan JavaScript Conference
HTML5 and Other Modern Browser Game Tech
203 Is It Real or Is It Virtual? Augmented Reality on the iPhone
Introduction to WebGL and WebVR
Polymer, A Web Component Polyfill Library
Introduction to WebVR Autodesk Forge 2016
iOS OpenGL
Ad

More from Youngbin Han (20)

PDF
Ubucon Europe and Asia
PDF
우분투 아시아 컨퍼런스 바닥에서 시작하기
PDF
Automating boring and repetitive UbuCon Asia video and subtitle stuffs
PDF
Engaging new l10n contributors through Open Source Contributhon
PDF
Introduction to Hanjp-IM Project (DebConf18 - Hsinchu, Taiwan)
PDF
What's new in Ubuntu 18.04 LTS
PDF
Naver Campus Hackday Winter 2017 참가 후기
PDF
우분투한국커뮤니티 2017년 활동보고
PDF
FluxSync Team 중간보고
PDF
openSUSE.Asia Summit 2017 Tokyo 참관후기
PDF
How & Why we have connected Slack & IRC
PDF
SKHUFEEDS 소개 발표자료(노트 포함)
PDF
SKHUFEEDS 소개 발표자료
PDF
Snaps on Ubuntu Desktop
PDF
How and why we have integrated Slack and IRC
PDF
Ubuntu's Unity - Birth to Death(in 5minutes)
PDF
Jekyll and GitHub Pages
PDF
Git&GitHub 를 이용한 버전관리와 협업 - 2.비교하기와 되돌리기
PDF
Git&GitHub 를 이용한 버전관리와 협업 - 1.첫 커밋 푸시하기
PDF
Node.js 런타임 버전 관리하기
Ubucon Europe and Asia
우분투 아시아 컨퍼런스 바닥에서 시작하기
Automating boring and repetitive UbuCon Asia video and subtitle stuffs
Engaging new l10n contributors through Open Source Contributhon
Introduction to Hanjp-IM Project (DebConf18 - Hsinchu, Taiwan)
What's new in Ubuntu 18.04 LTS
Naver Campus Hackday Winter 2017 참가 후기
우분투한국커뮤니티 2017년 활동보고
FluxSync Team 중간보고
openSUSE.Asia Summit 2017 Tokyo 참관후기
How & Why we have connected Slack & IRC
SKHUFEEDS 소개 발표자료(노트 포함)
SKHUFEEDS 소개 발표자료
Snaps on Ubuntu Desktop
How and why we have integrated Slack and IRC
Ubuntu's Unity - Birth to Death(in 5minutes)
Jekyll and GitHub Pages
Git&GitHub 를 이용한 버전관리와 협업 - 2.비교하기와 되돌리기
Git&GitHub 를 이용한 버전관리와 협업 - 1.첫 커밋 푸시하기
Node.js 런타임 버전 관리하기

Recently uploaded (20)

PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PPTX
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
PPTX
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
PPTX
FLIGHT TICKET API | API INTEGRATION PLATFORM
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Chapter_05_System Modeling for software engineering
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PDF
Mobile App for Guard Tour and Reporting.pdf
PPTX
Chapter 1 - Transaction Processing and Mgt.pptx
PPTX
Human Computer Interaction lecture Chapter 2.pptx
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PPTX
Beige and Black Minimalist Project Deck Presentation (1).pptx
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PPTX
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
PPTX
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
PDF
Engineering Document Management System (EDMS)
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PDF
What Makes a Great Data Visualization Consulting Service.pdf
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
Independent Consultants’ Biggest Challenges in ERP Projects – and How Apagen ...
FLIGHT TICKET API | API INTEGRATION PLATFORM
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Chapter_05_System Modeling for software engineering
Comprehensive Guide to Digital Image Processing Concepts and Applications
Mobile App for Guard Tour and Reporting.pdf
Chapter 1 - Transaction Processing and Mgt.pptx
Human Computer Interaction lecture Chapter 2.pptx
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
Beige and Black Minimalist Project Deck Presentation (1).pptx
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
Engineering Document Management System (EDMS)
Folder Lock 10.1.9 Crack With Serial Key
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
What Makes a Great Data Visualization Consulting Service.pdf

Cardboard : Android 를 위한 저렴한 VR

  • 1. Cardboard Android 를 위한 저렴한 VR Youngbin Han <[email protected]>
  • 16. Toolkit을 이용하면 다음을 포함한 많은 공통된 VR 개발을 단순화 할 수 있습니다. ● 렌즈 왜곡 보정 ● 머리 추적 ● 3D 교정 ● 양쪽에 나란히 렌더링 ● 입체 형상 구성 ● 사용자 입력 이벤트 처리
  • 17. 간단한 Cardboard 앱 만들기. 만들기 어려운 건 함정 https://developers.google.com/cardboard/get-started
  • 20. 권장되는 Manifest.xml 설정 <manifest ... <uses-permission android:name="android.permission.NFC" /> <uses-permission android:name="android.permission.VIBRATE" /> ... <uses-sdk android:minSdkVersion="16"/> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <application ... <activity android:screenOrientation="landscape" ... </activity> </application> </manifest> 가로 모드 Open GL ES 사용 NFC 및 진동 권한 Android 4.1 +
  • 21. CardboardActivity 상속받기 public class CardboardActivityExample extends CardboardActivity { … }
  • 22. CardboardView.StereoRenderer 구현하기 public class CardboardActivityExample extends CardboardActivity implements CardboardView.StereoRenderer { … }
  • 24. private float[] mModelCube; private float[] mCamera; private float[] mView; private float[] mHeadView; private float[] mModelViewProjection; private float[] mModelView; private float[] mModelFloor; private Vibrator mVibrator; … * * * Sets the view to our CardboardView and initializes the transformation matrices we will use * to render our scene. * @param savedInstanceState */ … @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.common_ui); CardboardView cardboardView = (CardboardView) findViewById(R.id. common_paperscope_view); // Associate a CardboardView.StereoRenderer with cardboardView. cardboardView.setRenderer(this); // Associate the cardboardView with this activity. setCardboardView(cardboardView); mModelCube = new float[16]; mCamera = new float[16]; mView = new float[16]; mModelViewProjection = new float[16]; mModelView = new float[16]; mModelFloor = new float[16]; mHeadView = new float[16]; mVibrator = (Vibrator) getSystemService (Context.VIBRATOR_SERVICE); … }
  • 25. 뷰 렌더링 하기 CardboardView.StereoRenderer 를 통해 구현한, onNewFrame(), onDrawEye() 사용.
  • 26. onNewFrame() 구현하기 private int mGlProgram = GLES20.glCreateProgram(); private int mPositionParam; private int mNormalParam; private int mColorParam; private int mModelViewProjectionParam; private int mLightPosParam; private int mModelViewParam; private int mModelParam; private int mIsFloorParam; private float[] mHeadView; ... /** * Prepares OpenGL ES before we draw a frame. * @param headTransform The head transformation in the new frame. */ … … @Override public void onNewFrame(HeadTransform headTransform) { GLES20.glUseProgram(mGlProgram); mModelViewProjectionParam = GLES20. glGetUniformLocation(mGlProgram, "u_MVP"); mLightPosParam = GLES20.glGetUniformLocation (mGlProgram, "u_LightPos"); mModelViewParam = GLES20.glGetUniformLocation (mGlProgram, "u_MVMatrix"); mModelParam = GLES20.glGetUniformLocation (mGlProgram, "u_Model"); mIsFloorParam = GLES20.glGetUniformLocation (mGlProgram, "u_IsFloor"); // Build the Model part of the ModelView matrix. Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5 f, 1.0f); // Build the camera matrix and apply it to the ModelView. Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); headTransform.getHeadView(mHeadView, 0); checkGLError("onReadyToDraw"); }
  • 27. onDrawEye() 구현하기 private int mPositionParam; private int mNormalParam; private int mColorParam; // We keep the light always position just above the user. private final float[] mLightPosInEyeSpace = new float[] {0.0f, 2.0f, 0.0f, 1.0f}; ... /** * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as * a parameter. * @param transform The transformations to apply to render this eye. */ … @Override public void onDrawEye(EyeTransform transform) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20. GL_DEPTH_BUFFER_BIT); mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position"); mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal"); mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color"); GLES20.glEnableVertexAttribArray(mPositionParam); GLES20.glEnableVertexAttribArray(mNormalParam); GLES20.glEnableVertexAttribArray(mColorParam); checkGLError("mColorParam"); // Apply the eye transformation to the camera. Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0); // Set the position of the light Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0); GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]); // Build the ModelView and ModelViewProjection matrices // for calculating cube position and light. Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0); Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0); drawCube(); // Set mModelView for the floor, so we draw floor in the correct location Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0); Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0); ... }
  • 28. 자석 버튼 누름 감지하기 MagnetSensor.OnCardboardTriggerListener 사용
  • 29. private Vibrator mVibrator; private CardboardOverlayView mOverlayView; ... /** * Increment the score, hide the object, and give feedback if the user pulls the magnet while * looking at the object. Otherwise, remind the user what to do. */ @Override public void onCardboardTrigger() { if (isLookingAtObject()) { mScore++; mOverlayView.show3DToast("Found it! Look around for another one.nScore = " + mScore); ... } else { mOverlayView.show3DToast("Look around to find the object!"); } // Always give user feedback mVibrator.vibrate(50); } /** * Check if user is looking at object by calculating where the object is in eye- space. * @return */ private boolean isLookingAtObject() { float[] initVec = {0, 0, 0, 1.0f}; float[] objPositionVec = new float[4]; // Convert object space to camera space. Use the headView from onNewFrame. Matrix.multiplyMM(mModelView, 0, mHeadView, 0, mModelCube, 0); Matrix.multiplyMV(objPositionVec, 0, mModelView, 0, initVec, 0); float pitch = (float)Math.atan2 (objPositionVec[1], -objPositionVec[2]); float yaw = (float)Math.atan2 (objPositionVec[0], -objPositionVec[2]); ... return (Math.abs(pitch) < PITCH_LIMIT) && (Math.abs(yaw) < YAW_LIMIT); }
  • 30. Cardboard 앱 시연 (예제 앱) Treasure Hunt Cardboard Demo 앱
  • 31. 참고자료 ● https://developers.google.com/cardboard/get-started ● g.co/cardboard ● http://www.khronos.org/opengles/sdk/docs/man/