Add default citosyne model to GearVR (requested by Oculus Store)

Add support for markers
parent 6d4d53ba
...@@ -6,7 +6,9 @@ include ../../../../../cflags.mk ...@@ -6,7 +6,9 @@ include ../../../../../cflags.mk
LOCAL_MODULE := ovrapp LOCAL_MODULE := ovrapp
LOCAL_SRC_FILES := ../../../Src/OvrApp.cpp ../../../Src/rply/rply.c \ LOCAL_SRC_FILES := ../../../Src/OvrApp.cpp ../../../Src/rply/rply.c \
../../../Src/NOMADVRLib/ConfigFile.cpp ../../../Src/NOMADVRLib/atoms.cpp \ ../../../Src/NOMADVRLib/ConfigFile.cpp \
../../../Src/NOMADVRLib/ConfigFileAtoms.cpp \
../../../Src/NOMADVRLib/atoms.cpp \
../../../Src/happyhttp/happyhttp.cpp \ ../../../Src/happyhttp/happyhttp.cpp \
../../../Src/NOMADVRLib/atomsGL.cpp \ ../../../Src/NOMADVRLib/atomsGL.cpp \
../../../Src/NOMADVRLib/CompileGLShader.cpp \ ../../../Src/NOMADVRLib/CompileGLShader.cpp \
......
/*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 oculus; package oculus;
//This file is the same, except for the package above, as //This file is the same, except for the package above, as
//NOMADgvrT\src\main\java\com\google\vr\ndk\samples\treasurehunt\Filepath.java //NOMADgvrT\src\main\java\com\google\vr\ndk\samples\treasurehunt\Filepath.java
......
...@@ -15,6 +15,7 @@ import android.os.Bundle; ...@@ -15,6 +15,7 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.content.Intent; import android.content.Intent;
import com.oculus.vrappframework.VrActivity; import com.oculus.vrappframework.VrActivity;
import com.lrz.NOMADGearvrT.R;
public class MainActivity extends VrActivity { public class MainActivity extends VrActivity {
public static final String TAG = "NOMADGearvrT"; public static final String TAG = "NOMADGearvrT";
...@@ -82,9 +83,53 @@ public static void verifyStoragePermissions(android.app.Activity activity) { ...@@ -82,9 +83,53 @@ public static void verifyStoragePermissions(android.app.Activity activity) {
} }
} }
*/ */
private void SaveToDisk (java.io.InputStream is, java.lang.String name)
{ //https://stackoverflow.com/questions/10854211/android-store-inputstream-in-file
try {
try {
java.io.File f=new java.io.File(name);
java.io.OutputStream output = new java.io.FileOutputStream(f);
try {
byte[] buffer = new byte[4 * 1024]; // or other buffer size
int read;
while ((read = is.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
} finally {
output.close();
}
} finally {
is.close();
}
} catch (java.io.IOException e) {
android.util.Log.d("NOMADgvrT","java.io.IOException, e="+e);
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
//export example file
java.io.File d= new java.io.File ("/sdcard/Oculus/NomadGearVR");
try{
if (!d.exists()) {
d.mkdir();
}
}
catch(java.lang.SecurityException e){
android.util.Log.d("NOMADgvrT","java.lang.SecurityException, e="+e);
}
java.io.InputStream is=this.getApplicationContext().getResources().
openRawResource (com.lrz.NOMADGearvrT.R.raw.xyz);
SaveToDisk(is, "/sdcard/Oculus/NomadGearVR/cytosine.xyz");
is=this.getApplicationContext().getResources().openRawResource (com.lrz.NOMADGearvrT.R.raw.ncfg);
SaveToDisk(is, "/sdcard/Oculus/NomadGearVR/cytosine.ncfg");
//end export
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
verifyStoragePermissions(this); verifyStoragePermissions(this);
...@@ -98,9 +143,10 @@ public static void verifyStoragePermissions(android.app.Activity activity) { ...@@ -98,9 +143,10 @@ public static void verifyStoragePermissions(android.app.Activity activity) {
uriString=Filepath.getFilePath (this.getApplicationContext(), u); uriString=Filepath.getFilePath (this.getApplicationContext(), u);
} catch (java.net.URISyntaxException e) { } catch (java.net.URISyntaxException e) {
android.util.Log.d("NOMADgvrT","URISyntaxException, e="+e); android.util.Log.d("NOMADgvrT","URISyntaxException, e="+e);
uriString=null; uriString="/sdcard/Oculus/NomadGearVR/cytosine.ncfg";
} }
android.util.Log.d("NOMADgvrT","Uristring is="+uriString);
setAppPtr( nativeSetAppInterface( this, fromPackageNameString, commandString, uriString ) ); setAppPtr( nativeSetAppInterface( this, fromPackageNameString, commandString, uriString ) );
} }
} }
...@@ -115,12 +115,12 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO ...@@ -115,12 +115,12 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO
//} //}
const char *configLocation="/sdcard/NOMAD/NOMADGearVR.cfg"; const char *configLocation="/sdcard/NOMAD/NOMADGearVR.cfg";
const char *defaultURI="/sdcard/Oculus/NOMAD/ViveTDefault.ncfg"; const char *defaultURI="/sdcard/Oculus/NomadGearVR/cytosine.ncfg";
char finalURI[1024]; char finalURI[1024];
FILE *cl = fopen (configLocation, "r"); FILE *cl = fopen (configLocation, "r");
if (cl==nullptr) { if (cl==nullptr) {
LOG("NOMADGearVRT, /sdcard/NOMAD/NOMADGearVR.cfg not found, using default at /sdcard/Oculus/NOMAD/ViveTDefault.ncfg"); LOG("NOMADGearVRT, /sdcard/NOMAD/NOMADGearVR.cfg not found, using default at /sdcard/Oculus/NomadGearVR/cytosine.ncfg");
strcpy(finalURI, defaultURI); strcpy(finalURI, defaultURI);
} else { } else {
fgets(finalURI, 1024, cl); fgets(finalURI, 1024, cl);
...@@ -175,14 +175,14 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO ...@@ -175,14 +175,14 @@ void OvrApp::OneTimeInit( const char * fromPackage, const char * launchIntentJSO
LOG("NOMADGearVRT No atom glyph specified, using Icosahedron"); LOG("NOMADGearVRT No atom glyph specified, using Icosahedron");
solid=new Solid(Solid::Type::Icosahedron); solid=new Solid(Solid::Type::Icosahedron);
} }
LOG("OneTimeInit, 2"); // LOG("OneTimeInit, 2");
const ovrJava * java = app->GetJava(); const ovrJava * java = app->GetJava();
SoundEffectContext = new ovrSoundEffectContext( *java->Env, java->ActivityObject ); SoundEffectContext = new ovrSoundEffectContext( *java->Env, java->ActivityObject );
SoundEffectContext->Initialize(); SoundEffectContext->Initialize();
SoundEffectPlayer = new OvrGuiSys::ovrDummySoundEffectPlayer(); SoundEffectPlayer = new OvrGuiSys::ovrDummySoundEffectPlayer();
LOG("OneTimeInit, 3"); //LOG("OneTimeInit, 3");
Locale = ovrLocale::Create( *app, "default" ); Locale = ovrLocale::Create( *app, "default" );
LOG("OneTimeInit, 4"); //LOG("OneTimeInit, 4");
String fontName; String fontName;
GetLocale().GetString( "@string/font_name", "efigs.fnt", fontName ); GetLocale().GetString( "@string/font_name", "efigs.fnt", fontName );
GuiSys->Init( this->app, *SoundEffectPlayer, fontName.ToCStr(), &app->GetDebugLines() ); GuiSys->Init( this->app, *SoundEffectPlayer, fontName.ToCStr(), &app->GetDebugLines() );
...@@ -232,9 +232,16 @@ LOG("OneTimeInit, 4"); ...@@ -232,9 +232,16 @@ LOG("OneTimeInit, 4");
if (e!=GL_NO_ERROR) if (e!=GL_NO_ERROR)
eprintf ("SetupUnitCell error %d", e); eprintf ("SetupUnitCell error %d", e);
if (ISOS) { e=SetupMarkerNoTess(&MarkerVAO, &MarkerVertBuffer, &MarkerIndexBuffer);
PrepareISOShader(&ISOP, &ISOMatrixLoc); if (e!=GL_NO_ERROR) {
eprintf ("SetupMarkerNoTess error %d", e);
}
if (ISOS || markers) {
PrepareISOShader(&ISOP, &ISOMatrixLoc);
}
if (ISOS) {
float m=BACKGROUND[0]; float m=BACKGROUND[0];
m=std::max(m, BACKGROUND[1]); m=std::max(m, BACKGROUND[1]);
m=std::max(m, BACKGROUND[2]); m=std::max(m, BACKGROUND[2]);
...@@ -469,11 +476,44 @@ void OvrApp::RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso) { ...@@ -469,11 +476,44 @@ void OvrApp::RenderIsos(const OVR::Matrix4f eyeViewProjection, int iso) {
glBindVertexArray(0); glBindVertexArray(0);
} }
void OvrApp::RenderMarker(const float *m) //m[16]
{
int e;
if (!markers)
return;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindVertexArray(MarkerVAO);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("b %d", e);
glUseProgram(ISOP);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("c %d", e);
glUniformMatrix4fv(ISOMatrixLoc, 1, GL_FALSE, m);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("d %d, matrixloc=%d, program=%d", e, ISOMatrixLoc, ISOP);
glDrawElements(GL_TRIANGLES, 3*3*MARKERSOLID::nFaces,
#ifndef INDICESGL32
GL_UNSIGNED_SHORT, (void*)(currentSet*sizeof(unsigned short)*3*3*MARKERSOLID::nFaces
)
#else
GL_UNSIGNED_INT, (void*)(currentSet*sizeof(unsigned int)*3*3*MARKERSOLID::nFaces
)
#endif
);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("e %d", e);
glBindVertexArray(0);
if ((e = glGetError()) != GL_NO_ERROR)
eprintf("f %d", e);
glDisable(GL_BLEND);
}
void OvrApp::RenderAtoms(const float *m) //m[16] void OvrApp::RenderAtoms(const float *m) //m[16]
{ {
eprintf ("RenderAtoms start numatoms %d", numAtoms); //eprintf ("RenderAtoms start numatoms %d", numAtoms);
int e; int e;
if (numAtoms==0) if (numAtoms==0)
return; return;
...@@ -607,6 +647,7 @@ void OvrApp::RenderUnitCell(const Matrix4f eyeViewProjection) ...@@ -607,6 +647,7 @@ void OvrApp::RenderUnitCell(const Matrix4f eyeViewProjection)
//atom trajectories //atom trajectories
RenderAtomTrajectoriesUnitCell(); RenderAtomTrajectoriesUnitCell();
RenderAtoms(t); RenderAtoms(t);
RenderMarker(t);
} }
} }
...@@ -628,6 +669,7 @@ void OvrApp::RenderAtomTrajectories (const Matrix4f eyeViewProjection) ...@@ -628,6 +669,7 @@ void OvrApp::RenderAtomTrajectories (const Matrix4f eyeViewProjection)
glUniformMatrix4fv(UnitCellMatrixLoc, 1, GL_FALSE, t); glUniformMatrix4fv(UnitCellMatrixLoc, 1, GL_FALSE, t);
RenderAtomTrajectoriesUnitCell(); RenderAtomTrajectoriesUnitCell();
RenderAtoms(t); RenderAtoms(t);
RenderMarker(t);
} }
Matrix4f OvrApp::DrawEyeView( const int eye, const float fovDegreesX, const float fovDegreesY, ovrFrameParms & frameParms ) Matrix4f OvrApp::DrawEyeView( const int eye, const float fovDegreesX, const float fovDegreesY, ovrFrameParms & frameParms )
......
...@@ -56,7 +56,8 @@ private: ...@@ -56,7 +56,8 @@ private:
//if no tesselation is available, we still need the tess atoms for the trajectories! //if no tesselation is available, we still need the tess atoms for the trajectories!
GLuint *AtomTVAO=nullptr, *AtomTBuffer=nullptr, BondIndices=0, *AtomVAO=nullptr, *AtomBuffer=nullptr, GLuint *AtomTVAO=nullptr, *AtomTBuffer=nullptr, BondIndices=0, *AtomVAO=nullptr, *AtomBuffer=nullptr,
*AtomIndices=nullptr,//[2], atoms, extraatoms *AtomIndices=nullptr,//[2], atoms, extraatoms
UnitCellVAO, UnitCellBuffer, UnitCellIndexBuffer; UnitCellVAO, UnitCellBuffer, UnitCellIndexBuffer,
MarkerVAO, MarkerVertBuffer, MarkerIndexBuffer;
GLuint *ISOVAO=nullptr/*[ISOS*TIMESTEPS]*/, *ISOBuffer=nullptr/*[ISOS*TIMESTEPS]*/, GLuint *ISOVAO=nullptr/*[ISOS*TIMESTEPS]*/, *ISOBuffer=nullptr/*[ISOS*TIMESTEPS]*/,
*ISOIndices=nullptr/*[ISOS*TIMESTEPS]*/; *ISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
...@@ -65,6 +66,7 @@ private: ...@@ -65,6 +66,7 @@ private:
int *numISOIndices=nullptr/*[ISOS*TIMESTEPS]*/; int *numISOIndices=nullptr/*[ISOS*TIMESTEPS]*/;
void RenderAtoms(const float *m); void RenderAtoms(const float *m);
void RenderMarker(const float *m);
void RenderUnitCell(const OVR::Matrix4f eyeViewProjection); void RenderUnitCell(const OVR::Matrix4f eyeViewProjection);
void RenderAtomTrajectories (const OVR::Matrix4f eyeViewProjection); void RenderAtomTrajectories (const OVR::Matrix4f eyeViewProjection);
void RenderAtomTrajectoriesUnitCell(); void RenderAtomTrajectoriesUnitCell();
......
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