Commit d5d879d3 authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
Browse files
parents 1dfdb958 c1df5eb6
/*# Copyright 2016-2018 The NOMAD Developers Group*/
/* /*
* Copyright 2016 Google Inc. All Rights Reserved. * Copyright 2016 Google Inc. All Rights Reserved.
* *
...@@ -19,18 +20,45 @@ ...@@ -19,18 +20,45 @@
#import "GVROverlayView.h" #import "GVROverlayView.h"
#import "treasure_hunt_renderer.h" #import "treasure_hunt_renderer.h"
#include "FileBrowser/FileBrowser.h"
#include "FileBrowser-Swift.h"
@interface TreasureHuntViewController ()<GLKViewControllerDelegate, GVROverlayViewDelegate> { @interface TreasureHuntViewController ()<GLKViewControllerDelegate, GVROverlayViewDelegate> {
gvr_context *_gvrContext; gvr_context *_gvrContext;
std::unique_ptr<TreasureHuntRenderer> _renderer; std::unique_ptr<TreasureHuntRenderer> _renderer;
NSMutableArray *mycommands;
} }
@end @end
NSString * filename;
@implementation TreasureHuntViewController @implementation TreasureHuntViewController
//https://stackoverflow.com/questions/3717141/how-to-detect-keyboard-events-on-hardware-keyboard-on-iphone-ios
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (NSArray *)keyCommands
{
return mycommands;
}
- (void)dealloc { - (void)dealloc {
gvr_destroy(&_gvrContext); gvr_destroy(&_gvrContext);
} }
- (UIViewController *)presentingViewControllerForSettingsDialog {
return self;
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
...@@ -47,6 +75,7 @@ ...@@ -47,6 +75,7 @@
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapGLView:)]; [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapGLView:)];
[self.view addGestureRecognizer:tapGesture]; [self.view addGestureRecognizer:tapGesture];
// Create an OpenGL ES context and assign it to the view loaded from storyboard // Create an OpenGL ES context and assign it to the view loaded from storyboard
GLKView *glkView = (GLKView *)self.view; GLKView *glkView = (GLKView *)self.view;
glkView.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; glkView.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
...@@ -63,9 +92,67 @@ ...@@ -63,9 +92,67 @@
// Create GVR context. // Create GVR context.
_gvrContext = gvr_create(); _gvrContext = gvr_create();
// Initialize TreasureHuntRenderer. FileBrowser *fb=[[FileBrowser alloc] initWithInitialPath: nullptr allowEditing:NO showCancelButton:NO];
_renderer.reset(new TreasureHuntRenderer(_gvrContext));
void (^ _Nullable didSelectFileCallback)(FBFile * _Nonnull) = ^(FBFile * _Nonnull file)
{
filename=[[file filePath] path];
NSFileManager *filemgr = [NSFileManager defaultManager];
//http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS#The_Application_Documents_Directory
if ([filemgr changeCurrentDirectoryPath: [filename stringByDeletingLastPathComponent]] == NO)
NSLog(@"Cannot change current directory");
_renderer->setConfigFile (filename);
_renderer->InitializeGl(); _renderer->InitializeGl();
};
//https://gist.github.com/ferbass/0ddea86e6b2eb5915fabdbfe9f151a5e
fb.didSelectFile=didSelectFileCallback;
//[self.navigationController pushViewController:fb animated:YES];
[self presentViewController:fb animated:YES completion:nil];
_renderer.reset(new TreasureHuntRenderer(_gvrContext));
//keys
NSMutableArray *commands = [[NSMutableArray alloc] init];
/* Up */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Down */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Left */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
/* Right */
[commands addObject:[UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:kNilOptions action:@selector(handleCommand:)]];
//VRPark, ABCD=uhyj, arrows: up down left right = wxad
UIKeyModifierFlags f[]={
//UIKeyModifierAlphaShift,
//UIKeyModifierShift,
//UIKeyModifierControl,
//UIKeyModifierAlternate,
//UIKeyModifierCommand,
//UIKeyModifierControl | UIKeyModifierAlternate,
//UIKeyModifierControl | UIKeyModifierCommand,
//UIKeyModifierAlternate | UIKeyModifierCommand,
//UIKeyModifierControl | UIKeyModifierAlternate | UIKeyModifierCommand,
kNilOptions
};
NSString *characters = @"uhyjwxad";
for (NSInteger i = 0; i < characters.length; i++) {
for (int j=0;j<1;j++) {
NSString *input = [characters substringWithRange:NSMakeRange(i, 1)];
[commands addObject:[UIKeyCommand keyCommandWithInput:input modifierFlags:f[j] action:@selector(handleCommand:)]];
}
}
mycommands = commands.copy;
// [self.addKeyCommand:mycommands];
}
- (void)handleCommand:(UIKeyCommand *)command
{
_renderer->keypress (command.input.UTF8String[0]);
} }
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
...@@ -104,9 +191,6 @@ ...@@ -104,9 +191,6 @@
NSLog(@"User pressed back button"); NSLog(@"User pressed back button");
} }
- (UIViewController *)presentingViewControllerForSettingsDialog {
return self;
}
- (void)didPresentSettingsDialog:(BOOL)presented { - (void)didPresentSettingsDialog:(BOOL)presented {
// The overlay view is presenting the settings dialog. Pause our rendering while presented. // The overlay view is presenting the settings dialog. Pause our rendering while presented.
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
#import <OpenGLES/ES3/gl.h> #import <OpenGLES/ES3/gl.h>
#import <OpenGLES/ES3/glext.h> #import <OpenGLES/ES3/glext.h>
//https://www.raywenderlich.com/66532/ios-7-game-controller-tutorial
#include "GameController/GameController.h"
#include <memory> #include <memory>
#include <string> #include <string>
#include <thread> // NOLINT #include <thread> // NOLINT
...@@ -45,6 +48,10 @@ class TreasureHuntRenderer { ...@@ -45,6 +48,10 @@ class TreasureHuntRenderer {
*/ */
~TreasureHuntRenderer(); ~TreasureHuntRenderer();
void setConfigFile (NSString * filename);
/** /**
* Initialize any GL-related objects. This should be called on the rendering * Initialize any GL-related objects. This should be called on the rendering
* thread with a valid GL context. * thread with a valid GL context.
...@@ -71,7 +78,11 @@ class TreasureHuntRenderer { ...@@ -71,7 +78,11 @@ class TreasureHuntRenderer {
*/ */
void OnResume(); void OnResume();
void keypress (int k);
private: private:
NSArray<GCController *> *controllers=nullptr;
int CreateTexture(int width, int height, int textureFormat, int textureType); int CreateTexture(int width, int height, int textureFormat, int textureType);
/** /**
...@@ -106,7 +117,7 @@ class TreasureHuntRenderer { ...@@ -106,7 +117,7 @@ class TreasureHuntRenderer {
gvr::BufferViewport scratch_viewport_; gvr::BufferViewport scratch_viewport_;
gvr::Mat4f head_view_; gvr::Mat4f head_view_;
gvr::Mat4f model_cube_; //gvr::Mat4f model_cube_;
gvr::Mat4f camera_; gvr::Mat4f camera_;
gvr::Mat4f view_; gvr::Mat4f view_;
gvr::Mat4f modelview_projection_cube_; gvr::Mat4f modelview_projection_cube_;
...@@ -148,8 +159,10 @@ class TreasureHuntRenderer { ...@@ -148,8 +159,10 @@ class TreasureHuntRenderer {
void RenderAtomTrajectories(const gvr::Mat4f eyeViewProjection); void RenderAtomTrajectories(const gvr::Mat4f eyeViewProjection);
void RenderIsos(const gvr::Mat4f eyeViewProjection, int curDataPos); void RenderIsos(const gvr::Mat4f eyeViewProjection, int curDataPos);
float UserTranslation[3]={10,0,0}; float UserTranslation[3]={10,0,0};
NSString * configfilename=nullptr;
int error=0; int error=0;
bool openGLIsInitialized=false;
}; };
#endif // TREASUREHUNT_APP_SRC_MAIN_JNI_TREASUREHUNTRENDERER_H_ // NOLINT #endif // TREASUREHUNT_APP_SRC_MAIN_JNI_TREASUREHUNTRENDERER_H_ // NOLINT
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "AudioToolbox/AudioToolbox.h"
#include "treasure_hunt_renderer.h" #include "treasure_hunt_renderer.h"
#include <assert.h> #include <assert.h>
...@@ -164,22 +165,55 @@ static void CheckGLError(const char* label) { ...@@ -164,22 +165,55 @@ static void CheckGLError(const char* label) {
} // namespace } // namespace
void TreasureHuntRenderer::loadConfigFile(void) void TreasureHuntRenderer::setConfigFile (NSString * filename)
{ {
//http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS#The_Application_Documents_Directory configfilename=filename;
NSArray *dirPaths; loadConfigFile();
NSString *docsDir; }
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, void TreasureHuntRenderer::keypress (int k)
NSUserDomainMask, YES); {
switch (k) { //A B C D -> Y A X B
//case 'u':
docsDir = [dirPaths objectAtIndex:0]; case 'h':
NSFileManager *filemgr = [NSFileManager defaultManager]; animateMovement=!animateMovement;
break;
case 'y':
animateTimesteps=!animateTimesteps;
break;
//case 'j':
//up down left right
case 'w':
currentSet++;
if (currentSet>TIMESTEPS-1)
currentSet=0;
break;
case 'x':
currentSet--;
if (currentSet<0)
currentSet=TIMESTEPS-1;
break;
case 'a':
currentIso++;
if (currentIso>ISOS)
currentIso=0;
break;
case 'd':
currentIso--;
if (currentIso<0)
currentIso=ISOS;
break;
}
}
if ([filemgr changeCurrentDirectoryPath: docsDir] == NO) void TreasureHuntRenderer::loadConfigFile(void)
NSLog(@"Cannot change current directory"); {
if (configfilename==nullptr)
return;
if ((error=::loadConfigFile("cytosine.ncfg"))<0) {
if ((error=::loadConfigFile(configfilename.UTF8String))<0) {
if (-100<error) { if (-100<error) {
eprintf(loadConfigFileErrors[-error]); eprintf(loadConfigFileErrors[-error]);
eprintf("Config file reading error"); eprintf("Config file reading error");
...@@ -211,7 +245,10 @@ TreasureHuntRenderer::TreasureHuntRenderer( ...@@ -211,7 +245,10 @@ TreasureHuntRenderer::TreasureHuntRenderer(
: gvr_api_(gvr::GvrApi::WrapNonOwned(gvr_context)), : gvr_api_(gvr::GvrApi::WrapNonOwned(gvr_context)),
scratch_viewport_(gvr_api_->CreateBufferViewport()) scratch_viewport_(gvr_api_->CreateBufferViewport())
{ {
loadConfigFile();
controllers=[GCController controllers];
//won't have config file until later
// loadConfigFile();
} }
TreasureHuntRenderer::~TreasureHuntRenderer() {} TreasureHuntRenderer::~TreasureHuntRenderer() {}
...@@ -288,9 +325,13 @@ void TreasureHuntRenderer::InitializeGl() { ...@@ -288,9 +325,13 @@ void TreasureHuntRenderer::InitializeGl() {
viewport_list_.reset(new gvr::BufferViewportList(gvr_api_->CreateEmptyBufferViewportList())); viewport_list_.reset(new gvr::BufferViewportList(gvr_api_->CreateEmptyBufferViewportList()));
openGLIsInitialized=true;
} }
void TreasureHuntRenderer::DrawFrame() { void TreasureHuntRenderer::DrawFrame() {
if (!openGLIsInitialized)
return;
viewport_list_->SetToRecommendedBufferViewports(); viewport_list_->SetToRecommendedBufferViewports();
if (animateTimesteps) { if (animateTimesteps) {
...@@ -332,8 +373,8 @@ void TreasureHuntRenderer::DrawFrame() { ...@@ -332,8 +373,8 @@ void TreasureHuntRenderer::DrawFrame() {
} }
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glCullFace(GL_FRONT); //glCullFace(GL_FRONT);
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND); glDisable(GL_BLEND);
...@@ -375,6 +416,7 @@ void TreasureHuntRenderer::DrawFrame() { ...@@ -375,6 +416,7 @@ void TreasureHuntRenderer::DrawFrame() {
void TreasureHuntRenderer::OnTriggerEvent() { void TreasureHuntRenderer::OnTriggerEvent() {
animateMovement=!animateMovement; animateMovement=!animateMovement;
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
} }
void TreasureHuntRenderer::OnPause() { void TreasureHuntRenderer::OnPause() {
...@@ -520,6 +562,8 @@ void TreasureHuntRenderer::RenderAtoms(const float *m) //m[16] ...@@ -520,6 +562,8 @@ void TreasureHuntRenderer::RenderAtoms(const float *m) //m[16]
LOGW("FIXME, No Tess code for atoms yet!"); LOGW("FIXME, No Tess code for atoms yet!");
return; return;
} else { //no tess } else { //no tess
if (AtomVAO==nullptr) //not yet loaded
return;
glBindVertexArray(AtomVAO[0]); glBindVertexArray(AtomVAO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, AtomIndices[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, AtomIndices[0]);
if ((e = glGetError()) != GL_NO_ERROR) if ((e = glGetError()) != GL_NO_ERROR)
...@@ -774,6 +818,7 @@ void TreasureHuntRenderer::DrawEye(gvr::Eye eye, const gvr::Mat4f& view_matrix, ...@@ -774,6 +818,7 @@ void TreasureHuntRenderer::DrawEye(gvr::Eye eye, const gvr::Mat4f& view_matrix,
pixel_rect.right - pixel_rect.left, pixel_rect.right - pixel_rect.left,
pixel_rect.top - pixel_rect.bottom); pixel_rect.top - pixel_rect.bottom);
CheckGLError("Before glClear");
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CheckGLError("ColorParam"); CheckGLError("ColorParam");
......
This directory contains the demo for Google Cardboard using Google Cardboard SDK
for IOS.
Follow https://developers.google.com/vr/develop/ios/get-started to install
the SDK.
Copy NOMADVRIOS in gvr-ios-sdk/Samples
Enter gvr-ios-sdk/Samples/NOMADVRIOS and run
pod update
If you get this error
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down
follow this:
https://stackoverflow.com/questions/38993527/cocoapods-failed-to-connect-to-github-to-update-the-cocoapods-specs-specs-repo
Open Xcode and select NOMADVR.xcworkspace
Setup Developer Account / Profiles / Code signing
Compile and run
...@@ -56,17 +56,23 @@ GLenum atomTexture(GLuint t) ...@@ -56,17 +56,23 @@ GLenum atomTexture(GLuint t)
a[(i+atomsInPeriodicTable)*4+3]=extraAtomData[i][3]*atomScaling; a[(i+atomsInPeriodicTable)*4+3]=extraAtomData[i][3]*atomScaling;
} }
glBindTexture(GL_TEXTURE_2D, t); //atom texture glBindTexture(GL_TEXTURE_2D, t); //atom texture
if ((e = glGetError()) != GL_NO_ERROR) {
eprintf( "opengl error %d, atomTexture bind\n", e);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#ifdef __APPLE__ if ((e = glGetError()) != GL_NO_ERROR) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a); eprintf( "opengl error %d, atomTexture parameter\n", e);
#else }
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a);
if ((e = glGetError()) != GL_NO_ERROR) {
eprintf( "opengl error %d, atomTexture glTexImage2D\n", e);
}
glBindTexture( GL_TEXTURE_2D, 0 ); glBindTexture( GL_TEXTURE_2D, 0 );
if ((e = glGetError()) != GL_NO_ERROR) { if ((e = glGetError()) != GL_NO_ERROR) {
eprintf( "opengl error %d, atomTexture\n", e); eprintf( "opengl error %d, atomTexture\n", e);
} }
......
...@@ -9,7 +9,8 @@ Context: ...@@ -9,7 +9,8 @@ Context:
Requirements: Requirements:
-Supported virtual reality hardware: HTC Vive or Oculus Rift, GearVR, -Supported virtual reality hardware: HTC Vive or Oculus Rift, GearVR,
Google Cardboard for Android, or the LRZ CAVE environment. Google Cardboard for Android or IOS, or the LRZ CAVE
environment.
Usage Instructions: Usage Instructions:
See https://www.nomad-coe.eu/the-project/graphics/VR-prototype See https://www.nomad-coe.eu/the-project/graphics/VR-prototype
...@@ -18,6 +19,9 @@ Subdirectories: ...@@ -18,6 +19,9 @@ Subdirectories:
OpenVR: Demos for HTC Vive. OpenVR: Demos for HTC Vive.
OculusMobile: Demos for GearVR. OculusMobile: Demos for GearVR.
GoogleCardboardAndroid: Demos for Google Cardboard (android) GoogleCardboardAndroid: Demos for Google Cardboard (android)
GoogleCardboardIOS: Demo for Google Cardboard (IOS)
GoogleCardboard: Common files between Google Cardboard for Android
and for IOS
CAVE: Demos for LRZ CAVE-like environment (linux) CAVE: Demos for LRZ CAVE-like environment (linux)
NOMADGearVRChooser: Android app to select the dataset for GearVR, which NOMADGearVRChooser: Android app to select the dataset for GearVR, which
......
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