Add filebrowser to select ncfg in IOS

parent 2bae0c34
Thumbs.db
\ No newline at end of file
Thumbs.db
.DS_Store
/*
# 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.
*/
#include <math.h>
#include "aux.h"
gvr::Mat4f TranslationMatrix (float x, float y, float z)
{
gvr::Mat4f mvs;
mvs.m[0][0]=1;mvs.m[0][1]=0;mvs.m[0][2]=0; mvs.m[0][3]=x;
mvs.m[1][0]=0;mvs.m[1][1]=1;mvs.m[1][2]=0;mvs.m[1][3]=y;
mvs.m[2][0]=0;mvs.m[2][1]=0;mvs.m[2][2]=1; mvs.m[2][3]=z;
mvs.m[3][0]=0;mvs.m[3][1]=0;mvs.m[3][2]=0; mvs.m[3][3]=1;
return mvs;
}
gvr::Mat4f TranslationMatrix (float v[3])
{
return TranslationMatrix (v[0], v[1], v[2]);
}
gvr::Mat4f ScalingMatrix (float x, float y, float z)
{
gvr::Mat4f mvs;
mvs.m[0][0]=x;mvs.m[0][1]=0;mvs.m[0][2]=0; mvs.m[0][3]=0;
mvs.m[1][0]=0;mvs.m[1][1]=y;mvs.m[1][2]=0;mvs.m[1][3]=0;
mvs.m[2][0]=0;mvs.m[2][1]=0;mvs.m[2][2]=z; mvs.m[2][3]=0;
mvs.m[3][0]=0;mvs.m[3][1]=0;mvs.m[3][2]=0; mvs.m[3][3]=1;
return mvs;
}
gvr::Mat4f ScalingMatrix (float v[3])
{
return ScalingMatrix(v[0], v[1], v[2]);
}
gvr::Mat4f ScalingMatrix (float s)
{
return ScalingMatrix(s,s,s);
}
float getCofactor(float m0, float m1, float m2,
float m3, float m4, float m5,
float m6, float m7, float m8)
......@@ -13,7 +65,7 @@ float getCofactor(float m0, float m1, float m2,
//adapted from
//openvr-0.9.19\samples\shared\matrices.cpp
static gvr::Mat4f invert (const gvr::Mat4f& m)
gvr::Mat4f invert (const gvr::Mat4f& m)
{
gvr::Mat4f r;
// get cofactors of minor matrices
......
/*
# 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.
*/
#include "vr/gvr/capi/include/gvr.h"
const float EPSILON = 0.00001f;
gvr::Mat4f TranslationMatrix (float x, float y, float z);
gvr::Mat4f TranslationMatrix (float v[3]);
gvr::Mat4f ScalingMatrix (float x, float y, float z);
gvr::Mat4f ScalingMatrix (float v[3]);
gvr::Mat4f ScalingMatrix (float s);
float getCofactor(float m0, float m1, float m2,
float m3, float m4, float m5,
float m6, float m7, float m8);
static gvr::Mat4f invert (const gvr::Mat4f& m);
gvr::Mat4f invert (const gvr::Mat4f& m);
/*# Copyright 2016-2018 The NOMAD Developers Group*/
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
......@@ -19,18 +20,28 @@
#import "GVROverlayView.h"
#import "treasure_hunt_renderer.h"
#include "FileBrowser/FileBrowser.h"
#include "FileBrowser-Swift.h"
@interface TreasureHuntViewController ()<GLKViewControllerDelegate, GVROverlayViewDelegate> {
gvr_context *_gvrContext;
std::unique_ptr<TreasureHuntRenderer> _renderer;
}
@end
NSString * filename;
@implementation TreasureHuntViewController
- (void)dealloc {
gvr_destroy(&_gvrContext);
}
- (UIViewController *)presentingViewControllerForSettingsDialog {
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
......@@ -47,6 +58,7 @@
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapGLView:)];
[self.view addGestureRecognizer:tapGesture];
// Create an OpenGL ES context and assign it to the view loaded from storyboard
GLKView *glkView = (GLKView *)self.view;
glkView.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
......@@ -62,11 +74,26 @@
// Create GVR context.
_gvrContext = gvr_create();
// Initialize TreasureHuntRenderer.
_renderer.reset(new TreasureHuntRenderer(_gvrContext));
_renderer->InitializeGl();
}
FileBrowser *fb=[[FileBrowser alloc] initWithInitialPath: nullptr allowEditing:NO showCancelButton:NO];
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();
};
fb.didSelectFile=didSelectFileCallback;
//[self.navigationController pushViewController:fb animated:YES];
[self presentViewController:fb animated:YES completion:nil];
_renderer.reset(new TreasureHuntRenderer(_gvrContext));
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
// GVR only supports landscape right orientation for inserting the phone in the viewer.
......@@ -104,9 +131,6 @@
NSLog(@"User pressed back button");
}
- (UIViewController *)presentingViewControllerForSettingsDialog {
return self;
}
- (void)didPresentSettingsDialog:(BOOL)presented {
// The overlay view is presenting the settings dialog. Pause our rendering while presented.
......
......@@ -45,6 +45,10 @@ class TreasureHuntRenderer {
*/
~TreasureHuntRenderer();
void setConfigFile (NSString * filename);
/**
* Initialize any GL-related objects. This should be called on the rendering
* thread with a valid GL context.
......@@ -106,7 +110,7 @@ class TreasureHuntRenderer {
gvr::BufferViewport scratch_viewport_;
gvr::Mat4f head_view_;
gvr::Mat4f model_cube_;
//gvr::Mat4f model_cube_;
gvr::Mat4f camera_;
gvr::Mat4f view_;
gvr::Mat4f modelview_projection_cube_;
......@@ -148,8 +152,10 @@ class TreasureHuntRenderer {
void RenderAtomTrajectories(const gvr::Mat4f eyeViewProjection);
void RenderIsos(const gvr::Mat4f eyeViewProjection, int curDataPos);
float UserTranslation[3]={10,0,0};
NSString * configfilename=nullptr;
int error=0;
bool openGLIsInitialized=false;
};
#endif // TREASUREHUNT_APP_SRC_MAIN_JNI_TREASUREHUNTRENDERER_H_ // NOLINT
......@@ -164,22 +164,20 @@ static void CheckGLError(const char* label) {
} // namespace
void TreasureHuntRenderer::setConfigFile (NSString * filename)
{
configfilename=filename;
loadConfigFile();
}
void TreasureHuntRenderer::loadConfigFile(void)
{
//http://www.techotopia.com/index.php/Working_with_Directories_on_iPhone_OS#The_Application_Documents_Directory
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSFileManager *filemgr = [NSFileManager defaultManager];
if (configfilename==nullptr)
return;
if ([filemgr changeCurrentDirectoryPath: docsDir] == NO)
NSLog(@"Cannot change current directory");
if ((error=::loadConfigFile("cytosine.ncfg"))<0) {
if ((error=::loadConfigFile(configfilename.UTF8String))<0) {
if (-100<error) {
eprintf(loadConfigFileErrors[-error]);
eprintf("Config file reading error");
......@@ -211,13 +209,14 @@ TreasureHuntRenderer::TreasureHuntRenderer(
: gvr_api_(gvr::GvrApi::WrapNonOwned(gvr_context)),
scratch_viewport_(gvr_api_->CreateBufferViewport())
{
loadConfigFile();
//won't have config file until later
// loadConfigFile();
}
TreasureHuntRenderer::~TreasureHuntRenderer() {}
void TreasureHuntRenderer::InitializeGl() {
gvr_api_->InitializeGl();
gvr_api_->InitializeGl();
glGenTextures(2, textures);
glGenTextures(2+ZLAYERS, textDepthPeeling);
......@@ -288,9 +287,13 @@ void TreasureHuntRenderer::InitializeGl() {
viewport_list_.reset(new gvr::BufferViewportList(gvr_api_->CreateEmptyBufferViewportList()));
openGLIsInitialized=true;
}
void TreasureHuntRenderer::DrawFrame() {
if (!openGLIsInitialized)
return;
viewport_list_->SetToRecommendedBufferViewports();
if (animateTimesteps) {
......@@ -520,6 +523,8 @@ void TreasureHuntRenderer::RenderAtoms(const float *m) //m[16]
LOGW("FIXME, No Tess code for atoms yet!");
return;
} else { //no tess
if (AtomVAO==nullptr) //not yet loaded
return;
glBindVertexArray(AtomVAO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, AtomIndices[0]);
if ((e = glGetError()) != GL_NO_ERROR)
......
......@@ -56,17 +56,23 @@ GLenum atomTexture(GLuint t)
a[(i+atomsInPeriodicTable)*4+3]=extraAtomData[i][3]*atomScaling;
}
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_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
#ifdef __APPLE__
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a);
#else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, finalatoms, 1, 0, GL_RGBA, GL_FLOAT, a);
#endif
if ((e = glGetError()) != GL_NO_ERROR) {
eprintf( "opengl error %d, atomTexture parameter\n", e);
}
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 );
if ((e = glGetError()) != GL_NO_ERROR) {
eprintf( "opengl error %d, atomTexture\n", e);
}
......
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