Skip to content

Commit

Permalink
Completed Leap Motion example. Added a chessboard rendering example, …
Browse files Browse the repository at this point in the history
…although it isn't fully functional.
  • Loading branch information
BradLarson committed Aug 18, 2013
1 parent 8c01228 commit cf4931d
Show file tree
Hide file tree
Showing 18 changed files with 4,982 additions and 25 deletions.
1 change: 1 addition & 0 deletions OculusRiftSceneKitView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@property(readwrite, nonatomic) SCNVector3 headLocation;

- (CVReturn)renderTime:(const CVTimeStamp *)timeStamp;
- (void)setBackgroundColorRed:(CGFloat)redComponent green:(CGFloat)greenComponent blue:(CGFloat)blueComponent alpha:(CGFloat)alphaComponent;

@end
21 changes: 18 additions & 3 deletions OculusRiftSceneKitView.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ @interface OculusRiftSceneKitView()
SCNNode *leftEyeCameraNode, *rightEyeCameraNode;
SCNNode *headRotationNode, *headPositionNode;

CGFloat redBackgroundComponent, blueBackgroundComponent, greenBackgroundComponent, alphaBackgroundComponent;

OculusRiftDevice *oculusRiftDevice;
}

Expand Down Expand Up @@ -182,6 +184,11 @@ - (void)commonInit;
_interpupillaryDistance = 64.0;
_headLocation = SCNVector3Make(0.0, 0.0, 200.0);

redBackgroundComponent = 0.0;
greenBackgroundComponent = 0.0;
blueBackgroundComponent = 1.0;
alphaBackgroundComponent = 1.0;

CGDirectDisplayID displayID = CGMainDisplayID();
CVReturn error = kCVReturnSuccess;
error = CVDisplayLinkCreateWithCGDisplay(displayID, &displayLink);
Expand Down Expand Up @@ -326,7 +333,7 @@ - (void)renderStereoscopicScene;
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glViewport(0, 0, (GLint)self.bounds.size.width, (GLint)self.bounds.size.height);

glClearColor(0.0, 1.0, 0.0, 1.0);
glClearColor(redBackgroundComponent, greenBackgroundComponent, blueBackgroundComponent, alphaBackgroundComponent);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

glEnableVertexAttribArray(displayPositionAttribute);
Expand Down Expand Up @@ -434,7 +441,7 @@ - (void)renderer:(id <SCNSceneRenderer>)aRenderer willRenderScene:(SCNScene *)sc
glViewport(0, 0, EYE_RENDER_RESOLUTION_X, EYE_RENDER_RESOLUTION_Y);
}

glClearColor(0.0, 0.0, 1.0, 1.0);
glClearColor(redBackgroundComponent, greenBackgroundComponent, blueBackgroundComponent, alphaBackgroundComponent);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

Expand Down Expand Up @@ -469,6 +476,14 @@ - (void)renderer:(id <SCNSceneRenderer>)aRenderer didRenderScene:(SCNScene *)sce
#pragma mark -
#pragma mark Accessors

- (void)setBackgroundColorRed:(CGFloat)redComponent green:(CGFloat)greenComponent blue:(CGFloat)blueComponent alpha:(CGFloat)alphaComponent;
{
redBackgroundComponent = redComponent;
blueBackgroundComponent = blueComponent;
greenBackgroundComponent = greenComponent;
alphaBackgroundComponent = alphaComponent;
}

- (void)setScene:(SCNScene *)newValue;
{
CVDisplayLinkStop(displayLink);
Expand All @@ -481,7 +496,7 @@ - (void)setScene:(SCNScene *)newValue;
glUniform4f(hmdWarpParamUniform, 1.0, 0.22, 0.24, 0.0);


CGFloat distortionCorrection = 1.0 + 0.22 + 0.24;
// CGFloat distortionCorrection = 1.0 + 0.22 + 0.24;
// CGFloat verticalFOV = 2.0 * atan(distortionCorrection * 0.09356 / (2.0 * 0.041)) * 180.0 / M_PI;// VScreenSize = 0.09356, EyeToScreenDistance = 0.041
// CGFloat horizontalFOV = 2.0 * atan(distortionCorrection * 0.14976 / (2.0 * 0.041)) * 180.0 / M_PI;// HScreenSize = 0.14976, EyeToScreenDistance = 0.041
CGFloat verticalFOV = 97.5;
Expand Down
408 changes: 408 additions & 0 deletions examples/ChessboardTest/ChessboardTest.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions examples/ChessboardTest/OculusSceneKit/ChessboardTest-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.sunsetlakesoftware.${PRODUCT_NAME:rfc1034identifier}</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>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2013 Sunset Lake Software LLC. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'OculusSceneKit' target in the 'OculusSceneKit' project
//

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
14 changes: 14 additions & 0 deletions examples/ChessboardTest/OculusSceneKit/SLSAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <Cocoa/Cocoa.h>
#import "OculusRiftSceneKitView.h"

@interface SLSAppDelegate : NSObject <NSApplicationDelegate>

@property(assign) IBOutlet NSWindow *window;
@property(assign) IBOutlet OculusRiftSceneKitView *oculusView;

- (IBAction)increaseIPD:(id)sender;
- (IBAction)decreaseIPD:(id)sender;
- (IBAction)increaseDistance:(id)sender;
- (IBAction)decreaseDistance:(id)sender;

@end
86 changes: 86 additions & 0 deletions examples/ChessboardTest/OculusSceneKit/SLSAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#import "SLSAppDelegate.h"

@implementation SLSAppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application

SCNScene *scene = [SCNScene scene];

SCNNode *objectsNode = [SCNNode node];
[scene.rootNode addChildNode:objectsNode];

objectsNode.scale = SCNVector3Make(0.02, 0.02, 0.02);
objectsNode.position = SCNVector3Make(0, -300.0, -250);
objectsNode.rotation = SCNVector4Make(1, 0, 0, -M_PI/2);

// Chess model is from the WWDC 2013 Scene Kit presentation
SCNScene *chessboardScene = [SCNScene sceneNamed:@"chess"];
SCNNode *chessboardNode = [chessboardScene.rootNode childNodeWithName:@"Line01" recursively:YES];
NSLog(@"Chess node: %@", chessboardNode);
[objectsNode addChildNode:chessboardNode];

SCNNode *bishop = [chessboardNode childNodeWithName:@"bishop" recursively:YES];
bishop.geometry.firstMaterial.reflective.intensity = 0.7;
bishop.geometry.firstMaterial.fresnelExponent = 1.5;

SCNNode *L = [chessboardNode childNodeWithName:@"L" recursively:YES];
L.geometry.firstMaterial.reflective.intensity = 0.7;
L.geometry.firstMaterial.fresnelExponent = 1.5;

// Create a diffuse light
SCNLight *diffuseLight = [SCNLight light];
diffuseLight.color = [NSColor colorWithDeviceRed:0.1 green:0.1 blue:0.1 alpha:0.5];
SCNNode *diffuseLightNode = [SCNNode node];
diffuseLight.type = SCNLightTypeOmni;
diffuseLightNode.light = diffuseLight;
diffuseLightNode.position = SCNVector3Make(200.0, 400.0, -100);
[scene.rootNode addChildNode:diffuseLightNode];

// Create a top-down spotlight
SCNLight *spotLight = [SCNLight light];
SCNNode *spotLightNode = [SCNNode node];
spotLight.type = SCNLightTypeSpot;
spotLightNode.light = diffuseLight;
spotLightNode.position = SCNVector3Make(0, 300, -250);
spotLightNode.rotation = SCNVector4Make(1, 0, 0, M_PI_2);
[spotLight setAttribute:@30 forKey:SCNLightShadowNearClippingKey];
[spotLight setAttribute:@50 forKey:SCNLightShadowFarClippingKey];
[spotLight setAttribute:@10 forKey:SCNLightSpotInnerAngleKey];
[spotLight setAttribute:@45 forKey:SCNLightSpotOuterAngleKey];
[scene.rootNode addChildNode:spotLightNode];

self.oculusView.scene = scene;
[self.oculusView setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:1.0];

// Have this start in fullscreen so that the rendering matches up to the Oculus Rift
[self.window toggleFullScreen:nil];
}


- (IBAction)increaseIPD:(id)sender;
{
self.oculusView.interpupillaryDistance = self.oculusView.interpupillaryDistance + 2.0;
}

- (IBAction)decreaseIPD:(id)sender;
{
self.oculusView.interpupillaryDistance = self.oculusView.interpupillaryDistance - 2.0;
}

- (IBAction)increaseDistance:(id)sender;
{
SCNVector3 currentLocation = self.oculusView.headLocation;
currentLocation.z = currentLocation.z - 50.0;
self.oculusView.headLocation = currentLocation;
}

- (IBAction)decreaseDistance:(id)sender;
{
SCNVector3 currentLocation = self.oculusView.headLocation;
currentLocation.z = currentLocation.z + 50.0;
self.oculusView.headLocation = currentLocation;
}

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cf4931d

Please sign in to comment.