Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CardboardSDK/CBDViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ typedef NS_ENUM(NSInteger, CBDEyeType)

- (void)getFrameParameters:(float *)frameParemeters zNear:(float)zNear zFar:(float)zFar;

// extension to allow panning in mono mode
@property (nonatomic) double offsetPan;
@property (nonatomic) double offsetTilt;

// return pitch, yaw, roll
- (GLKVector3)eulerAngles;

@end
26 changes: 25 additions & 1 deletion CardboardSDK/CBDViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ - (void)sharedInit
_magnetSensor->start();

_useTouchTrigger = YES;

_offsetPan = 0;
_offsetTilt = 0;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(triggerPressed:)
Expand Down Expand Up @@ -290,6 +293,16 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
}
}

- (void)setOffsetPan:(double)pan {
_offsetPan = pan;
[self glkViewControllerUpdate:self];
}

- (void)setOffsetTilt:(double)tilt {
_offsetTilt = tilt;
[self glkViewControllerUpdate:self];
}

- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause
{
if (pause)
Expand Down Expand Up @@ -372,7 +385,6 @@ - (void)calculateFrameParametersWithHeadTransform:(CardboardSDK::HeadTransform *
{
CardboardSDK::CardboardDeviceParams *cardboardDeviceParams = _headMountedDisplay->getCardboard();

headTransform->setHeadView(_headTracker->lastHeadView());
float halfInterLensDistance = cardboardDeviceParams->interLensDistance() * 0.5f;

// NSLog(@"%@", NSStringFromGLKMatrix4(_headTracker->lastHeadView()));
Expand All @@ -382,11 +394,18 @@ - (void)calculateFrameParametersWithHeadTransform:(CardboardSDK::HeadTransform *
GLKMatrix4 leftEyeTranslate = GLKMatrix4MakeTranslation(halfInterLensDistance, 0, 0);
GLKMatrix4 rightEyeTranslate = GLKMatrix4MakeTranslation(-halfInterLensDistance, 0, 0);

headTransform->setHeadView(_headTracker->lastHeadView());
leftEye->setEyeView( GLKMatrix4Multiply(leftEyeTranslate, headTransform->headView()));
rightEye->setEyeView( GLKMatrix4Multiply(rightEyeTranslate, headTransform->headView()));
}
else
{
GLKMatrix4 rot = GLKMatrix4MakeRotation(-_offsetTilt, 1.0, 0.0, 0.0);
rot = GLKMatrix4Rotate(rot, _offsetPan, 0, 1.0, 0.0);
// Apply manual pan/tilt values in mono mode only
GLKMatrix4 xform = GLKMatrix4Multiply(_headTracker->lastHeadView(), rot);
headTransform->setHeadView(xform);

monocularEye->setEyeView(headTransform->headView());
}

Expand Down Expand Up @@ -581,4 +600,9 @@ - (void)getFrameParameters:(float *)frameParemeters zNear:(float)zNear zFar:(flo
std::copy(rightEyePerspective.m, rightEyePerspective.m + 16, frameParemeters + 64);
}

// return pitch, yaw, roll
- (GLKVector3)eulerAngles {
return _headTransform->eulerAngles();
}

@end