Commit 1dfdb958 authored by Ruben Jesus Garcia Hernandez's avatar Ruben Jesus Garcia Hernandez
parents b85520c7 2bae0c34
#include "aux.h"
float getCofactor(float m0, float m1, float m2,
float m3, float m4, float m5,
float m6, float m7, float m8)
{
return m0 * (m4 * m8 - m5 * m7) -
m1 * (m3 * m8 - m5 * m6) +
m2 * (m3 * m7 - m4 * m6);
}
//adapted from
//openvr-0.9.19\samples\shared\matrices.cpp
static gvr::Mat4f invert (const gvr::Mat4f& m)
{
gvr::Mat4f r;
// get cofactors of minor matrices
float cofactor0 = getCofactor(m.m[1][1],m.m[1][2],m.m[1][3], m.m[2][1],m.m[2][2],m.m[2][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor1 = getCofactor(m.m[1][0],m.m[1][2],m.m[1][3], m.m[2][0],m.m[2][2],m.m[2][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor2 = getCofactor(m.m[1][0],m.m[1][1],m.m[1][3], m.m[2][0],m.m[2][1], m.m[2][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor3 = getCofactor(m.m[1][0],m.m[1][1],m.m[1][2], m.m[2][0],m.m[2][1], m.m[2][2], m.m[3][0],m.m[3][1],m.m[3][2]);
// get determinant
float determinant = m.m[0][0] * cofactor0 - m.m[0][1] * cofactor1 + m.m[0][2] * cofactor2 - m.m[0][3] * cofactor3;
if(fabs(determinant) <= EPSILON)
{
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
r.m[i][j]=i==j;
return r;
}
// get rest of cofactors for adj(M)
float cofactor4 = getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[2][1],m.m[2][2],m.m[2][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor5 = getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[2][0],m.m[2][2],m.m[2][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor6 = getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[2][0],m.m[2][1], m.m[2][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor7 = getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[2][0],m.m[2][1], m.m[2][2], m.m[3][0],m.m[3][1],m.m[3][2]);
float cofactor8 = getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[1][1],m.m[1][2], m.m[1][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor9 = getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[1][0],m.m[1][2], m.m[1][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor10= getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[1][0],m.m[1][1], m.m[1][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor11= getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[1][0],m.m[1][1], m.m[1][2], m.m[3][0],m.m[3][1],m.m[3][2]);
float cofactor12= getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[1][1],m.m[1][2], m.m[1][3], m.m[2][1], m.m[2][2],m.m[2][3]);
float cofactor13= getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[1][0],m.m[1][2], m.m[1][3], m.m[2][0], m.m[2][2],m.m[2][3]);
float cofactor14= getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[1][0],m.m[1][1], m.m[1][3], m.m[2][0], m.m[2][1], m.m[2][3]);
float cofactor15= getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[1][0],m.m[1][1], m.m[1][2], m.m[2][0], m.m[2][1], m.m[2][2]);
// build inverse matrix = adj(M) / det(M)
// adjugate of M is the transpose of the cofactor matrix of M
float invDeterminant = 1.0f / determinant;
r.m[0][0] = invDeterminant * cofactor0;
r.m[0][1] = -invDeterminant * cofactor4;
r.m[0][2] = invDeterminant * cofactor8;
r.m[0][3] = -invDeterminant * cofactor12;
r.m[1][0] = -invDeterminant * cofactor1;
r.m[1][1] = invDeterminant * cofactor5;
r.m[1][2] = -invDeterminant * cofactor9;
r.m[1][3] = invDeterminant * cofactor13;
r.m[2][0] = invDeterminant * cofactor2;
r.m[2][1] = -invDeterminant * cofactor6;
r.m[2][2]= invDeterminant * cofactor10;
r.m[2][3]= -invDeterminant * cofactor14;
r.m[3][0]= -invDeterminant * cofactor3;
r.m[3][1]= invDeterminant * cofactor7;
r.m[3][2]= -invDeterminant * cofactor11;
r.m[3][3]= invDeterminant * cofactor15;
return r;
}
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);
......@@ -39,6 +39,8 @@
#include "NOMADVRLib/polyhedron.h"
#include "NOMADVRLib/IsosurfacesGL.h"
#include "GoogleCardboard/aux.h"
#define LOG_TAG "NOMADgvrT"
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
......@@ -50,7 +52,6 @@
}
const char * configPath=0;
const float EPSILON = 0.00001f;
void eprintf( const char *fmt, ... )
{
......@@ -71,41 +72,6 @@ void eprintf( const char *fmt, ... )
namespace {
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);
}
//static const float kZNear = 1.0f;
//static const float kZFar = 100.0f;
......@@ -117,78 +83,6 @@ static const int kCoordsPerVertex = 3;
static const uint64_t kPredictionTimeWithoutVsyncNanos = 50000000;
float getCofactor(float m0, float m1, float m2,
float m3, float m4, float m5,
float m6, float m7, float m8)
{
return m0 * (m4 * m8 - m5 * m7) -
m1 * (m3 * m8 - m5 * m6) +
m2 * (m3 * m7 - m4 * m6);
}
//adapted from
//openvr-0.9.19\samples\shared\matrices.cpp
static gvr::Mat4f invert (const gvr::Mat4f& m)
{
gvr::Mat4f r;
// get cofactors of minor matrices
float cofactor0 = getCofactor(m.m[1][1],m.m[1][2],m.m[1][3], m.m[2][1],m.m[2][2],m.m[2][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor1 = getCofactor(m.m[1][0],m.m[1][2],m.m[1][3], m.m[2][0],m.m[2][2],m.m[2][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor2 = getCofactor(m.m[1][0],m.m[1][1],m.m[1][3], m.m[2][0],m.m[2][1], m.m[2][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor3 = getCofactor(m.m[1][0],m.m[1][1],m.m[1][2], m.m[2][0],m.m[2][1], m.m[2][2], m.m[3][0],m.m[3][1],m.m[3][2]);
// get determinant
float determinant = m.m[0][0] * cofactor0 - m.m[0][1] * cofactor1 + m.m[0][2] * cofactor2 - m.m[0][3] * cofactor3;
if(fabs(determinant) <= EPSILON)
{
for (int i=0;i<4;i++)
for (int j=0;j<4;j++)
r.m[i][j]=i==j;
return r;
}
// get rest of cofactors for adj(M)
float cofactor4 = getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[2][1],m.m[2][2],m.m[2][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor5 = getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[2][0],m.m[2][2],m.m[2][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor6 = getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[2][0],m.m[2][1], m.m[2][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor7 = getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[2][0],m.m[2][1], m.m[2][2], m.m[3][0],m.m[3][1],m.m[3][2]);
float cofactor8 = getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[1][1],m.m[1][2], m.m[1][3], m.m[3][1],m.m[3][2],m.m[3][3]);
float cofactor9 = getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[1][0],m.m[1][2], m.m[1][3], m.m[3][0],m.m[3][2],m.m[3][3]);
float cofactor10= getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[1][0],m.m[1][1], m.m[1][3], m.m[3][0],m.m[3][1],m.m[3][3]);
float cofactor11= getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[1][0],m.m[1][1], m.m[1][2], m.m[3][0],m.m[3][1],m.m[3][2]);
float cofactor12= getCofactor(m.m[0][1],m.m[0][2],m.m[0][3], m.m[1][1],m.m[1][2], m.m[1][3], m.m[2][1], m.m[2][2],m.m[2][3]);
float cofactor13= getCofactor(m.m[0][0],m.m[0][2],m.m[0][3], m.m[1][0],m.m[1][2], m.m[1][3], m.m[2][0], m.m[2][2],m.m[2][3]);
float cofactor14= getCofactor(m.m[0][0],m.m[0][1],m.m[0][3], m.m[1][0],m.m[1][1], m.m[1][3], m.m[2][0], m.m[2][1], m.m[2][3]);
float cofactor15= getCofactor(m.m[0][0],m.m[0][1],m.m[0][2], m.m[1][0],m.m[1][1], m.m[1][2], m.m[2][0], m.m[2][1], m.m[2][2]);
// build inverse matrix = adj(M) / det(M)
// adjugate of M is the transpose of the cofactor matrix of M
float invDeterminant = 1.0f / determinant;
r.m[0][0] = invDeterminant * cofactor0;
r.m[0][1] = -invDeterminant * cofactor4;
r.m[0][2] = invDeterminant * cofactor8;
r.m[0][3] = -invDeterminant * cofactor12;
r.m[1][0] = -invDeterminant * cofactor1;
r.m[1][1] = invDeterminant * cofactor5;
r.m[1][2] = -invDeterminant * cofactor9;
r.m[1][3] = invDeterminant * cofactor13;
r.m[2][0] = invDeterminant * cofactor2;
r.m[2][1] = -invDeterminant * cofactor6;
r.m[2][2]= invDeterminant * cofactor10;
r.m[2][3]= -invDeterminant * cofactor14;
r.m[3][0]= -invDeterminant * cofactor3;
r.m[3][1]= invDeterminant * cofactor7;
r.m[3][2]= -invDeterminant * cofactor11;
r.m[3][3]= invDeterminant * cofactor15;
return r;
}
static std::array<float, 16> MatrixToGLArray(const gvr::Mat4f& matrix) {
// Note that this performs a *tranpose* to a column-major matrix array, as
// expected by GL.
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIFileSharingEnabled</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>magnetometer</string>
</array>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.1</string>
<key>CFBundleVersion</key>
<string>2.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>launch</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Used to scan QR codes</string>
</dict>
</plist>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "12BEE99D1C8F53AB002F8361"
BuildableName = "NOMADVRSDK.app"
BlueprintName = "NOMADVRSDK"
ReferencedContainer = "container:NOMADVRSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "12BEE99D1C8F53AB002F8361"
BuildableName = "NOMADVRSDK.app"
BlueprintName = "NOMADVRSDK"
ReferencedContainer = "container:NOMADVRSDK.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "12BEE99D1C8F53AB002F8361"
BuildableName = "NOMADVRSDK.app"
BlueprintName = "NOMADVRSDK"
ReferencedContainer = "container:NOMADVRSDK.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "12BEE99D1C8F53AB002F8361"
BuildableName = "NOMADVRSDK.app"
BlueprintName = "NOMADVRSDK"
ReferencedContainer = "container:NOMADVRSDK.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>TreasureHuntNDK.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>12BEE99D1C8F53AB002F8361</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:NOMADVRSDK.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
target 'NOMADVRSDK' do
pod 'GVRSDK'
pod 'GVRAudioSDK'
source 'https://github.com/CocoaPods/Specs.git'
pod 'FileBrowser', '~> 1.0'
use_frameworks!
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
end
PODS:
- FileBrowser (1.0.0)
- GoogleToolboxForMac/Defines (2.1.0)
- GoogleToolboxForMac/Logger (2.1.0):
- GoogleToolboxForMac/Defines (= 2.1.0)
- GTMSessionFetcher/Core (1.1.6)
- GVRAudioSDK (1.120.0)
- GVRSDK (1.120.0):
- GoogleToolboxForMac/Logger (= 2.1.0)
- GTMSessionFetcher/Core (= 1.1.6)
DEPENDENCIES:
- FileBrowser (~> 1.0)
- GVRAudioSDK
- GVRSDK
SPEC CHECKSUMS:
FileBrowser: 2ca91ff61c9ea09665eb3b8f9e64a7a77e66a0bf
GoogleToolboxForMac: 2b2596cbb7186865e98cadf2b1e262d851c2b168
GTMSessionFetcher: 6aacd0ab48ddf0c3633ab2642d792abfcad1b08a
GVRAudioSDK: 302f0a8f190d855868ea07f246ce4f9b44c392ae
GVRSDK: 0cb9d0ce06a84d698e61e3db9509766022dcf815
PODFILE CHECKSUM: 99ba6b514157c57c4187c4110345b7c329fef13f
COCOAPODS: 1.4.0
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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.
*/
#import <UIKit/UIKit.h>
@interface TreasureHuntAppDelegate : NSObject
@property(nonatomic, strong) UIWindow* window;
@end
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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.
*/
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support. Compile with -fobjc-arc"
#endif
#import "TreasureHuntAppDelegate.h"
#import "TreasureHuntViewController.h"
@interface TreasureHuntAppDelegate ()<UINavigationControllerDelegate>
@end
@implementation TreasureHuntAppDelegate
#pragma mark - UIApplicationDelegate overrides
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:[[TreasureHuntViewController alloc] init]];
navigationController.delegate = self;
navigationController.navigationBarHidden = YES;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - UINavigationControllerDelegate
// Make the navigation controller defer the check of supported orientation to its topmost view
// controller. This allows |GVRCardboardViewController| to lock the orientation in VR mode.
- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:
(UINavigationController *)navigationController {
return [navigationController.topViewController supportedInterfaceOrientations];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:/Users/lrz/gvr-ios-sdk/Samples/TreasureHuntNDK/NOMADVRSDK.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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.
*/
#import <GLKit/GLKit.h>
@interface TreasureHuntViewController : GLKViewController
@end
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* 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.
*/
#import "TreasureHuntViewController.h"
#import "GVROverlayView.h"
#import "treasure_hunt_renderer.h"
@interface TreasureHuntViewController ()<GLKViewControllerDelegate, GVROverlayViewDelegate> {
gvr_context *_gvrContext;
std::unique_ptr<TreasureHuntRenderer> _renderer;
}
@end
@implementation TreasureHuntViewController
- (void)dealloc {
gvr_destroy(&_gvrContext);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
// Create an overlay view on top of the GLKView.
GVROverlayView *overlayView = [[GVROverlayView alloc] initWithFrame:self.view.bounds];
overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
overlayView.delegate = self;
[self.view addSubview:overlayView];
// Add a tap gesture to handle viewer trigger action.
UITapGestureRecognizer *tapGesture =
[[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];
// Set animation frame rate.
self.preferredFramesPerSecond = 60;
// Set the GL context to initialize GVR.
[EAGLContext setCurrentContext:glkView.context];
// Make sure the glkView has bound its offscreen buffers before calling into gvr.
[glkView bindDrawable];
// Create GVR context.
_gvrContext = gvr_create();
// Initialize TreasureHuntRenderer.
_renderer.reset(new TreasureHuntRenderer(_gvrContext));
_renderer->InitializeGl();
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
// GVR only supports landscape right orientation for inserting the phone in the viewer.
return UIInterfaceOrientationMaskLandscapeRight;
}
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
_renderer->DrawFrame();
}
#pragma mark - GLKViewControllerDelegate
- (void)glkViewControllerUpdate:(GLKViewController *)controller {
// Perform GL state update before drawing.
}
- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause {
if (pause) {