2014-02-10 01:10:30 +00:00
/*************************************************************************/
2020-09-30 19:08:01 +00:00
/* godot_view.mm */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2014-02-10 01:10:30 +00:00
/*************************************************************************/
2020-01-01 10:16:22 +00:00
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 01:10:30 +00:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2018-01-04 23:50:27 +00:00
2020-09-30 19:08:01 +00:00
#import "godot_view.h"
2014-02-10 01:10:30 +00:00
2017-04-09 12:18:49 +00:00
#include "core/os/keyboard.h"
2017-07-30 20:53:40 +00:00
#include "core/project_settings.h"
2017-04-09 12:18:49 +00:00
#include "os_iphone.h"
2014-05-14 04:22:15 +00:00
#include "servers/audio_server.h"
2014-02-10 01:10:30 +00:00
2017-04-09 12:18:49 +00:00
#import <OpenGLES/EAGLDrawable.h>
#import <QuartzCore/QuartzCore.h>
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
#import "display_layer.h"
#import "godot_view_gesture_recognizer.h"
#import "godot_view_renderer.h"
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
#import <CoreMotion/CoreMotion.h>
2020-08-25 12:18:47 +00:00
2020-10-05 19:19:38 +00:00
static const int max_touches = 8;
2020-08-25 12:18:47 +00:00
2020-10-05 19:19:38 +00:00
@interface GodotView () {
UITouch *godot_touches[max_touches];
String keyboard_text;
2018-04-10 10:35:30 +00:00
}
2020-10-05 19:19:38 +00:00
@property(assign, nonatomic) BOOL isActive;
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
// CADisplayLink available on 3.1+ synchronizes the animation timer & drawing with the refresh rate of the display, only supports animation intervals of 1/60 1/30 & 1/15
@property(strong, nonatomic) CADisplayLink *displayLink;
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
// An animation timer that, when animation is started, will periodically call -drawView at the given rate.
// Only used if CADisplayLink is not
@property(strong, nonatomic) NSTimer *animationTimer;
2016-02-19 04:09:06 +00:00
2020-10-05 19:19:38 +00:00
@property(strong, nonatomic) CALayer<DisplayLayer> *renderingLayer;
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
@property(strong, nonatomic) CMMotionManager *motionManager;
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
@property(strong, nonatomic) GodotViewGestureRecognizer *delayGestureRecognizer;
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
@end
2014-12-02 17:02:41 +00:00
2020-10-05 19:19:38 +00:00
@implementation GodotView
2014-12-02 17:02:41 +00:00
2020-10-05 19:19:38 +00:00
// Implement this to override the default layer class (which is [CALayer class]).
// We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering.
- (CALayer<DisplayLayer> *)initializeRendering {
if (self.renderingLayer) {
return self.renderingLayer;
2014-11-17 10:46:11 +00:00
}
2020-10-05 19:19:38 +00:00
CALayer<DisplayLayer> *layer = [GodotOpenGLLayer layer];
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
layer.frame = self.bounds;
layer.contentsScale = self.contentScaleFactor;
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
[self.layer addSublayer:layer];
self.renderingLayer = layer;
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
[layer initializeDisplayLayer];
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
return self.renderingLayer;
2014-11-17 10:46:11 +00:00
}
2014-03-14 01:57:24 +00:00
2020-10-05 19:19:38 +00:00
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self godot_commonInit];
2016-02-19 04:09:06 +00:00
}
2014-03-14 01:57:24 +00:00
2020-10-05 19:19:38 +00:00
return self;
2014-03-14 01:57:24 +00:00
}
2020-10-05 19:19:38 +00:00
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
2014-03-14 01:57:24 +00:00
2020-10-05 19:19:38 +00:00
if (self) {
[self godot_commonInit];
2017-10-04 08:39:31 +00:00
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
return self;
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
// Stop animating and release resources when they are no longer needed.
- (void)dealloc {
[self stopRendering];
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
self.renderer = nil;
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
if (self.renderingLayer) {
[self.renderingLayer removeFromSuperlayer];
self.renderingLayer = nil;
2016-04-02 18:26:12 +00:00
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
if (self.motionManager) {
[self.motionManager stopDeviceMotionUpdates];
self.motionManager = nil;
2019-03-14 22:14:20 +00:00
}
2019-03-15 01:36:33 +00:00
2020-10-05 19:19:38 +00:00
if (self.displayLink) {
[self.displayLink invalidate];
self.displayLink = nil;
2019-03-14 22:14:20 +00:00
}
2019-03-15 01:36:33 +00:00
2020-10-05 19:19:38 +00:00
if (self.animationTimer) {
[self.animationTimer invalidate];
self.animationTimer = nil;
2014-02-10 01:10:30 +00:00
}
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
if (self.delayGestureRecognizer) {
self.delayGestureRecognizer = nil;
}
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (void)godot_commonInit {
self.contentScaleFactor = [UIScreen mainScreen].nativeScale;
2014-03-14 01:57:24 +00:00
2020-10-05 19:19:38 +00:00
[self initTouches];
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
// Configure and start accelerometer
if (!self.motionManager) {
self.motionManager = [[CMMotionManager alloc] init];
if (self.motionManager.deviceMotionAvailable) {
self.motionManager.deviceMotionUpdateInterval = 1.0 / 70.0;
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];
} else {
self.motionManager = nil;
}
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
// Initialize delay gesture recognizer
GodotViewGestureRecognizer *gestureRecognizer = [[GodotViewGestureRecognizer alloc] init];
self.delayGestureRecognizer = gestureRecognizer;
[self addGestureRecognizer:self.delayGestureRecognizer];
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (void)startRendering {
if (self.isActive) {
return;
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
self.isActive = YES;
2014-02-10 01:10:30 +00:00
printf("start animation!\n");
2020-10-05 19:19:38 +00:00
if (self.useCADisplayLink) {
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
2015-10-23 00:31:09 +00:00
// Approximate frame rate
// assumes device refreshes at 60 fps
2020-10-05 19:19:38 +00:00
int displayFPS = (NSInteger)(1.0 / self.renderingInterval);
2015-10-23 00:31:09 +00:00
2020-10-05 19:19:38 +00:00
self.displayLink.preferredFramesPerSecond = displayFPS;
2015-10-23 00:31:09 +00:00
// Setup DisplayLink in main thread
2020-10-05 19:19:38 +00:00
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
2017-04-09 11:22:40 +00:00
} else {
2020-10-05 19:19:38 +00:00
self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:self.renderingInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
2014-11-26 17:24:13 +00:00
}
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (void)stopRendering {
if (!self.isActive) {
2014-02-10 01:10:30 +00:00
return;
2015-10-23 00:31:09 +00:00
}
2020-10-05 19:19:38 +00:00
self.isActive = NO;
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
printf("******** stop animation!\n");
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
if (self.useCADisplayLink) {
[self.displayLink invalidate];
self.displayLink = nil;
} else {
[self.animationTimer invalidate];
self.animationTimer = nil;
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
[self clearTouches];
2014-02-10 01:10:30 +00:00
}
// Updates the OpenGL view when the timer fires
2017-04-09 11:22:40 +00:00
- (void)drawView {
2020-10-05 19:19:38 +00:00
if (!self.isActive) {
2019-10-29 07:58:59 +00:00
printf("draw view not active!\n");
return;
2020-10-05 19:19:38 +00:00
}
if (self.useCADisplayLink) {
2015-10-23 00:31:09 +00:00
// Pause the CADisplayLink to avoid recursion
2020-10-05 19:19:38 +00:00
[self.displayLink setPaused:YES];
2015-02-10 19:54:22 +00:00
2015-10-23 00:31:09 +00:00
// Process all input events
2019-10-29 07:58:59 +00:00
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, TRUE) == kCFRunLoopRunHandledSource)
2017-04-09 12:18:49 +00:00
;
2015-02-10 19:54:22 +00:00
2015-10-23 00:31:09 +00:00
// We are good to go, resume the CADisplayLink
2020-10-05 19:19:38 +00:00
[self.displayLink setPaused:NO];
2015-10-23 00:31:09 +00:00
}
2015-02-10 19:54:22 +00:00
2020-10-05 19:19:38 +00:00
[self.renderingLayer startRenderDisplayLayer];
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
if (!self.renderer) {
return;
2014-02-10 01:10:30 +00:00
}
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
if ([self.renderer setupView:self]) {
return;
}
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
[self handleMotion];
[self.renderer renderOnView:self];
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
[self.renderingLayer stopRenderDisplayLayer];
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (BOOL)canRender {
if (self.useCADisplayLink) {
return self.displayLink != nil;
} else {
return self.animationTimer != nil;
}
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (void)setRenderingInterval:(NSTimeInterval)renderingInterval {
_renderingInterval = renderingInterval;
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
if (self.canRender) {
[self stopRendering];
[self startRendering];
}
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
// If our view is resized, we'll be asked to layout subviews.
// This is the perfect opportunity to also update the framebuffer so that it is
// the same size as our display area.
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
- (void)layoutSubviews {
if (self.renderingLayer) {
self.renderingLayer.frame = self.bounds;
[self.renderingLayer layoutDisplayLayer];
}
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
[super layoutSubviews];
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
// MARK: - Input
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
// MARK: Keyboard
2014-02-10 01:10:30 +00:00
- (BOOL)canBecomeFirstResponder {
return YES;
2020-10-05 19:19:38 +00:00
}
2017-10-04 08:39:31 +00:00
2020-10-05 19:19:38 +00:00
- (BOOL)becomeFirstResponderWithString:(String)p_existing {
keyboard_text = p_existing;
return [self becomeFirstResponder];
2017-10-04 08:39:31 +00:00
}
2020-10-05 19:19:38 +00:00
- (BOOL)resignFirstResponder {
keyboard_text = String();
return [super resignFirstResponder];
2017-10-04 08:39:31 +00:00
}
2014-02-10 01:10:30 +00:00
- (void)deleteBackward {
2020-10-05 19:19:38 +00:00
if (keyboard_text.length()) {
2014-02-10 01:10:30 +00:00
keyboard_text.erase(keyboard_text.length() - 1, 1);
2020-10-05 19:19:38 +00:00
}
2014-02-10 01:10:30 +00:00
OSIPhone::get_singleton()->key(KEY_BACKSPACE, true);
2020-10-05 19:19:38 +00:00
}
2014-02-10 01:10:30 +00:00
- (BOOL)hasText {
2020-10-05 19:19:38 +00:00
return keyboard_text.length() > 0;
}
2014-02-10 01:10:30 +00:00
- (void)insertText:(NSString *)p_text {
String character;
character.parse_utf8([p_text UTF8String]);
keyboard_text = keyboard_text + character;
2017-04-09 12:18:49 +00:00
OSIPhone::get_singleton()->key(character[0] == 10 ? KEY_ENTER : character[0], true);
2020-10-05 19:19:38 +00:00
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
// MARK: Touches
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
- (void)initTouches {
for (int i = 0; i < max_touches; i++) {
godot_touches[i] = NULL;
}
}
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
- (int)getTouchIDForTouch:(UITouch *)p_touch {
int first = -1;
for (int i = 0; i < max_touches; i++) {
if (first == -1 && godot_touches[i] == NULL) {
first = i;
continue;
}
if (godot_touches[i] == p_touch) {
return i;
}
}
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
if (first != -1) {
godot_touches[first] = p_touch;
return first;
}
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
return -1;
}
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
- (int)removeTouch:(UITouch *)p_touch {
int remaining = 0;
for (int i = 0; i < max_touches; i++) {
if (godot_touches[i] == NULL) {
continue;
}
if (godot_touches[i] == p_touch) {
godot_touches[i] = NULL;
} else {
++remaining;
}
}
return remaining;
}
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
- (void)clearTouches {
for (int i = 0; i < max_touches; i++) {
godot_touches[i] = NULL;
2015-03-03 17:39:13 +00:00
}
}
2020-10-05 19:19:38 +00:00
- (void)touchesBegan:(NSSet *)touchesSet withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touchesSet containsObject:[tlist objectAtIndex:i]]) {
UITouch *touch = [tlist objectAtIndex:i];
int tid = [self getTouchIDForTouch:touch];
ERR_FAIL_COND(tid == -1);
CGPoint touchPoint = [touch locationInView:self];
OSIPhone::get_singleton()->touch_press(tid, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, true, touch.tapCount > 1);
}
}
}
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
UITouch *touch = [tlist objectAtIndex:i];
int tid = [self getTouchIDForTouch:touch];
ERR_FAIL_COND(tid == -1);
CGPoint touchPoint = [touch locationInView:self];
CGPoint prev_point = [touch previousLocationInView:self];
OSIPhone::get_singleton()->touch_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor);
}
}
2014-02-10 01:10:30 +00:00
}
2020-10-05 19:19:38 +00:00
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
UITouch *touch = [tlist objectAtIndex:i];
int tid = [self getTouchIDForTouch:touch];
ERR_FAIL_COND(tid == -1);
[self removeTouch:touch];
CGPoint touchPoint = [touch locationInView:self];
OSIPhone::get_singleton()->touch_press(tid, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, false, false);
}
}
}
2014-04-05 15:39:30 +00:00
2020-10-05 19:19:38 +00:00
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
UITouch *touch = [tlist objectAtIndex:i];
int tid = [self getTouchIDForTouch:touch];
ERR_FAIL_COND(tid == -1);
OSIPhone::get_singleton()->touches_cancelled(tid);
}
}
[self clearTouches];
}
2014-04-05 15:39:30 +00:00
2020-10-05 19:19:38 +00:00
// MARK: Motion
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
- (void)handleMotion {
if (!self.motionManager) {
return;
2014-02-10 01:10:30 +00:00
}
2016-04-02 18:26:12 +00:00
2020-10-05 19:19:38 +00:00
// Just using polling approach for now, we can set this up so it sends
// data to us in intervals, might be better. See Apple reference pages
// for more details:
// https://developer.apple.com/reference/coremotion/cmmotionmanager?language=objc
2014-02-10 01:10:30 +00:00
2020-10-05 19:19:38 +00:00
// Apple splits our accelerometer date into a gravity and user movement
// component. We add them back together
CMAcceleration gravity = self.motionManager.deviceMotion.gravity;
CMAcceleration acceleration = self.motionManager.deviceMotion.userAcceleration;
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
///@TODO We don't seem to be getting data here, is my device broken or
/// is this code incorrect?
CMMagneticField magnetic = self.motionManager.deviceMotion.magneticField.field;
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
///@TODO we can access rotationRate as a CMRotationRate variable
///(processed date) or CMGyroData (raw data), have to see what works
/// best
CMRotationRate rotation = self.motionManager.deviceMotion.rotationRate;
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
// Adjust for screen orientation.
// [[UIDevice currentDevice] orientation] changes even if we've fixed
// our orientation which is not a good thing when you're trying to get
// your user to move the screen in all directions and want consistent
// output
2014-11-26 17:24:13 +00:00
2020-10-05 19:19:38 +00:00
///@TODO Using [[UIApplication sharedApplication] statusBarOrientation]
/// is a bit of a hack. Godot obviously knows the orientation so maybe
/// we
// can use that instead? (note that left and right seem swapped)
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationUnknown;
2015-03-03 17:39:13 +00:00
2020-10-05 19:19:38 +00:00
if (@available(iOS 13, *)) {
interfaceOrientation = [UIApplication sharedApplication].delegate.window.windowScene.interfaceOrientation;
} else {
interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
2015-03-03 17:39:13 +00:00
}
2014-11-17 10:46:11 +00:00
2020-10-05 19:19:38 +00:00
switch (interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft: {
OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, gravity.z);
OSIPhone::get_singleton()->update_accelerometer(-(acceleration.y + gravity.y), (acceleration.x + gravity.x), acceleration.z + gravity.z);
OSIPhone::get_singleton()->update_magnetometer(-magnetic.y, magnetic.x, magnetic.z);
OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, rotation.z);
} break;
case UIInterfaceOrientationLandscapeRight: {
OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, gravity.z);
OSIPhone::get_singleton()->update_accelerometer((acceleration.y + gravity.y), -(acceleration.x + gravity.x), acceleration.z + gravity.z);
OSIPhone::get_singleton()->update_magnetometer(magnetic.y, -magnetic.x, magnetic.z);
OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, rotation.z);
} break;
case UIInterfaceOrientationPortraitUpsideDown: {
OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, gravity.z);
OSIPhone::get_singleton()->update_accelerometer(-(acceleration.x + gravity.x), (acceleration.y + gravity.y), acceleration.z + gravity.z);
OSIPhone::get_singleton()->update_magnetometer(-magnetic.x, magnetic.y, magnetic.z);
OSIPhone::get_singleton()->update_gyroscope(-rotation.x, rotation.y, rotation.z);
} break;
default: { // assume portrait
OSIPhone::get_singleton()->update_gravity(gravity.x, gravity.y, gravity.z);
OSIPhone::get_singleton()->update_accelerometer(acceleration.x + gravity.x, acceleration.y + gravity.y, acceleration.z + gravity.z);
OSIPhone::get_singleton()->update_magnetometer(magnetic.x, magnetic.y, magnetic.z);
OSIPhone::get_singleton()->update_gyroscope(rotation.x, rotation.y, rotation.z);
} break;
}
2014-11-17 10:46:11 +00:00
}
2014-02-10 01:10:30 +00:00
@end