Add gitignore

Add license to Google Cardboard
Add scaling to google cardboard.
parent e7524e46
Thumbs.db
\ No newline at end of file
...@@ -6,12 +6,13 @@ model { ...@@ -6,12 +6,13 @@ model {
buildToolsVersion = "25.0.2" buildToolsVersion = "25.0.2"
defaultConfig.with { defaultConfig.with {
applicationId = "com.google.vr.ndk.samples.treasurehunt" applicationId = "com.lrz.nomadvr"
minSdkVersion.apiLevel = 19 minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 23 targetSdkVersion.apiLevel = 23
versionCode = 1 versionCode = 8
versionName = "1.0" versionName = "1.2"
} }
} }
android.buildTypes { android.buildTypes {
release { release {
......
/*Uses code from Stackoverflow which uses the MIT license and the CC BY-SA 3.0*/
/*These licenses are compatible with Apache 2.0*/
/*
# Copyright 2016-2018 The NOMAD Developers Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
*/
package com.google.vr.ndk.samples.treasurehunt; package com.google.vr.ndk.samples.treasurehunt;
//https://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore/7265235#7265235 //https://stackoverflow.com/questions/3401579/get-filename-and-path-from-uri-from-mediastore/7265235#7265235
......
/*Uses code from Stackoverflow which uses the MIT license and the CC BY-SA 3.0*/
/*These licenses are compatible with Apache 2.0*/
/*
# Copyright 2016-2018 The NOMAD Developers Group
*/
/* Copyright 2017 Google Inc. All rights reserved. /* Copyright 2017 Google Inc. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -50,6 +57,18 @@ public class MainActivity extends Activity { ...@@ -50,6 +57,18 @@ public class MainActivity extends Activity {
System.loadLibrary("treasurehunt_jni"); System.loadLibrary("treasurehunt_jni");
} }
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
android.util.Log.d("NOMADgvrT","onKeyUp, keycode="+keyCode);
nativekeyPress(nativeTreasureHuntRenderer, keyCode);
return true;
//Matthias Scheffler Bluetooth Controller, in GAME MODE @->B
//KeyEvent.BUTTON_X, KeyEvent.BUTTON_Y, KeyEvent.BUTTON_A, KeyEvent.BUTTON_B
}
//http://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android //http://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-android
// Storage Permissions // Storage Permissions
private static final int REQUEST_EXTERNAL_STORAGE = 1; private static final int REQUEST_EXTERNAL_STORAGE = 1;
...@@ -112,12 +131,6 @@ public static void verifyStoragePermissions(Activity activity) { ...@@ -112,12 +131,6 @@ public static void verifyStoragePermissions(Activity activity) {
verifyStoragePermissions(this); verifyStoragePermissions(this);
//http://stackoverflow.com/questions/36557879/how-to-use-native-android-file-open-dialog //http://stackoverflow.com/questions/36557879/how-to-use-native-android-file-open-dialog
/////////
//setContentView(R.layout.activity_main);
///////////
String externalsd=android.os.Environment.getExternalStorageDirectory().getPath() + "/"; String externalsd=android.os.Environment.getExternalStorageDirectory().getPath() + "/";
...@@ -337,24 +350,5 @@ public static void verifyStoragePermissions(Activity activity) { ...@@ -337,24 +350,5 @@ public static void verifyStoragePermissions(Activity activity) {
private native void nativeSetConfigFile(String s, String e); private native void nativeSetConfigFile(String s, String e);
private native void nativeLoadConfigFile(long nativeTreasureHuntRenderer); private native void nativeLoadConfigFile(long nativeTreasureHuntRenderer);
public void DisplayMessage (final String s) private native void nativekeyPress(long nativeTreasureHuntRenderer, int k);
{
//http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare
//rgh: this hangs, need to investigate
new Thread()
{
public void run()
{
MainActivity.this.runOnUiThread(new Runnable()
{
public void run()
{
android.widget.Toast toast = android.widget.Toast.makeText(MainActivity.this.getApplicationContext(), s,
android.widget.Toast.LENGTH_LONG);
}
});
}
}.start();
}
} }
/*Uses code from Stackoverflow which uses the MIT license and the CC BY-SA 3.0*/
/*These licenses are compatible with Apache 2.0*/
/*
# Copyright 2016-2018 The NOMAD Developers Group
*/
/* Copyright 2017 Google Inc. All rights reserved. /* Copyright 2017 Google Inc. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -18,12 +25,11 @@ ...@@ -18,12 +25,11 @@
#include <memory> #include <memory>
#include "treasure_hunt_renderer.h" // NOLINT
#include "vr/gvr/capi/include/gvr.h" #include "vr/gvr/capi/include/gvr.h"
#include "vr/gvr/capi/include/gvr_audio.h" #include "vr/gvr/capi/include/gvr_audio.h"
#include "NOMADVRLib/atoms.hpp" //for TMPDIR #include "NOMADVRLib/atoms.hpp" //for TMPDIR
#include "treasure_hunt_jni.h" #include "treasure_hunt_renderer.h"
#define JNI_METHOD(return_type, method_name) \ #define JNI_METHOD(return_type, method_name) \
JNIEXPORT return_type JNICALL \ JNIEXPORT return_type JNICALL \
...@@ -56,16 +62,6 @@ inline TreasureHuntRenderer *native(jlong ptr) { ...@@ -56,16 +62,6 @@ inline TreasureHuntRenderer *native(jlong ptr) {
genv->CallStaticVoidMethod(jc, mid, jurl, jpath); genv->CallStaticVoidMethod(jc, mid, jurl, jpath);
}*/ }*/
void DisplayMessage (const char *s)
{
JNIEnv *env;
javaVM->AttachCurrentThread(&env, nullptr);
jstring js = env->NewStringUTF(s);
jclass cls = env->GetObjectClass(jo);
jmethodID mid = env->GetMethodID(cls, "DisplayMessage", "(Ljava/lang/String;)V");
env->CallVoidMethod(jo, mid, js);
}
extern "C" { extern "C" {
JNI_METHOD(jlong, nativeCreateRenderer) JNI_METHOD(jlong, nativeCreateRenderer)
......
//void GetUrl (const char *url, const char *path);
void DisplayMessage (const char *s);
/*Uses code from Stackoverflow which uses the MIT license and the CC BY-SA 3.0*/
/*These licenses are compatible with Apache 2.0*/
/*
# Copyright 2016-2018 The NOMAD Developers Group
*/
/* Copyright 2017 Google Inc. All rights reserved. /* Copyright 2017 Google Inc. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -16,7 +22,6 @@ ...@@ -16,7 +22,6 @@
#include <unistd.h> #include <unistd.h>
#include "treasure_hunt_renderer.h" // NOLINT #include "treasure_hunt_renderer.h" // NOLINT
#include "treasure_hunt_jni.h"
#include <android/log.h> #include <android/log.h>
#include <assert.h> #include <assert.h>
...@@ -60,8 +65,6 @@ void eprintf( const char *fmt, ... ) ...@@ -60,8 +65,6 @@ void eprintf( const char *fmt, ... )
if (*fmt=='\0') if (*fmt=='\0')
LOGD("Empty format"); LOGD("Empty format");
LOGD("<%s>", buffer); LOGD("<%s>", buffer);
//rgh: does not work yet
//DisplayMessage(buffer);
} }
...@@ -99,6 +102,11 @@ gvr::Mat4f ScalingMatrix (float v[3]) ...@@ -99,6 +102,11 @@ gvr::Mat4f ScalingMatrix (float v[3])
return ScalingMatrix(v[0], v[1], v[2]); return ScalingMatrix(v[0], v[1], v[2]);
} }
gvr::Mat4f ScalingMatrix (float s)
{
return ScalingMatrix(s,s,s);
}
//static const float kZNear = 1.0f; //static const float kZNear = 1.0f;
//static const float kZFar = 100.0f; //static const float kZFar = 100.0f;
static const float kZNear = 0.01f; static const float kZNear = 0.01f;
...@@ -587,7 +595,7 @@ glGenTextures(2+ZLAYERS, textDepthPeeling); ...@@ -587,7 +595,7 @@ glGenTextures(2+ZLAYERS, textDepthPeeling);
plyfiles[p % ISOS]); plyfiles[p % ISOS]);
gvr::Mat4f trans; gvr::Mat4f trans;
gvr::Mat4f matFinal, matcubetrans, mvs, sc, sctrans; gvr::Mat4f matFinal, matcubetrans, mvs, sc, sctrans;
//rotateX(-90)
if (voxelSize[0]!=-1) { if (voxelSize[0]!=-1) {
mvs=ScalingMatrix(scaling/(float)voxelSize[0], scaling/(float)voxelSize[1], mvs=ScalingMatrix(scaling/(float)voxelSize[0], scaling/(float)voxelSize[1],
scaling/(float)voxelSize[2]); scaling/(float)voxelSize[2]);
...@@ -603,19 +611,12 @@ glGenTextures(2+ZLAYERS, textDepthPeeling); ...@@ -603,19 +611,12 @@ glGenTextures(2+ZLAYERS, textDepthPeeling);
matFinal=MatrixMul(matFinal,sc); matFinal=MatrixMul(matFinal,sc);
matFinal=MatrixMul(matFinal,mvs); matFinal=MatrixMul(matFinal,mvs);
} else { } else {
/*trans.m[0][0]=1;trans.m[0][1]=0;trans.m[0][2]=0; trans.m[0][3]=0;
trans.m[1][0]=0;trans.m[1][1]=0;trans.m[1][2]=1;trans.m[1][3]=0;
trans.m[2][0]=0;trans.m[2][1]=-1;trans.m[2][2]=0; trans.m[2][3]=0;
trans.m[3][0]=0;trans.m[3][1]=0;trans.m[3][2]=0; trans.m[3][3]=1;*/
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
for(int j=0;j<4;j++) for(int j=0;j<4;j++)
matFinal.m[i][j]=(i==j); matFinal.m[i][j]=(i==j);
for (int i=0;i<3;i++) for (int i=0;i<3;i++)
matFinal.m[i][3]=translations[p%ISOS][i]; matFinal.m[i][3]=translations[p%ISOS][i];
//matFinal=MatrixMul(trans, matFinal);
trans.m[0][0]=scaling;trans.m[0][1]=0;trans.m[0][2]=0; trans.m[0][3]=0; trans.m[0][0]=scaling;trans.m[0][1]=0;trans.m[0][2]=0; trans.m[0][3]=0;
trans.m[1][0]=0;trans.m[1][1]=scaling;trans.m[1][2]=0;trans.m[1][3]=0; trans.m[1][0]=0;trans.m[1][1]=scaling;trans.m[1][2]=0;trans.m[1][3]=0;
trans.m[2][0]=0;trans.m[2][1]=0;trans.m[2][2]=scaling; trans.m[2][3]=0; trans.m[2][0]=0;trans.m[2][1]=0;trans.m[2][2]=scaling; trans.m[2][3]=0;
...@@ -1055,10 +1056,11 @@ void TreasureHuntRenderer::RenderAtomTrajectories(const gvr::Mat4f eyeViewProjec ...@@ -1055,10 +1056,11 @@ void TreasureHuntRenderer::RenderAtomTrajectories(const gvr::Mat4f eyeViewProjec
int e; int e;
if (!numAtoms) if (!numAtoms)
return; return;
gvr::Mat4f trans=TranslationMatrix (UserTranslation[0], UserTranslation[1], UserTranslation[2]); gvr::Mat4f sc=ScalingMatrix(scaling);
gvr::Mat4f trans=TranslationMatrix (UserTranslation[0]/scaling, UserTranslation[1]/scaling, UserTranslation[2]/scaling);
const gvr::Mat4f rot={.m={1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1}}; const gvr::Mat4f rot={.m={1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1}};
//trans.translate(iPos).rotateX(-90).translate(UserPosition); //trans.translate(iPos).rotateX(-90).translate(UserPosition);
gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(trans,rot)); gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(sc, MatrixMul(trans,rot)));
//gvr::Mat4f transform=eyeViewProjection; //gvr::Mat4f transform=eyeViewProjection;
float t[16]; float t[16];
for (int i=0;i<4;i++) for (int i=0;i<4;i++)
...@@ -1095,6 +1097,8 @@ if ((e = glGetError()) != GL_NO_ERROR) ...@@ -1095,6 +1097,8 @@ if ((e = glGetError()) != GL_NO_ERROR)
//glDisableVertexAttribArray(1); //glDisableVertexAttribArray(1);
//LOG("atomtrajectories.size()=%d", atomtrajectories.size()); //LOG("atomtrajectories.size()=%d", atomtrajectories.size());
//rgh FIXME, old code which does not work with large atom sets!
glBindBuffer(GL_ARRAY_BUFFER, AtomTBuffer[0]); glBindBuffer(GL_ARRAY_BUFFER, AtomTBuffer[0]);
if ((e = glGetError()) != GL_NO_ERROR) if ((e = glGetError()) != GL_NO_ERROR)
eprintf("3 Gl error RenderAtomTrajectoriesUnitCell: %d\n", e); eprintf("3 Gl error RenderAtomTrajectoriesUnitCell: %d\n", e);
...@@ -1135,6 +1139,7 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection) ...@@ -1135,6 +1139,7 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection)
int e; int e;
int p[3]; int p[3];
gvr::Mat4f sc=ScalingMatrix(scaling);
for (p[0]=0;p[0]<repetitions[0];(p[0])++) for (p[0]=0;p[0]<repetitions[0];(p[0])++)
for (p[1]=0;p[1]<repetitions[1];(p[1])++) for (p[1]=0;p[1]<repetitions[1];(p[1])++)
for (p[2]=0;p[2]<repetitions[2];(p[2])++) for (p[2]=0;p[2]<repetitions[2];(p[2])++)
...@@ -1145,10 +1150,11 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection) ...@@ -1145,10 +1150,11 @@ void TreasureHuntRenderer::RenderUnitCell(const gvr::Mat4f eyeViewProjection)
0,1,0,delta[1]+UserTranslation[1], 0,1,0,delta[1]+UserTranslation[1],
0,0,1,delta[2]+UserTranslation[2], 0,0,1,delta[2]+UserTranslation[2],
0,0,0,1};*/ 0,0,0,1};*/
gvr::Mat4f trans=TranslationMatrix (UserTranslation[0], UserTranslation[1], UserTranslation[2]); gvr::Mat4f trans=TranslationMatrix (delta[0]+UserTranslation[0]/scaling, delta[2]+UserTranslation[1]/scaling,
-delta[1]+UserTranslation[2]/scaling);
const gvr::Mat4f rot={.m={1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1}}; const gvr::Mat4f rot={.m={1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1}};
//trans.translate(iPos).rotateX(-90).translate(UserPosition); //trans.translate(iPos).rotateX(-90).translate(UserPosition);
gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(trans,rot)); gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(sc, MatrixMul(trans,rot)));
...@@ -1161,26 +1167,28 @@ gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(trans,rot)); ...@@ -1161,26 +1167,28 @@ gvr::Mat4f transform = MatrixMul(eyeViewProjection, MatrixMul(trans,rot));
glUseProgram(UnitCellP); glUseProgram(UnitCellP);
glUniformMatrix4fv(UnitCellMatrixLoc, 1, GL_FALSE, t); glUniformMatrix4fv(UnitCellMatrixLoc, 1, GL_FALSE, t);
if ((e = glGetError()) != GL_NO_ERROR) if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error after glUniform4fv 1 RenderUnitCell: %d\n", e); eprintf("Gl error after glUniform4fv 1 RenderUnitCell: %d\n", e);
glUniform4fv(UnitCellColourLoc, 1, unitcellcolour); if (displayunitcell) {
if ((e = glGetError()) != GL_NO_ERROR) glUniform4fv(UnitCellColourLoc, 1, unitcellcolour);
eprintf("Gl error after glUniform4fv 2 RenderUnitCell: %d\n", e); if ((e = glGetError()) != GL_NO_ERROR)
glBindVertexArray(UnitCellVAO); eprintf("Gl error after glUniform4fv 2 RenderUnitCell: %d\n", e);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, UnitCellIndexBuffer); glBindVertexArray(UnitCellVAO);
if ((e = glGetError()) != GL_NO_ERROR) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, UnitCellIndexBuffer);
eprintf("1 Gl error RenderAtom timestep =%d: %d\n", currentSet, e); if ((e = glGetError()) != GL_NO_ERROR)
glBindBuffer(GL_ARRAY_BUFFER, UnitCellBuffer); eprintf("1 Gl error RenderAtom timestep =%d: %d\n", currentSet, e);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (const void *)(0)); glBindBuffer(GL_ARRAY_BUFFER, UnitCellBuffer);
glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (const void *)(0));
glDisableVertexAttribArray(1); glEnableVertexAttribArray(0);
glDisableVertexAttribArray(2); glDisableVertexAttribArray(1);
glDisableVertexAttribArray(3); glDisableVertexAttribArray(2);
if ((e = glGetError()) != GL_NO_ERROR) glDisableVertexAttribArray(3);
eprintf("Gl error after glBindVertexArray RenderUnitCell: %d\n", e); if ((e = glGetError()) != GL_NO_ERROR)
glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0); eprintf("Gl error after glBindVertexArray RenderUnitCell: %d\n", e);
//glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, 0); glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0);
if ((e = glGetError()) != GL_NO_ERROR) //glDrawElements(GL_TRIANGLES, 24, GL_UNSIGNED_INT, 0);
eprintf("Gl error after RenderUnitCell: %d\n", e); if ((e = glGetError()) != GL_NO_ERROR)
eprintf("Gl error after RenderUnitCell: %d\n", e);
}
//atom trajectories //atom trajectories
RenderAtomTrajectoriesUnitCell(); RenderAtomTrajectoriesUnitCell();
RenderAtoms(t); RenderAtoms(t);
......
/* Copyright 2017 Google Inc. All rights reserved. /* Copyright 2017 Google Inc. All rights reserved.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment